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)
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.
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?
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.
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.
Cheers!