I was trying to get some CP code to talk to Processing over a serial port interface. Of course, the CP REPL is normally available on whatever serial port the board mounts by default. This is a little complicated, because although you can use something like print
from the REPL (or code.py
) to print a value to the console, sys.stdin
and sys.stdout
are text-based streams, which may not be what you want. And you'll get REPL noise to boot. Not ideal.
This is where usb_cdc
comes in. It's a handy library for managing the USB CDC (serial) on most CircuitPython boards. First, usb_cdc
can be used to control how many serial ports CP will provide at startup. You can modify boot.py
to make this work:
import usb_cdc
usb_cdc.enable(console=True, data=False)