Shop OBEX P1 Docs P2 Docs Learn Events
display signal strength - xbee & lcd — Parallax Forums

display signal strength - xbee & lcd

JBWolfJBWolf Posts: 405
edited 2015-03-03 00:19 in Propeller 1
Hi,
I'm having a bit of trouble getting the signal strength to display on two propellers with xbee's.
I can get everything else to work great, but if i try to place the portion of code that gets the signal strength into my program, it wont work.
using xbee tutorial v1 - page: 67
example code:
{{
***************************************
* Config_Getting_dB_Level *
***************************************
* See end of file for terms of use. *
***************************************
Demonstrates receiving multiple decimal
value with start delimiter
}}
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
' Set pins and Baud rate for XBee comms
XB_Rx = 0 ' XBee DOUT
XB_Tx = 1 ' XBee DIN
XB_Baud = 9600
' Carriage return value
CR = 13
OBJ
XB : "XBee_Object"

Pub Start | DataIn, Val1,Val2
XB.start(XB_Rx, XB_Tx, 0, XB_Baud) ' Initialize comms for XBee
XB.Delay(1000) ' One second delay
' Configure XBee module
XB.Str(String("Configuring XBee...",13))
XB.AT_Init ' Configure for fast AT Command Mode
XB.AT_Config(string("ATD5 4")) ' Send AT command turn off Association LED
XB.str(string("Awaiting Data...")) ' Notify Base
XB.CR
Repeat
DataIn := XB.RxTime(100) ' Wait for byte with timeout
If DataIn == "!" ' Check if delimiter
Val1 := XB.RxDecTime(3000) ' Wait for 1st value with timeout
Val2 := XB.RxDecTime(3000) ' Wait for next value with timeout
If Val2 <> -1 ' If value not received value is -1
XB.CR
XB.Str(string(CR,"Value 1 = ")) ' Display remotely with string
XB.Dec(Val1) ' Decimal value
XB.Str(string(CR,"Value 2 = ")) ' Display remotely
XB.Dec(Val2) ' Decimal value
XB.RxFlush ' Clear buffer
XB.AT_Config(string("ATDB")) ' Request dB Level
DataIn := XB.RxHexTime(200) ' Accept returning hex value
XB.Str(string(13,"dB level = "))' Display remotely
XB.Dec(-DataIn) ' Value as negative decimal
XB.CR
Else
XB.Tx(".") ' Send dot to show actively waiting

Here is the code that I am placing into my program... this is what I isolated from the example code... just a simple display for testing
Pub Main | datain
LCD.start(TX_PIN, TX_PIN, %1000, 19_200)     ' Initialize LCD
XB.start(XB_Rx, XB_Tx, 0, XB_Baud)            ' Initialize XBee    
XB.AT_Init                     ' Configure for fast AT Command Mode
XB.AT_Config(string("ATD5 4")) ' Send AT command turn off Association LED
  Repeat
    XB.RxFlush 
    XB.AT_Config(string("ATDB"))     ' Request dB Level
    DataIn := XB.RxHexTime(400)      ' Accept returning hex value 
    LCD.Dec(datain)
    waitcnt(clkfreq * 3 + cnt) 

It just displays "-1" on the LCD.
I'm not sure if it isnt working at all... or maybe it is working and im trying to use an LCD command that only works on decimal values while the received datain value is hex?
Plz help.
Thanks,
J

Comments

  • JBWolfJBWolf Posts: 405
    edited 2015-03-02 17:00
    ok i think i have sort of figured it out...
    there was a hint on one of the xbee tutorials working with rssi... "read signal strength from previous data packet"
    So I thought maybe the signal strength isnt it's own dedicated send/receive value... rather it is included on each data packet.
    II modified my code to first send a basic decimal value, then request rssi.
    It works!
    repeat
           ++tmp1
           XB.Tx("!")
           XB.Dec(999)     ' send ping, base should reply '999'
           XB.CR
           XB.RxFlush
           DataIn := XB.RxTime(100)
            If DataIn == "!"                     ' if start delim received
               DataIn := XB.RxDecTime(100)       ' get ping response
              If Datain == 999                   ' if ping successfully received 
                XB.AT_Config(string("ATDB"))     ' Request dB Level
                DataIn := XB.RxHexTime(400)      ' Accept returning hex value
                LCD.Tx(148)
                LCD.Str(String("Signal dB = "))
                LCD.Tx(160)
                LCD.Dec(-datain)                 ' display signal strength
             else                                ' if no response received from base
                LCD.Tx(179)
                LCD.Str(String("error"))
    
           LCD.Tx(188)                            ' Line 3, Pos 0
           LCD.dec(tmp1)                          ' show counter
           waitcnt(clkfreq * 3 + cnt)
           LCD.Tx(179)
           LCD.Str(String("                "))    ' clear last reading    
    
  • JBWolfJBWolf Posts: 405
    edited 2015-03-02 17:39
    ok nevermind... now it doesnt work.
    It worked once... didnt change anything, now im just getting replies of -1
    i dont get it... this is more complicated than it should be for such a simple feature
  • JBWolfJBWolf Posts: 405
    edited 2015-03-02 21:46
    aha... have to enable fast at commands.
    I put this before the repeat loop and it seems to work again
    XB.AT_Init                               ' Configure for fast AT Command Mode
    XB.AT_Config(string("ATD5 4"))           ' Send AT command turn off Association LED
    
  • JBWolfJBWolf Posts: 405
    edited 2015-03-02 23:28
    ok but now I cannot send receive regular data.... sigh
    So I can send receive regular data fine but not rssi... or I can enable AT_init, have rssi reporting working fine but not receive normal data.

    So using AT_init goes into command mode? How do I exit command mode?
  • JBWolfJBWolf Posts: 405
    edited 2015-03-03 00:19
    weird... so just playin around with the order of those commands, found a way that appears to work.
    So I moved the AT-init command.... instead of using it just once before entering my main program loop, I am now using it everytime directly after requesting rssi.
                    XB.AT_Config(string("ATDB"))     ' Request dB Level  
                    DataIn := XB.RxHexTime(1000)         ' Accept returning hex value
                    LCD.Dec(DataIn)
                    XB.AT_Init
    

    Oddly enough, this works!
    I can send/receive data before sending an rssi request, also after receiving & displaying the rssi data.
    I do not understand why this works and would love to know
  • Hi JB, I have the same problem with ATDB. I did not use any of the xbee OBJ stuff but now I have tried just about every thing and NOTHING is working.

    Love the xbeeProS2 units in AT mode with nothing but the serial driver but would love to get the ATDB working. I had a question though, you said it would kind/some times work. If you type +++ then atdb into your terminal have you EVER got the same value back from atdb in your code?


    I did find out that serial.rx would not return the $1F that I would get if I just typed it (+++atdb in the terminal) in but the serial.getc would get the "1" and a 2nd got the "F".

    Aside from putc(getc) to debug I have NEVER got ATDB in my code to return the same value as when I type ATDB into the Terminal.
Sign In or Register to comment.