Shop OBEX P1 Docs P2 Docs Learn Events
Making the Ping Wireless — Parallax Forums

Making the Ping Wireless

TymkrsTymkrs Posts: 539
edited 2012-06-29 17:32 in Accessories
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:
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 :p.

Comments

  • TymkrsTymkrs Posts: 539
    edited 2012-06-29 17:32
    So I looked at the tutorial again and on page 61, there's a statement "Using the XBee is a great way to simply monitor your Remote node for robotics or sensor data." So I thought I'd start from scratch and try to use the Serial Pass Through Data and the Debug Data.

    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 PC
    

    And 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:

    Image178.png

    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.
    452 x 586 - 13K
Sign In or Register to comment.