Skip to content

Instantly share code, notes, and snippets.

View nari4169's full-sized avatar

Billcorea nari4169

View GitHub Profile
@nari4169
nari4169 / gist:c23ad1f67bce6b6d733bb546596a4991
Created August 5, 2024 11:04 — forked from stonehippo/using_circuitpython_native_used_for_serial_data.md
A note to self about using the CircuitPython native USB for serial data with usb_cdc

Using the CircuitPython native USB for serial data

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)