stamp to stamp communication through xbee (remote to Local)
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:
Local
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
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
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
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
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.
Using the Fpin with the serial communication I can solve my problem. I'll be back to tell u guys how it went.
or do I just need the local stamp to ask the xbee to send the data.
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
just need something simple so I can understand.
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.
' {$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
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,
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.
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
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