Hi,
I am looking for a working snippet of a communication over USB to a Xiao ESP32S3.
What I have tried (well, too many things to post here) as reference:
On the PC:
import serial
import time
# Configuration
COM = "COM4"
BUADRATE = 115200
while True:
try:
with serial.Serial(COM, baudrate=BUADRATE, timeout=1) as ser:
print(f"Listening...")
time.sleep(1) # Give time to the ESP32 to send data
while ser.in_waiting > 0:
incoming_data = ser.read_all()
if incoming_data:
print(f"Received: {incoming_data}")
except Exception as e:
print(f"Error: {e}")
time.sleep(1)
if "KeyboardInterrupt" in str(e):
break
On the Xiao ESP32S3:
import uos
import machine
import time
UART = 0
BAUDRATE = 115200
time.sleep(1.5)
uos.dupterm(None, UART) # detach UART from REPL
uart = machine.UART(UART, baudrate=BAUDRATE)
count = 0
while count < 10:
count += 1
uart.write(b"Hello PC\n")
print("Sent")
time.sleep(.5)
Interestingly enough, I get the “Sent” message but not the expected ‘b"Hello PC\n"’.
What am I doing wrong? Thanks!