Releases: MrJake222/micropython
Releases · MrJake222/micropython
v1.17.1 with ESP-8266 SoftUART support
class SoftUART - half-duplex serial communication
SoftUART implements the standard UART/USART half-duplex serial communications protocol.
Supported communication parameters are:
- 8 data bits,
- 1 stop bit,
- No parity,
- 1M-baud tested with nothing running in the background.
Initialization
from machine import SoftUART, Pin
uart = SoftUART(tx=Pin(2), rx=Pin(4))
uart.init(baudrate=9600, timeout=0)Constructors
class machine.SoftUART(tx=Pin(Tx), rx=Pin(Rx))Tx- pin used for data transmissionRx- pin used for data reception
Methods
SoftUART.init(tx=Pin(Tx), rx=Pin(Rx), baudrate=9600, bits=8, parity=None, stop=1)
Basically constructor without additional memory allocation.Tx- pin used for data transmissionRx- pin used for data receptionbaudrate- data ratebits- data bits (only 8 supported)parity- data parity bit (only None supported)stop- stop bits (only 1 supported)
SoftUART.deinit()
Frees memory.SoftUART.read(n)SoftUART.readline()
Unreliable.SoftUART.readinto()
Not tested.SoftUART.write(buf)
Stream API
SoftUART supports stream API (select.select, select.poll, etc.)
Changelog
- Changed API. Moved tx/rx to kwargs.
v1.17 with ESP-8266 SoftUART support
Software UART support for ESP-8266
- Adapted from dmascord,
- Added multiple instances support,
- See commit history for more info.
Examples
Read
# test suite for SoftUART
from machine import SoftUART, Pin
import time
import select
poll = select.poll()
s1 = SoftUART(Pin(2), Pin(4), baudrate=9600, timeout=0) # tx=2 rx=4
s2 = SoftUART(Pin(0), Pin(5), baudrate=9600, timeout=0) # tx=0 rx=5
poll.register(s1)
poll.register(s2)
print("polling...")
while True:
read = poll.ipoll()
for r, ev in read:
if (ev & select.POLLIN) != 0:
i = None
if r is s1:
i = "s1"
else:
i = "s2"
print(i, r.read())
Write
# test suite for SoftUART
from machine import SoftUART, Pin
import time
s1 = SoftUART(Pin(2), Pin(4), baudrate=9600, timeout=0) # tx=2 rx=4
s2 = SoftUART(Pin(0), Pin(5), baudrate=9600, timeout=0) # tx=0 rx=5
while True:
print("sending... ", end="")
s1.write("Hello world s1\r\n")
print("1, ", end="")
s2.write("Hello world s2\r\n")
print("2, done.")
time.sleep(1)