Shop OBEX P1 Docs P2 Docs Learn Events
Xbee help — Parallax Forums

Xbee help

Carl LawhonCarl Lawhon Posts: 36
edited 2009-02-21 21:13 in Propeller 1
This may be a noobish question, but here goes. I have two protoboards and have two xbees hooked up to the protoboards. I need one protoboard to be able to send a·latitude coordinate and a longitude coordinate, obtained from a Parallax GPS receiver, to the other protoboard. Any suggestions? ·

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-02-21 19:15
    You need to have the two coordinates stored either as long values or as strings of characters terminated by a zero byte. You use the FullDuplexSerial object to transmit the values to one xBee (after the xBees are wirelessly connected) using either the ser.STR method to send strings separated by a return character using ser.OUT(13) (assuming "ser" is the name of your FullDuplexSerial object). On the receive end, you'd use the Extended FullDuplexSerial object from the Object Exchange to handle the process of separating the received strings. Alternatively, you could send the long values as decimal values using ser.DEC and the corresponding Extended FullDuplexSerial routine on the receive end. There are other ways to do this, but what I've suggested is probably the most straightforward.

    You might use a unique lead-in for each "packet" of information like the character '!' and discard all received characters until that one is found before using the Extended FullDuplexSerial routines to handle the actual values. This would help you if one end of the "conversation" gets confused. It just ignores everything until something makes sense.
  • Carl LawhonCarl Lawhon Posts: 36
    edited 2009-02-21 20:01
    Should I float the coordinates to strings? As in FS.floattostring(Gps.getlongitude), and then use ser.str to transmit that value? Also, does fullduplexserial (the original one)have the OUT method? If not how can I send a return character?
  • Jay KickliterJay Kickliter Posts: 446
    edited 2009-02-21 21:13
    If you are dealing with floats on the sending side already, it might be better to send them as binary, and not strings. I find that it is alot more easy to predict packet size that way, since floats are always 32 bits.

    On the sending side you could so something like:

    serial.tx(ESCAPE_CHAR)
    serial.tx(ESCAPE_CHAR) 'I like to send the escape twice so the receive side knows it is at the beginning of a new packet
    serial.tx(latitude & $FF)
    serial.tx((latitude>>8)& $FF)
    serial.tx((latitude>>16)& $FF)
    serial.tx((latitude>>24)& $FF)
    serial.tx((longitude)& $FF)
    serial.tx((longitude >>8)& $FF)
    serial.tx((longitude >>16)& $FF)
    serial.tx((longitude >>24)& $FF)

    On the receive end:

    waint until serial.rx == ESCAPE_CHAR
    if serial.rx == ESCAPE_CHAR
    latitude := serial.rx
    latitude |= serial.rx<<8
    latitude |= serial.rx<<16
    latitude |= serial.rx<<24
    longitude := serial.rx
    longitude |= serial.rx<<8
    longitude |= serial.rx<<16
    longitude |= serial.rx<<24

    I couldn't find any exact snippets from my code, so this is untested, but this or something very similar has worked well for me in the past.
Sign In or Register to comment.