So you want to use the UART...
Posted: Wed Jun 29, 2016 10:22 am
...to control something but can't because of the junk output and baud rate.
I want to share my solutions to the obvious problems using the UART to communicate with some other bit of kit.
The schematic is self-explanatory. There are plenty of perfectly valid ways of doing this and partly depends on what components you have lying about. If you have a board that already has pullups on some GPIO then you only need to add one common NPN transistor and one resistor.
When you actually want to transmit make the GPIO an output and pull it low and afterwards (allowing for transmission time) send it high or switch it back to input.
You should in any case call esp.osdebug(None) at startup as this reduces the chances of other unwanted output.
No doubt with better documentation one might be able to use official API but in the meantime...
You can use regular print to produce output but you want to read without blocking. With a heavyweight OS there are a multitude of methods but for now
I want to share my solutions to the obvious problems using the UART to communicate with some other bit of kit.
- Junk at startup and regular intervals. Some of this, such as "ip=..." comes from Espressif's binary blobs and short of patching those which might be worth trying my solution is with hardware
- Baud rate - easy to fix
- Non-blocking read - again straightforward
The schematic is self-explanatory. There are plenty of perfectly valid ways of doing this and partly depends on what components you have lying about. If you have a board that already has pullups on some GPIO then you only need to add one common NPN transistor and one resistor.
When you actually want to transmit make the GPIO an output and pull it low and afterwards (allowing for transmission time) send it high or switch it back to input.
You should in any case call esp.osdebug(None) at startup as this reduces the chances of other unwanted output.
No doubt with better documentation one might be able to use official API but in the meantime...
Code: Select all
def baudrate(rate):
machine.mem32[0x60000014] = int(80000000/rate)
Code: Select all
>>> uart = machine.UART(0)
>>> time.sleep(2); uart.read()
brexit yawn
b'brexit yawn'
>>>