XBee3 access TX serial with MicroPython for Simplified Serial use

Good morning everyone!

I have a motor driver that i want to directly control with a simple XBee3 (XB3-24Z8PT-J).
Until now I would have use an intermediate cpu like an Arduino, but now we have MicroPython!

The motor driver needs to receive TTL level single-byte serial commands of 8 bits and it is a one direction only interface (no RX needed on the XBee, just TX).

I want to receive lets say a transmit packet with a json payload and depending on the content of the json send the correct command to the motor driver. 9600 Baud rate is enough.

I do not need to monitor anything on a console, so I can use [AP] = [1, 2, 4]. (I do not want to use transparent mode)

Any idea how to achieve that?


If you want the Micro Python on the remote end, then you would use AP 4 which uses Micro Python mode. From there, you would want to use the Micro Python Serial port for the data to come out of.

There are examples in the PyCharm IDE that Digi has created that should allow you to see how to perform the functions you desire.

Digi Support

1 Like

Correct me if I am wrong but the example you are referencing to are for “cellular” XBees which have indeed a second UART port accessible through MicroPython.

However I do not have a cellular XBee3 and I do not plan to buy one.

I only need transmission of 8bits of data at a time following TTL level 8N1 - 9600 baudrate.

For now I will try to bit bang these 10bits and see if it works!

Bit banging did not work as it takes around 5ms for a normal GPIO (GPIO4) to switch from one state to the other. Are there any fast pins I could use for bit banging from MicroPython?

No, these are the only ones that would use UART data in and out from Micro Python application to an external device.

Alright! I hope Digi will implement UART for the XBee3 soon! It would be a life changer!
Thanks again mvut!

I finally managed to find a solution.

In MicroPython using this:

from sys import stdout

I then matched the UART baudrate of the XBee3 with XCTU to the speed on the remote motor driver.

As a final answer:

using stdout worked but there are many messages that are printed in the stdout that I have no control on, so it is quite unsafe.

In the end I gave up the idea and replaced my motor driver with PWM controlled ones.

i had this issue too. thanks for sharing and thanks for answers

I’d love to have access to the machine uart class, maybe in the future!

As I was saying, it can be a bit dangerous as the a few micropython messages and errors are automatically print in the dout, and that can mess up your application. So make sure you have a way to deal with these.


I’m trying to make some SDISerial communication can you please feed us with some details or code ?

That’s it really.
I’m not very good with low level programming so there must be tons of things I oversee…
I was basically send 3 bytes with stdout.buffer.write(), start data and stop if I recall correctly. But for example if the python program were to bug, it would write the error message on the stdout as usual, sending random command to the motor driver, and that is not what you want on a safe device.
Therefore I quickly bought a new motor driver with a PWM control and that works great.