As @jimmo said, software serial is not expected to work. Unlike the Arduino, the ESP32 has no guaranteed response time to interrupts, making receiving almost impossible, unless you can deal with really slow data rates, like <300 baud. Sending is possible in the actual port using the RMT hardware and the write_pulses() API. The corresponding read_pulses method is not yet implemented. If that helps: for sending, there is a short snippet below, which I used. It worked well with 9600 Baud. Should be fine for faster rates up to 38400 baud too.
Code: Select all
class RMT_UART:
def __init__(self, gpio, *, status=None, restart=None, baudrate=BAUDRATE):
self.rmt = RMT(0, pin=Pin(gpio), clock_div=80, idle=1)
self.duration = 1000000 // baudrate # tick duration 1us
def send(self, msg):
if type(msg) is str:
msg = msg.encode()
for byte in msg:
data = [self.duration] # start bit
state = 0
# create data bits
for bit in range(8):
if (byte & 1) == state:
data[-1] += self.duration
else:
data.append(self.duration)
state = byte & 1
byte >>= 1
self.rmt.write_pulses(data, start=0)
self.rmt.wait_done(timeout=self.duration * 9) # Wait for the end
sleep_us(self.duration * 2) # Two stop bits