Shop OBEX P1 Docs P2 Docs Learn Events
stamp to stamp communication through xbee (remote to Local) — Parallax Forums

stamp to stamp communication through xbee (remote to Local)

CreeCree Posts: 132
edited 2013-08-27 07:25 in BASIC Stamp
Hi, i'm trying to send serial information through my xbee.

This is the Loop back example, but I want to send it to a second basic stamp.

http://learn.parallax.com/KickStart/32440

I
have been able to send serial information to my local xbee and display in on the x-ctu terminal window.

I modified the loop back example to try to recieve the info on the 2nd stamp.

**Xbees are working, settings are default


Remote:
' {$STAMP BS2sx}' {$PBASIC 2.5}




Baud  CON     240                        ' 9600 baud non-inverted
'Rx    PIN     1                        ' XBee DOUT
Tx    PIN     0                        ' XBee DIN
temp  VAR     Byte                      ' Temporary variable


PAUSE 500                               ' 1/2 second pause to stabilize
  temp = 1
  'temp2 = 10
  'temp3 = 100
  'temp4 = 1000
DO
  DEBUG CLS, CR, "!! " ,CR,      ' Prompt for character
   "temp: ", DEC (temp),CR
                  ' Catch user response
  SEROUT Tx, Baud, [temp]               ' Send to transmitting XBee
  PAUSE 1500                            ' Wait 1-1/2 seconds
LOOP


Local

' {$STAMP BS2sx}' {$PBASIC 2.5}


'


Baud  CON     240                        ' 9600 baud non-inverted
Rx    PIN     0                        ' XBee DOUT
'Tx    PIN     0                        ' XBee DIN
temp  VAR     Byte                      ' Temporary variable


PAUSE 500                               ' 1/2 second pause to stabilize


DO
  DEBUG CLS, CR, "!!" ,CR
  SERIN Rx, Baud, [DEC temp]                ' Get echo from receiving XBee
   DEBUG CLS, CR, "(!!) " ,CR,      ' Prompt for character
   "temp: ", DEC (temp),CR
  PAUSE 1500                            ' Wait 1-1/2 seconds
LOOP


Can some one tell me what I am doing wrong in terms of programming for the Local BS2sx.
*I checked my wiring and its fine.

** Using series 1 xbee pro, bs2sx

Comments

  • stamptrolstamptrol Posts: 1,731
    edited 2013-08-22 09:04
    The BS2sx should work fine at 9600 baud.

    I assume you've set the XBees baud, etc using the XCTU utility.

    Also, both of your programs look like they only transmit. One, of course, has to be setup to receive the expected data.

    Cheers,
  • CreeCree Posts: 132
    edited 2013-08-22 09:25
    stamptrol wrote: »
    The BS2sx should work fine at 9600 baud.

    I assume you've set the XBees baud, etc using the XCTU utility.

    Also, both of your programs look like they only transmit. One, of course, has to be setup to receive the expected data.

    Cheers,

    Ya i copied the wrong code, its been changed now
  • Mike GreenMike Green Posts: 23,101
    edited 2013-08-22 09:46
    Probably what's going on is that you're assuming that the Stamp is "listening" to the serial input all the time so, whenever the xBee sends a character, the Stamp will "see" it. That's not true. The only time the Stamp can receive a character is when the SERIN is executing and the SERIN will normally wait forever for a character to come in. In your case, it's waiting for a sequence of digits followed by a non-digit and it will ignore anything else (because you're using a DEC formatter and that's what it does). I think what you meant was to leave out the DEC. To cope with the first issue, you need to use flow control. Look in the Stamp Manual or the Stamp Editor help files for a discussion of this and the SERIN statement. You'll need to enable flow control on the xBee as well using XCTU and it'll require another wire between the two devices. Essentially, the Stamp tells the xBee when it can send its data and the xBee saves its data in an internal buffer until it gets permission to send it. The Stamp only gives permission when a SERIN statement is ready to receive it.

    The Wikipedia has a discussion on this "hardware flow control", but the best description for this purpose is in the Stamp Manual section on the SERIN statement
  • CreeCree Posts: 132
    edited 2013-08-22 11:33
    Just posting a link to a thread so i can find it.
    http://forums.parallax.com/showthread.php/122153-confused-about-xbee-flow-control

    I'm trying the first example in the link i posted, but it doesn't work for me. probably some issue on my end with wiring. a bit tired and slightly fustrated doesn't make for good wiring programing. :innocent:
  • CreeCree Posts: 132
    edited 2013-08-23 08:40
    I think understand what to do now.

    Using the Fpin with the serial communication I can solve my problem. I'll be back to tell u guys how it went.
  • CreeCree Posts: 132
    edited 2013-08-23 08:52
    Just one question, do I need flow control on both the remote and local stamp.

    or do I just need the local stamp to ask the xbee to send the data.
  • CreeCree Posts: 132
    edited 2013-08-23 10:37
    Ok I tried making something from the examples below:

    I'm really trying, I understand what ur telling me Mike, but I haven't been able to get something to work besides the one from that link that gives me random numbers.
    serial out:
    ' {$STAMP BS2sx}' {$PBASIC 2.5}
     sData   VAR     Byte
    
    
    Main:
    DO
     sData = 1
     DEBUG "Sdata out: ", DEC sData, CR
      SEROUT 1, 240, [DEC sData]                       ' baudmode set for BS2
    
    
     LOOP
    


    Serial in:
    ' {$STAMP BS2sx}' {$PBASIC 2.5}
    sData   VAR     Byte
    
    
    Main:
    DEBUG "sData"
      SERIN 1/0, 240, [DEC sData]
    
    
        DEBUG "sdata in" , DEC sData,CR
      STOP
    
    
    
  • CreeCree Posts: 132
    edited 2013-08-23 11:07
    still going over examples and going crazy, like usual when I'm not able to get something to work...

    just need something simple so I can understand.
  • stamptrolstamptrol Posts: 1,731
    edited 2013-08-24 04:54
    The flow control method certainly will work if the radios can get the flow signal through to the Stamp.

    However, I've always had better success using the "Wait" modifier and the SERIN command. That way, the receiving Stamp will pause on the SERIN command long enough to actually receive the data. For "Wait" to work, you put in a special leading character in the data from the transmitter. Instead of sending 123, the sending Stamp sends %123, for example.

    The receiving Stamp uses SERIN to Wait for the %, then knows to grab the next 3 characters (or however many you need).

    I've attached a piece of code showing the SERIN and SEROUT I used on one project during testing.

    Cheers,
  • CreeCree Posts: 132
    edited 2013-08-26 06:29
    stamptrol wrote: »
    The flow control method certainly will work if the radios can get the flow signal through to the Stamp.

    However, I've always had better success using the "Wait" modifier and the SERIN command. That way, the receiving Stamp will pause on the SERIN command long enough to actually receive the data. For "Wait" to work, you put in a special leading character in the data from the transmitter. Instead of sending 123, the sending Stamp sends %123, for example.

    The receiving Stamp uses SERIN to Wait for the %, then knows to grab the next 3 characters (or however many you need).

    I've attached a piece of code showing the SERIN and SEROUT I used on one project during testing.

    Cheers,

    Thx for the tip.

    I looked at your website, you've done quite a few interesting projects.
  • CreeCree Posts: 132
    edited 2013-08-26 07:01
    Are there any limits to the serial out, because I'm going to need to send out Words instead of bytes eventually.
  • CreeCree Posts: 132
    edited 2013-08-26 08:45
    Going back to what I was trying at first, I have just modified it a bit with Tom's previous post (#10), but I still can not receive anything on the local stamp. I just wanted to know what you guys might think is wrong.

    ' {$STAMP BS2sx}' {$PBASIC 2.5}
    
    
    ' Remote
    
    
    Baud  CON     240                        ' 9600 baud non-inverted
    Rx    PIN     0                        ' XBee DOUT
    Tx    PIN     1                       ' XBee DIN
    temp  VAR     Byte                      ' Temporary variable
    
    
    PAUSE 500                               ' 1/2 second pause to stabilize
      temp = %1
      'temp2 = 10
      'temp3 = 100
      'temp4 = 1000
    DO
      DEBUG CLS, CR, "! " ,CR,      ' Prompt for character
       "temp: ", DEC (temp),CR
                      ' Catch user response
      SEROUT Tx, Baud, [ DEC temp]               ' Send to transmitting XBee
      PAUSE 2000                            ' Wait 1-1/2 seconds
    LOOP
    

    ' {$STAMP BS2sx}' {$PBASIC 2.5}
    
    
    'Local
    
    
    Baud  CON     240                        ' 9600 baud non-inverted
    Rx    PIN     0                        ' XBee DOUT
    Tx    PIN     1                       ' XBee DIN
    temp  VAR     Byte                      ' Temporary variable
    
    
    PAUSE 500                               ' 1/2 second pause to stabilize
    
    
    DO
      DEBUG CLS, CR, "!!" ,CR
      SERIN Rx, Baud, [WAIT ("&"), DEC  temp]                ' Get echo from receiving XBee
       DEBUG CLS, CR, "(!!) " ,CR,      ' Prompt for character
       "temp: ", DEC (temp),CR
                                  ' Wait 1-1/2 seconds
    LOOP
    
  • stamptrolstamptrol Posts: 1,731
    edited 2013-08-26 09:55
    In your transmitting section, be sure you're sending the "&" for the receiver to watch for.

    Also, when you use Wait, there is a parameter which gives a place for the program to go if nothing comes along. See the SERIN command in the Help file.

    There are provisions for sending word sizes, although you can also send var.byte1, var.byte2.

    Cheers,
  • CreeCree Posts: 132
    edited 2013-08-26 10:34
    In your transmitting section, be sure you're sending the "&" for the receiver to watch for.

    Like this? I tried this, it did not work.
    ' {' {$STAMP BS2sx}' {$PBASIC 2.5}
    
    
    ' Remote
    
    
    Baud  CON     240                        ' 9600 baud non-inverted
    Rx    PIN     0                        ' XBee DOUT
    Tx    PIN     1                       ' XBee DIN
    temp  VAR     Byte                      ' Temporary variable
    
    
    PAUSE 500                               ' 1/2 second pause to stabilize
      temp = 1
      'temp2 = 10
      'temp3 = 100
      'temp4 = 1000
    DO
      DEBUG CLS, CR, "! " ,CR,      ' Prompt for character
       "temp: ", DEC (temp),CR
                      ' Catch user response
      SEROUT Tx, Baud, ["&", temp]               ' Send to transmitting XBee
      PAUSE 2000                            ' Wait 1-1/2 seconds
    LOOP
    
    ' {$STAMP BS2sx}' {$PBASIC 2.5}
    
    
    'Local
    
    
    Baud  CON     240                        ' 9600 baud non-inverted
    Rx    PIN     0                        ' XBee DOUT
    Tx    PIN     1                       ' XBee DIN
    temp  VAR     Byte                      ' Temporary variable
    
    
    Main:
    PAUSE 500                               ' 1/2 second pause to stabilize
    
    
    DO
      DEBUG CLS, CR, "!!" ,CR
      SERIN Rx, Baud,5000, tlabel, [WAIT("&"),temp]                ' Get echo from receiving XBee
       DEBUG CLS, CR, "(!!) " ,CR,      ' Prompt for character
       "temp: ", DEC (temp),CR
                                  ' Wait 1-1/2 seconds
    LOOP
    
    
      tlabel:
       DEBUG   "Did Not Recieve Serial input! " ,CR
      GOTO Main
    
    
      ' In your transmitting section, be sure you're sending the "&" for the receiver to watch for.
    
    
    'There are provisions FOR sending Word sizes, although you can also send VAR.BYTE1, VAR.byte2.
    
    
    
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2013-08-26 18:32
    Your receive programme is waiting for a %
    SERIN Rx, Baud,5000, tlabel,[WAIT("%"),temp]

    that your transmitter never sends
    SEROUT Tx, Baud, [temp] ' Send to transmitting XBee

    With changes:
    SERIN Rx, Baud, [WAIT("%"),temp]

    SEROUT Tx, Baud, ["%",temp]

    (The posts and your programme's notes make mention of using an ampersand, but you used a percent, so I didn't change that.)
  • CreeCree Posts: 132
    edited 2013-08-27 06:15
    PJ Allen wrote: »
    Your receive programme is waiting for a %
    SERIN Rx, Baud,5000, tlabel,[WAIT("%"),temp]

    that your transmitter never sends
    SEROUT Tx, Baud, [temp] ' Send to transmitting XBee

    With changes:
    SERIN Rx, Baud, [WAIT("%"),temp]

    SEROUT Tx, Baud, ["%",temp]

    (The posts and your programme's notes make mention of using an ampersand, but you used a percent, so I didn't change that.)

    Sry I had fixed in my code, but not the one I posted in the forum
  • CreeCree Posts: 132
    edited 2013-08-27 06:34
    starting to think it might be something with the wiring, the local xbee is receiving the data and I can see it on the x-ctu terminal on my PC, but still seems to have difficulty getting it to the stamp.
  • CreeCree Posts: 132
    edited 2013-08-27 07:25
    Got it to work thx guys! Much appreciated. I just need to fix it up a bit. I'll post the code that I have for others.

    Now just to apply it to a larger project.

    ' {$STAMP BS2sx}' {$PBASIC 2.5}
    
    
    ' Remote
    
    
    Baud  CON     240                        ' 9600 baud non-inverted
    Rx    PIN     0                        ' XBee DOUT
    Tx    PIN     1                       ' XBee DIN
    temp  VAR     Byte                      ' Temporary variable
    
    
    PAUSE 500                               ' 1/2 second pause to stabilize
      temp = 1
      'temp2 = 10
      'temp3 = 100
      'temp4 = 1000
    DO
      DEBUG CLS, CR, "! " ,CR,      ' Prompt for character
       "temp: ", DEC (temp),CR
      SEROUT Tx, Baud,  ["A", CR]                ' Catch user response
      SEROUT Tx, Baud,  [DEC temp,CR]               ' Send to transmitting XBee
      PAUSE 2000                            ' Wait 1-1/2 seconds
    LOOP
    


    ' {$STAMP BS2sx}' {$PBASIC 2.5}
    
    
    'Local
    
    
    Baud  CON     240                        ' 9600 baud non-inverted
    Rx    PIN     0                        ' XBee DOUT
    Tx    PIN     1                       ' XBee DIN
    temp  VAR     Byte                      ' Temporary variable
    
    
    Main:
    PAUSE 500                               ' 1/2 second pause to stabilize
    
    
    DO
      DEBUG CLS, CR, "!!" ,CR
      SERIN Rx, Baud,5000, tlabel, [WAIT("A"),DEC temp]     ' Get echo from receiving XBee
       DEBUG CLS, CR, "(!!) " ,CR,                          ' Prompt for character
       "temp: ", DEC (temp),CR                              ' Wait 1-1/2 seconds
       STOP
    LOOP
    
    
      tlabel:
       DEBUG   "Did Not Recieve Serial input! " ,CR
      GOTO Main
    
    
    
Sign In or Register to comment.