Page 1 of 1

Noob question: how to send and receive bytes over USB?

Posted: Fri Jan 04, 2019 9:48 pm
by superquest
(I also posted on Loboris' forum)

I'm using loboris' fork with an m5stack. I'm trying to send bytes to and receive bytes from the device using PySerial.

On the m5stack side I've tried

Code: Select all

from machine import UART
import utime

uart = UART(1, tx=22, rx=21)

def main():
    while True:
        msg = uart.readline()
        print(msg)
        utime.sleep(1)

if __name__ == '__main__':
    main()
On the PySerial side I tried

Code: Select all

ser = serial.Serial('/dev/ttyUSB0')
ser.write(b"hello, world!")
Interestingly, when I connect to MicroPython REPL using screen, I do see the "hello, world!" prints to the input line in my MicroPython REPL as if I typed it but didn't hit enter!

The m5stack just prints empty strings. Any hints on how to read the bytes PySerial is sending?

I've seen people recommend pyb.USB_VCP but it seems that's not available on esp32 ...

Also I see that loboris defines machine.stdin_get(bytes, timeout) but that only returns "bytes"-many \x00 bytes whenever I try to send it a bytestring from PySerial.

Would appreciate any direction I can get. Thanks!

Re: Noob question: how to send and receive bytes over USB?

Posted: Sat Jan 05, 2019 3:45 am
by superquest
Where should I look to fill in the parameters to machine.UART constructor? There's a UART id, "rx" and "tx" values. I understand that "rx" and "tx" correspond somehow to wires, but don't know more than that ....

Re: Noob question: how to send and receive bytes over USB?

Posted: Sat Jan 05, 2019 4:33 am
by superquest