Page 1 of 1

Piping data from pyboard to serial to cat

Posted: Wed Apr 06, 2022 4:46 pm
by mathieu
I'm writing strings using pyb.USB_VCP() while my pyboard is connected to a laptop running macOS. I would expect that the following code would read this data and allow me to pipe it to another process, but no luck (cat remains silent). Am I doing something wrong? I'm looking for the very simplest method to pipe sensor readings from a pyboard to polt.

Code: Select all

# on the pyboard:
import pyb, time
vcp = pyb.USB_VCP()
while True:
    vcp.write('3.1416\n')
    time.sleep(1)

# on the laptop (there is only one usbmodem* port):
cat /dev/tty.usbmodem2052387C374E1

Re: Piping data from pyboard to serial to cat

Posted: Wed Apr 06, 2022 9:49 pm
by dhylands
Try using /dev/cu.usbmodem2052387C374E1 instead of /dev/tty.usbmodem2052387C374E1

The /dev/tty.usbmodem* port is designed for incoming serial connections when connected to an old-fashioned modem and will wait until the DCD signal is asserted before the open proceeds.

The /dev/cu.usbmodem* is designed for outgoing serial connections and doesn't wait for the DCD signal.

Some USB-to-serial adapters will assert DCD and some won't, so your best bet is to use /dev/cu.*

If you were using your own program (instead of cat) you can open the serial port in non-blocking mode and then turn blocking mode back on, something like this code does: https://github.com/dhylands/projects/bl ... #L213-L231 and then you can use /dev/tty.usbmodem* or /dev/cu.usbmodem* and it won't matter.

Most terminal programs (like minicom, picocom, putty, etc) will do the same non-blocking open dance.

Re: Piping data from pyboard to serial to cat

Posted: Thu Apr 07, 2022 7:06 am
by mathieu
That did the trick, and I learned something new. Thanks!

PSA: a combination of cat+polt makes it extremely easy to monitor various sensors on the fly, be it in the lab or in the field, and offers a lot of flexibility (cf polt docs). I wonder if this can somehow be done using Pythonista on iOS...

Thanks again.

Re: Piping data from pyboard to serial to cat

Posted: Thu Apr 07, 2022 9:50 am
by scruss
You might be able to feed the data directly to polt with something like:

Code: Select all

polt < /dev/cu.usbmodem2052387C374E1