XBee - 232 Explorer - MicroPython

I’ve been going round in circles for days trying to do this.

I seem to be stuck down a small hole between everything I have read.

I’m using 2 (soon to be more) XBee 3 modules and I simply want to output some control data out of a sparkfun 232 explorer to a third-party device.

I’m using MicroPython as I don’t want any of the XBee packet data to go out with it.

I am successfully sending data from one XBee to another using its Node Identifier and the receiving XBee will print this out in REPL, but I need this to go out of the 232 shield.

I thought I would need to send it out of a UART port but I get “ImportError: cannot import name UART” so looks like I’m barking up the wrong tree.

This all works fine if I set the receiving XBee to API but as I said, I need the data to be “clean” so am using MicroPython.

This is the example code I’m using that works up to receiving the data

import xbee

print(" ±-------------------------------------+“)
print(” | XBee MicroPython Receive Data Sample |“)
print(” ±-------------------------------------+
")

print("Waiting for data…
")

while True:
# Check if the XBee has any message in the queue.
received_msg = xbee.receive()
if received_msg:
# Get the sender’s 64-bit address and payload from the received message.
sender = received_msg[‘sender_eui64’]
payload = received_msg[‘payload’]
print(“Data received from %s >> %s” % (‘’.join(‘{:02x}’.format(x).upper() for x in sender),
payload.decode()))

What am I looking for here to send data out? Serial? UART? an IO?

Any help appreciated.

Why are you not just using transparent mode?

2 Likes

(Which would be ATAP=0)

If ATAP=4, then print() will send data out the serial port (because REPL output is directed to the serial port).

If ATAP=1, then you can use User Data Relay frames to send data between MicroPython and your host processor, but it will need to parse the frames.

If ATAP=0, then any data you send to the module (in a “transmit” frame with default endpoint/cluster/profile settings) will just go out the serial port without any intervention. You wouldn’t need to make use of MicroPython at all.

1 Like

Because I need to do more than just this in MicroPython once I get this working

Ah! Didn’t realise that the REPL output went straight out… it was working the whole time but I didn’t check it as I thought I needed to send it somewhere else.

You can only use one mode or the other. You can’t intermix the two.

I don’t understand what you mean.

I don’t want to use transparent mode because I need to use MicroPython on all XBees

What I am saying is that you can’t intermix API mode and Micro Python mode. You can only use one or the other.

Thanks, I didn’t know that but that doesn’t apply to my problem does it?

It was you that suggested using ATAP=0, I am using ATAP=4 on all devices.

So that works fine, thanks.

So how about the reverse, reading responses from the local connection?

waits to kick self

device.read_data()
?

http://cms.digi.com/resources/documentation/digidocs/90002219/#reference/r_uart_constants.htm?Highlight=UART

That is how to use the Primary UART for accessing data from outside of the module in and out of Micro Python.

From @mvut’s comment to the other answer:
http://cms.digi.com/resources/documentation/digidocs/90002219/#reference/r_uart_constants.htm?Highlight=UART

Perfect, thank you.

Thanks @TonyCollins re sending data

If ATAP=4, then print() will send data out the serial port (because REPL output is directed to the serial port).

Thanks @mvut re receiving data

http://cms.digi.com/resources/documentation/digidocs/90002219/#reference/r_uart_constants.htm?Highlight=UART

That is how to use the Primary UART for accessing data from outside of the module in and out of Micro Python.