3
\$\begingroup\$

I am having the hardest time trying to get my XBEE's to work with my Raspberry pi (RP). I have one on a USB breakout board into my computer and the other XBEE connected to a RP. The one on the RP is the API coordinator and the one in the computer is the AT router. When I run this program on the RP (which should change one of the IO pins on the router XBEE)

    #!/usr/bin/python
import serial
print("TEST")
ser=serial.Serial('/dev/ttyAMA0', baudrate=9600)
print(ser)
ser.write('\x7E')
ser.write('\x00')
ser.write('\x10')
ser.write('\x17')
ser.write('\x00')
ser.write('\x00')
ser.write('\x00')
ser.write('\x00')
ser.write('\x00')
ser.write('\x00')
ser.write('\xFF')
ser.write('\xFF')
ser.write('\xFF')
ser.write('\xFE')
ser.write('\x02')
ser.write('\x44')
ser.write('\x01')
ser.write('\x05')
sum=(0x17+0xFF+0xFF+0xFF+0xFE+0x02+0x44+0x01+0x05)
check=(0xFF - ( sum & 0xFF ))
ser.write(chr(check))
ser.close()
print("DONE")

Nothing gets done on the router though. I believe the XBEE's are connected because when I plug in the router to the computer, I get a message on the serial port the RP notifying it that something has joined. I am out of ideas, and I was hoping someone could help me out.

\$\endgroup\$
4
  • \$\begingroup\$ Do you have an oscilloscope to use? If so that would be your best way to diagnose a problem like this. \$\endgroup\$
    – Reid
    Apr 11, 2013 at 19:19
  • \$\begingroup\$ I do. What were you thinking? I think the problem is why the coordinator is not transmitting. How can I tell that with an oscilloscope? \$\endgroup\$
    – Ryan F
    Apr 12, 2013 at 15:17
  • \$\begingroup\$ I'd worry about how this went out on the wire. There may be timeouts between characters that are messing you up. If you can, look at a scope to see the difference between the working version in the app and your python version. If you can't do that... try to assemble the message in a buffer and send the buffer all at once. \$\endgroup\$
    – darron
    May 13, 2013 at 14:43
  • \$\begingroup\$ Are you sure your code is correct? That checksum calculation looks suspect to me ((0xFF - ( sum & 0xFF ))?). I'd store your whole packet as a string, and compute the checksum by iterating over the string. That way, you won't have possible transcription errors. \$\endgroup\$ Jun 11, 2013 at 22:15

2 Answers 2

1
\$\begingroup\$

You are using API mode; is that escaped API (ATAP=2) or non-escaped API? The frame you are sending has to be escaped/non-escaped to match the setting configured on the sender XBee.

Try achieving some kind of transmission in AT mode first; when that works, then upgrade to API mode.

\$\endgroup\$
1
  • \$\begingroup\$ I've not found AT mode good for much other than when using a terminal, or for getting a device which in factory-default state out of AT mode. If a non-crashed XBEE is in escaped API mode, it should unconditionally respond to something like an "SL" command packet which is sent in that mode, and the response should be clear and unambiguous. \$\endgroup\$
    – supercat
    Dec 9, 2013 at 16:53
0
\$\begingroup\$

I don't know XBee, but it looks like your length byte is 0x10 (16) and your message is only 15 bytes long.

Also you repeat the message in code twice, which is just bad practice.

Try code like this (untested):

#!/usr/bin/python
import serial
print("TEST")
ser=serial.Serial('/dev/ttyAMA0', baudrate=9600)
print(ser)

msg=[0x17,
     0x00,
     0x00,
     0x00,
     0x00,
     0x00,
     0x00,
     0xFF,
     0xFF,
     0xFF,
     0xFE,
     0x02,
     0x44,
     0x01,
     0x05]

ser.write(chr(0x7e)+
          chr(len(msg)//256)+
          chr(len(msg)%256))
ser.write(''.join(chr(x) for x in msg))
check=(0xFF - ( sum(msg) & 0xFF ))
ser.write(chr(check))
ser.close()
print("DONE")
\$\endgroup\$
1
  • \$\begingroup\$ So I tried this, and it didn't work. Here is what I have learned in the last couple days. I opened XCTU the program that comes with the XBee. I was able to send the hex stream 7E 00 10 17 05 00 13 A2 00 40 A0 D2 93 FF FE 02 44 34 03 6F by using the "assemble packet" function. The problem seems to only be when I am sending the bytes from Python. Is there a way to make a byte stream or something like that. I have a feeling Python is sending the string incorrectly. Additionally, using the XBEE Java library, I was able to send API frames too. Does anybody know what I am doing wrong in Python? \$\endgroup\$
    – Ryan F
    Apr 14, 2013 at 9:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.