Shop OBEX P1 Docs P2 Docs Learn Events
No luck receiving data from Multiple XBee Series 1 TX's — Parallax Forums

No luck receiving data from Multiple XBee Series 1 TX's

FalconFalcon Posts: 191
edited 2012-04-08 14:14 in Accessories
Hello,
I'm working on XBee Series 1 based units to Transmit the condition of a Window position switch.
I've based my code off of the examples in the XBee Tutorial. The Scheduled Updates from Remote Units section seems to be the configuration, but am trying to use the Select Case structure from the Point-to-Multipoint — Manual Polling of Remote Nodes configuration to differentiate the three window locations.


Receiver code.
' {$STAMP BS2}
' {$PBASIC 2.5}
Baud            CON     396                     '2400 baud
Rx                PIN       15                       ' XBee DIN
Tx                 PIN       14                      ' XBee Dout
RTS             PIN       11                       ' XBee RTS - Used later


' ************** Variable Declarations ******************
DataIn             VAR     Byte 
WindowA         VAR     Byte
WindowB         VAR     Byte
WindowC         VAR     Byte

PAUSE 500
DEBUG CLS,"Configuring XBee...",CR
PAUSE 3000 ' Guard time
SEROUT Tx,Baud,["+++"] ' Command Mode Sequence
PAUSE 2000 ' Guard time
SEROUT Tx,Baud,["ATD6 1, CN",CR] ' Enable RTS
DEBUG CLS

' ************** Main LOOP ******************************
main:
  DEBUG CRSRXY, 0, 3, "Window A", CR                            'sets up labels tio identify individual window conditions received
  DEBUG CRSRXY, 0, 4, "Window B", CR
  DEBUG CRSRXY, 0, 5, "Window C", CR

    SERIN Rx\RTS,Baud,10,TimeOut,[DataIn]                            ' receives delimiter to identify individual window transmitter
     DEBUG CRSRXY, 0,0, "Last Window to transmit   ", DataIn, CR   
     PAUSE 200

    SELECT DataIn
      CASE "A"                                                                            'Window Location A
        SERIN Rx\RTS,Baud,20,Timeout,[DEC WindowA]          ' Accept state of window switch 1 or 0
        PAUSE 200 ' Give Base time to set up
        DEBUG CRSRXY, 15, 3, DEC WindowA, CR

      CASE "B"                                                                             'Window Location B
        SERIN Rx\RTS,Baud,20,Timeout,[DEC WindowB]          ' Accept state of window switch 1 or 0
        PAUSE 200 ' Give Base time to set up
        DEBUG CRSRXY, 15, 4, DEC WindowB, CR

      CASE "C"                                                                             'Window Location C
        SERIN Rx\RTS,Baud,20,Timeout,[DEC WindowC           ' Accept state of window switch 1 or 0
        PAUSE 200
        DEBUG CRSRXY, 15, 5, DEC WindowC, CR

    ENDSELECT
Timeout:
GOTO main

Transmitter A code
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'

' -----[ I/O Definitions ]-------------------------------------------------
Window           PIN     5                       ' Window Switch input
Rx                   PIN     15                      ' XBee DOUT (Adapter Pin 3)
Tx                   PIN     14                      ' XBee DIN  (Adapter Pin 4)
RTS                PIN     11                      ' XBee /RTS (Adapter Pin 18)

' -----[ Constants ]-------------------------------------------------------
Flag  = 0
Saved = 0
Baud               CON 396
' -----[ Variables ]-------------------------------------------------------
Flag                VAR     Bit                                           'Switch Flag
Saved            VAR     Bit                                            'Switch Saved
WindowA        VAR     Byte                                         'Switch Condition


' -----[ Program Code ]----------------------------------------------------

DEBUG "OK", CR                                                       'Verify code is running

ReadSwitch:
WindowA = IN5
  IF Saved = WindowA THEN                                     'if door saved = door current = no change set to false
    Flag = 0
  ELSE
    Flag = 1                                                                  'door changed states , set flag to true
    Saved = WindowA                                                 'save current state for compare next time through
ENDIF

IF Flag = 1 THEN                                                      'State of Switch has changed
  IF Saved = 1 THEN
    WindowA = 1
    DEBUG CRSRXY, 15, 3, "Transmit OPEN    ", DEC WindowA, CR, CR                              'Displays state of window switch
    SEROUT Tx, Baud, ["A", CR, CR, DEC WindowA, CR]                                                       'Transmit change to OPEN


    PAUSE 50
'    DEBUG CRSRXY, 15, 6, DEC WindowA, CR
  ELSE
    WindowA = 0
    DEBUG CRSRXY, 15, 3,  "Transmit CLOSED  ",DEC WindowA, CR, CR                            'Displays state of window switch
    SEROUT Tx, Baud, ["A", CR, CR, DEC WindowA, CR]                                                         'Transmit change to OPEN

    PAUSE 50
'    DEBUG CRSRXY, 15, 6, DEC WindowA, CR
  ENDIF
      Flag = 0
ENDIF
GOTO ReadSwitch

The Transmitter code for Windows B and C are identical except the variables and delimiters are changed as necessary.

I tried this code to separate the delimiter and data for the transmitter but it did not work either
'    SEROUT Tx, Baud, ["A", CR, CR]                                                                                                                                                            
'    SEROUT Tx, Baud, [DEC WindowA, CR]

My logic is that the "A", "B" or "C" delimiters are sent first when the state of a window changes. Then the 1 or 0 is sent using the WindowA, WindowB, or WindowC variables to represent the state of the window switch. The above Receiver code is all I need now to get this working but the rest of the base code will act on the individual window condition variables. That's why I'm only trying to send a 1 or 0.

I've tried with and without the RTS on the receiver but since I'm only sending a few bytes of data I don't think I actually need to worry about a overflow buffer filling up.

The Receiver DEBUG window should look like this if, for example, the last window that transmitted was Window A, and all three windows are currently OPEN:

A


Window A 1
Window B 1
Window D 1

I get inconsistant data from the DEBUG CRSRXY, 0,0, "Last Window to transmit ", DataIn, CR line of code. I seem to get the following characters randomly: A, B, C, 1, j, 5, ( and ¨ in the DataIn variable location.

Also, as the code is currently written, I do not get the 1 (or 0) data after the individual window labels. Nothing is displayed after those labels.

The TX LED on the Transmitter XBee's Adapter board is lighting up whenever the switch condition is changed (as it should). The RSSI LED on the Receiver XBee's Adapter board is lighting up at the same time (and stays lit a bit longer) inditating that data has been received.

I've set the individual XBee parameters as follows using the USB adapter and X-CTU software:

Receiver: DL: ffff
MY: 0

Transmitter A: DL 0
MY: 1

Transmitter B: DL 0
MY: 2

Transmitter C: DL 0
MY: 3

Question: Should I use the ATMY or ATDL commands in a SEROUT statement to identify individual XBee's? If so, which example in the XBee Tutorial would be closest to what I'm trying to accomplish?

Is my approach using the Select Case commands an appropriate approach.

Does anyone have any project code using multiple TX's that I could look at to see where I'm going wrong?

Thanks,

falcon

Comments

  • FalconFalcon Posts: 191
    edited 2012-04-08 14:14
    I believe the problem I was having was caused by manually configuring the XBees ATMY and ATDL. I Restored them using the X-CTU utility, then used AT commands to set all parameters from the BS2. I was then able to establish communication between all Remote XBees and the Base.

    Also, The Select Case approach works perfectly.

    falcon
Sign In or Register to comment.