Making the Ping Wireless
Tymkrs
Posts: 539
I apologize as this seems to be along the same grain as the last four posts. But I decided to make an attempt at getting my Ping to be wireless by way of XBee (series 1) modules.
My remote node is a propboe with the xbee, and my base node is a propdemo board with an xbee (my second propboe decided to go bust on me):
Base Node Code:
Remote Node Code:
I feel like something's missing, and I know there is since the code doesn't want to work or let the XBees be recognized by X-CTU during a Test/Query. This was somewhat cobbled (noobie style) from the led/buzzer code in the XBee tutorial PDF. I'd love any suggestions...thanks!!!
Oh and the goal is to have the ping be on the remote node. Have the base node continously ping to get a Ping measurement back and displayed in either X-CTU or a serial terminal window. At this point I'll take either
.
My remote node is a propboe with the xbee, and my base node is a propdemo board with an xbee (my second propboe decided to go bust on me):
Base Node Code:
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 ' XBee Baud Rate
' Set pins and baud rate for PC comms
PC_Rx = 31
PC_Tx = 30
PC_Baud = 9600
CR = 13
VAR
long Range
OBJ
XB : "XBee_Object_2"
PC : "XBee_Object_2" ' Using XBee object on PC side for more versatility
Pub Start
XB.Delay(2000)
PC.str(string("Warming Up XBee..."))
PC.start(PC_Rx, PC_Tx, 0, PC_Baud) ' Initialize comms for PC
XB.start(XB_Rx, XB_Tx, 0, XB_Baud) ' Initialize comms for XBee
repeat
XB.Delay(100) ' Allow buffer
XB.RxFlush ' Empty buffer
GetReading ' Request Ping value
XB.Delay(1000) ' 1 second delay
Pub GetReading
XB.Tx("P") ' Send P for Ping measurement
Range := XB.RxDecTime(500) ' Accept returned data
If Range == -1 ' -1 means timeout
PC.str(string("No Response"))
else
PC.str(string("Ping Reading", 32))
PC.tx(Range) ' Display value
PC.tx(13)
Remote Node Code:
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 ' XBee Baud Rate
CR = 13 ' Carriage Return
Ping_Pin = 4
OBJ
XB : "XBee_Object_2"
Ping : "Ping"
VAR
Long Range
Pub Start | DataIn
XB.start(XB_Rx, XB_Tx, 0, XB_Baud) ' Initialize comms for XBee
XB.RxFlush ' Ensure XBee buffer empty
repeat
DataIn := XB.Rx
Case Range ' Wait for byte
"P": DataIn := XB.RxDecTime(500) ' If byte P, accept request
if DataIn <> -1 ' Ensure wasn't timeout
Range := Ping.Inches(ping_pin)
XB.DEC(Range)
XB.CR
I feel like something's missing, and I know there is since the code doesn't want to work or let the XBees be recognized by X-CTU during a Test/Query. This was somewhat cobbled (noobie style) from the led/buzzer code in the XBee tutorial PDF. I'd love any suggestions...thanks!!!
Oh and the goal is to have the ping be on the remote node. Have the base node continously ping to get a Ping measurement back and displayed in either X-CTU or a serial terminal window. At this point I'll take either

Comments
So the BASE Prop w/Xbee had the following "Serial Pass Through" code:
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 ' 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 OBJ PC : "FullDuplexSerial" XB : "FullDuplexSerial" Pub Start PC.start(PC_Rx, PC_Tx, 0, PC_Baud) ' Initialize comms for PC XB.start(XB_Rx, XB_Tx, 0, XB_Baud) ' Initialize comms for XBee cognew(XB_to_PC,@stack) ' Start cog for XBee--> PC comms PC.rxFlush ' Empty buffer for data from PC repeat XB.tx(PC.rx) ' Accept data from PC and send to XBee Pub XB_to_PC XB.rxFlush ' Empty buffer for data from XB repeat PC.tx(XB.rx) ' Accept data from XBee and send to PCAnd then the REMOTE prop w/xbee had the following code:
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 XB_Rx = 0 ' XBee DOUT XB_Tx = 1 ' XBee DIN XB_Baud = 9600 CR = 13 ' Carriage Return value Ping_Pin = 4 OBJ XB : "FullDuplexSerial" Ping : "Ping" Pub Start | Counter, range XB.start(XB_Rx, XB_Tx, 0, XB_Baud) ' Initialize comms for XBee waitcnt(clkfreq + cnt) repeat range := ping.Inches(ping_pin) ' Get range in inches XB.str(string("Ping Measurement:")) ' send string XB.dec(range) ' send decimal value XB.Tx(CR) ' send Carriage Return waitcnt (clkfreq/4 + cnt)And when you use X-CTU to monitor the Ping Measurements on the Base Node's comport, you end up with this:
It's not as controlled as what I'd like it to be as the measurements just start as soon as everything's turned on, and ideally, I'd be able to incorporate a pushbutton into this. But, it's still wireless!
I also wanted to note that Test/Query did not work for either prop (strangely enough). But I guess that didn't stop things from working.