BS2 To Xbee To Xbee To Ping Sensor.
Tony11
Posts: 41
What I am looking to do is, make the ping sensor wireless. I am going to use two Xbee module and two BS2 module. So the smart sensors and applications program work's great. (program is below) I just want to make the ping wireless, from the BS2. I still want to read the data on my computer, from the ping sensor.
I need help with making the program that will send serial data to and from the xbee's.
Ping to BS2 to Xbee to Xbee to BS2 to my computer.
' Smart Sensors and Applications - PingMeasureCmAndIn.bs2
' Measure distance with Ping))) sensor and display in both in & cm
' {$STAMP BS2}
' {$PBASIC 2.5}
' Conversion constants for room temperature measurements.
CmConstant CON 2260
InConstant CON 890
cmDistance VAR Word
inDistance VAR Word
time VAR Word
DO
PULSOUT 15, 5
PULSIN 15, 1, time
cmDistance = cmConstant ** time
inDistance = inConstant ** time
DEBUG HOME, DEC3 cmDistance, " cm"
DEBUG CR, DEC3 inDistance, " in"
PAUSE 100
LOOP
I need help with making the program that will send serial data to and from the xbee's.
Ping to BS2 to Xbee to Xbee to BS2 to my computer.
' Smart Sensors and Applications - PingMeasureCmAndIn.bs2
' Measure distance with Ping))) sensor and display in both in & cm
' {$STAMP BS2}
' {$PBASIC 2.5}
' Conversion constants for room temperature measurements.
CmConstant CON 2260
InConstant CON 890
cmDistance VAR Word
inDistance VAR Word
time VAR Word
DO
PULSOUT 15, 5
PULSIN 15, 1, time
cmDistance = cmConstant ** time
inDistance = inConstant ** time
DEBUG HOME, DEC3 cmDistance, " cm"
DEBUG CR, DEC3 inDistance, " in"
PAUSE 100
LOOP
Comments
http://www.parallax.com/Portals/0/Downloads/docs/prod/rf/122-32450-XBeeTutorial-v1.0.1.pdf
Starting on Page 74, it has an example of how to connect two BS2's together serially with the Xbees and how to get feedback from light sensors. The manual/automatic polling process should be helpful as well.
And if it helps to read through my "thought process" here're some links to things I've done requiring communication between two xbees (and at the end of the day it just sounds like you want to set up a simple serial connection)
http://tymkrs.tumblr.com/post/19784957623/xbee-using-a-switch-to-control-rc-servos-set-up
http://tymkrs.tumblr.com/post/19837921484/xbee-using-a-switch-to-control-rc-servos-code
http://tymkrs.tumblr.com/post/19896757309/xbee-using-a-switch-to-control-the-heart-led-project
http://tymkrs.tumblr.com/post/20011194294/xbee-using-a-switch-to-control-the-heart-led-project
So something like...First BS2 sends (through the Xbee) the start sequence for the Ping Sensor, then listens for anything sent back to it to display on a serial terminal. Second BS2 hears the start sequence for the Ping Sensor, and just sends back anything it gets (either timed or not). Like you could easily make a switch that once you press it, wirelessly gets a Ping data thing back.
So if both pings sensor's is > 50, turn on led's. Box1 and Box2 will be wireless with the xbee's. I want to put one (Box1,ping1,xbeex,led1, and propeller) in one room and in some other room, I want (Box2,ping2,xbee,led2 and propeller)
"Box 1"
ping1
xbee
led1
Propeller
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
"Box 2"
ping2
xbee
led2
Propeller
What is the best way to write the program for this=
Box1
(ping1 > 50) = 1
(1 = box1)
send (box1) with xbee to xbee2
if (box1) and (box2)
then turn on led1
xbee's would send O or 1 tx and rx
====================================================
Box2
(ping1 > 50) =1
(1 = box2)
send (box2) with xbee to xbee1
if (box1) and (box2)
then turn on led2
xbee's would send O or 1 tx and rx
pst : "FullDuplexSerial"
ping : "Ping"
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
ping_pin = 0 ' I/O pin for Ping
_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
' Set pins and baud rate for PC comms
PC_Rx = 31
PC_Tx = 30
PC_Baud = 9600
VAR
long stack[50] ' stack space for second cog
long range
word Box1
PUB Go
pst.start(31,30,0,115200)
waitcnt(ClkFreq + Cnt)
repeat ' Repeat forever
range := ping.Inches(ping_pin) ' Get range in inches
pst.dec(range) ' Display result
pst.tx(13)
WaitCnt(ClkFreq / 4 + Cnt) ' Short delay until next read
(range > 50) = (Box1)
XB_Rx = (box1)
if (Box1) and (Box2)
outa[4] :=1
something like this.......
How about starting with the minimum program that demonstrates successful sensing with the PING)))? What you've posted won't compile or run successfully.
Note that the Parallax Serial Terminal object, while it uses FullDuplexSerial internally, adds some additional functionality which is understood by the Parallax Serial Terminal PC program. It may be confusing to others to use the object name "pst" for FullDuplexSerial. I usually use "ser" or "serial".
(ping1 < 50) = (xbee1) (ping2 < 50) = (xbee2).
if ping1 and ping2 sensor's are at (10). The output would be (0).
(ping1 < 50) = (xbee1) (ping2 < 50) = (xbee2).
Then on box1 and box2 program's. There would be this line that would read.
What is the state of (xbee1 and xbee2)
If (xbee1 and xbee2)then
turn on ledbox1 and ledbox2
What I need help is with sending the state of the output, using the xbee's, and no pc, hook up.
Box1 = ping sensor, xbee, and led.
Box2 = ping sensor, xbee, and led.
(if xbee1 output is 0 and xbee2 output is 1. Led = 0)
(if xbee1 output is 1 and xbee2 output is 0. Led = 0)
(if xbee1 output is 1 and xbee2 output is 1. Led = 1)
So in the end of all this Box1 and Box2 will be talking to each other, what is your state.
Box1 and Box2 are going to have to have a Stamp or Propeller or some other kind of microcontroller inside in addition to a Ping and an xBee along with an LED. If a Stamp or Propeller, we can help you with it. If not, you're on your own.
Box1 = ping sensor, propeller, xbee, and led.
Box2 = ping sensor, propeller, xbee, and led.
This is all I would like to know, to make it easy. Switch, propeller, xbee, and
led. (Box1) Switch, propeller, xbee, and led. (Box2).
Switch goes high on box1, led goes high on box2
Switch goes high on box2, led goes high on box1
Here is code, to send switch input one way, how do I send it back, with switch and led. So on the code that has no Switch input, how do I make it take the input and send it two ways.................
2 Propeller Demo Board (Item code 28015)
2 xbee's with two Xbee's SIP Adapter (Item code 32402).
2 ping sensor's (Item code 28015)
2 led's
I do know that I will have to use 1 kΩ resistor (when using the ping sinsors to the Propeller Demo Board) and
I all so know that I will have to use the 5V on the Sip Adaptor board for the xbee's.
So on the xbee's, in the program how do I send the state of the ping data (1), from one Box1 to Box2 and
or Box2 to box1.
I hope this helps
You use some kind of serial I/O in your program to talk to them. Since you're already using FullDuplexSerial to talk to the PC, you can use that to talk to the xBees. Just use the appropriate pin numbers in the FullDuplexSerial start call. I'd suggest that you use 9600 Baud for the xBees and FullDuplexSerial. If you want to send debug messages to the PC as well, use two instances of FullDuplexSerial, one for each serial port. Just declare two OBJs, both of them FullDuplexSerial.
Whatever is sent from Box1 to its xBee will be received by Box2 and whatever is sent from Box2 to its xBee will be received by Box1. The simplest thing would be to send the number you get from the Ping routines, preferably the distance in millimeters since all of the distances are integers and you'll have finer resolution using millimeters.
I'd send an identification character, then send the data as two 8-bit bytes like this: ping is the Ping object and xBee is the FullDuplexSerial object for the xBee.
On the receiving end, you'd do something like: The identification byte is some arbitrary character used to help sync the two boxes. It's not perfect in that one of the data bytes might be the same and the two boxes might get confused for a while. There are ways to have a sync byte that doesn't occur in the data, but this is a good start.
Your CON and OBJ sections look fine, so start with that. You're going to need two separate programs, one for each board, and I'd only include the things that you need for the particular program, i.e. no Ping definition for the program that doesn't have a Ping attached. Write each program completely within a single method (call it Start, but the name doesn't matter). Start the method with the initialization of any objects used. One will have a .start call for its xBee serial port. The other will have a .start call for an xBee port and another port for the PC. The Ping object doesn't need a .start call. The .start call already initializes the receive buffer to empty, so you don't need to flush it as well.
For the first program, test things by calling the Ping object and sending the data followed by a carriage return once a second. You've almost got that already, but it goes into a repeat loop in the Start method.
For the second program, just have a repeat loop that reads a character from the xBee serial port and echos it immediately to the PC serial port. Once that works for you, you can fancy it up with labels sent to the PC.
Once you have this working, swap the two boards' PC connection and swap programs so you have it working in the other direction. At this point, you've checked out the hardware and made sure the xBee link works.
For bidirectional use, you can take what I've given in Post #15 and just do the transmit and receive parts in order. The serial port is buffered with a 16 byte buffer, so, if you keep the message length to under 16 bytes or change to a different serial port object in the Object Exchange that has a bigger buffer, you can wait to process the receive information while the Ping and transmit is being done. The data coming back from the other xBee will just wait in the buffer until you access it.
For the led to turn on (Ping data < 100) and (xBee data < 100) turn on led
So, how often does the LED light when the Ping data is within range? How often does the Ping trigger light come on? The PC debug display does take a little time, maybe 50ms when the transmit buffer gets full. The xBee also takes some time to actually send the data back and forth.
Is there some way that I can use the xbee to send on-off signal transmission, like Momentary.
Box1 (ping,xbee,propeller,and led)
if (ping1 < 100) := (xbeeon1)
then send that (:=xbeeon1) to xbee2
if ( xbeeon1 and xbeeon2)
then high led
=========================================
Box2 (ping,xbee,propeller,and led)
if (ping2 < 100) := (xbeeon2)
then send that (:=xbeeon2) to xbee1
if ( xbeeon1 and xbeeon2)
then high led
some info, about it. Here is the link.
www.youtube.com/watch?v=xNru4zHEERc