Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Disable USB devices in CircuitPython in
# Turn on/off certain USB features based on touching RX & TX pins
# Squeeze TX & RX pins with fingers to enable CIRCUITPY & REPL
# Otherwise, they are turned off
# CircuitPython 7.x only
# Rename this as "" in your CIRCUITPY drive on a QT PY
# @todbot 17 May 2021
import time
import board
import neopixel
import touchio
print("hello from") # see this in 'boot_out.txt'
led = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2)
touch1in = touchio.TouchIn(board.RX)
touch2in = touchio.TouchIn(board.TX)
if touch1in.raw_value > 1500 and touch2in.raw_value > 1500:
print("both RX & TX touched! Keeping ON USB devices")
for i in range(5): # blink LED
led[0] = 0x00ff00
led[0] = 0x000000
# or enable just certain HID devices
#import usb_hid
print("RX & TX not touched. Turning OFF USB devices")
import storage
import usb_cdc
import usb_midi
storage.disable_usb_drive() # disable CIRCUITPY
usb_cdc.disable() # disable REPL
usb_midi.disable() # disable MIDI
#import usb_hid
#usb_hid.disable() # could also disable HID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment