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

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
superquest
Posts: 6
Joined: Mon Sep 03, 2018 1:22 am

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

Post by superquest » Fri Jan 04, 2019 9:48 pm

(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!
Last edited by superquest on Sat Jan 05, 2019 8:08 am, edited 2 times in total.

superquest
Posts: 6
Joined: Mon Sep 03, 2018 1:22 am

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

Post by superquest » Sat Jan 05, 2019 3:45 am

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 ....

superquest
Posts: 6
Joined: Mon Sep 03, 2018 1:22 am

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

Post by superquest » Sat Jan 05, 2019 4:33 am


Post Reply