Home/Support/Support Forum/XBee - 232 Explorer - MicroPython

XBee - 232 Explorer - MicroPython

0 votes
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(" +
+\n")

print("Waiting for data...\n")


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
payload = received_msg
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.
asked Aug 6 in MicroPython by tdg New to the Community (14 points)

Please log in or register to answer this question.

3 Answers

+1 vote
 
Best answer
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.
answered Aug 7 by TomCollins Veteran of the Digi Community (1,961 points)
selected Aug 11 by tdg
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.
So that works fine, thanks.

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

*waits to kick self*
device.read_data()
?
+2 votes
Why are you not just using transparent mode?
answered Aug 6 by mvut Veteran of the Digi Community (13,036 points)
(Which would be ATAP=0)
Because I need to do more than just this in MicroPython once I get this working
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.
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.
Perfect, thank you.
0 votes
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.
answered Aug 12 by tdg New to the Community (14 points)
...