1
votes

I have a python script that I want to use to configure some XBee modules. It works perfectly find when connect to a computer via an xbee development board, but fails when connect to a raspberry pi via the slice of pi board.

I have narrowed down the problem to it failing to enter the command mode, after sending the +++ the xbee never sends the OK message. Here is the relevant code:

...
CC = '+'
GT = '1.1' # Tried different values here
...

def startCommandMode(self):
    self.emptyBuffer() # Tried with and without this line
    sleep(self.GT) # Tried with and without this line
    self.ser.write(self.CC + self.CC + self.CC)
    sleep(self.GT)
    return self.getReply() == 'OK'

...

def getReply(self):
    count = 0
    reply = ''
    while True:
        char = self.ser.read()
        if char == '\r':
            break
        if len(char) == 0:
            return None
        reply += char

    return reply

The full source is available on github if needed.

I know it is not a problem with the xbee module, the raspberry pi or the slice of pi board as it works perfectly fine if I try it manually using "picocom -lc /dev/ttyAMA0".

2
Can you confirm that sleep() is really sleeping for 1.1 seconds? - tomlogic
The default guard time on the xbee modules is 1 second and you have to make sure no reads happen before this. I have tried various values up to about 5 seconds with no success, so a little error in the timing is acceptable. And on my desktop all of these values work as expected. - James147

2 Answers

0
votes

Some things to check:

  • Are you getting anything in response?

  • Have you enabled flow-control on the XBee? Make sure D6 and D7 are set to 0 since the Raspberry Pi serial port doesn't have flow control.

  • Is the Python code configured for flow control? It might be waiting for a CTS signal that is never asserted.

  • Can you try using the XBee Development Board on the Raspberry Pi's USB port?

0
votes

Use the following:

....
if args.common:
    args.at = ['ID', 'CH', 'MY', 'DL', 'DH', 'AP'] + args.at
xbee = XBee(args.port, args.baud);
sleep(2)
xbee.CC = args.CC
xbee.GT = args.GT
....
....

IMHO I thick Rpi need more time to initialize serial port, thats why I am using this delay . Also is applicable for transparent mode so add a delay after port init.

I hope this will Ok for you. For me it is solved.

BR. Manel.