Skip to content

Instantly share code, notes, and snippets.

@todbot
Created May 25, 2026 20:54
Show Gist options
  • Select an option

  • Save todbot/94a81da36c123c546599c295996fc73c to your computer and use it in GitHub Desktop.

Select an option

Save todbot/94a81da36c123c546599c295996fc73c to your computer and use it in GitHub Desktop.
USB HID Keyboard LED emulator in CircuitPython
import time
import usb_hid
import adafruit_hid
keyboard_hid = adafruit_hid.find_device(usb_hid.devices, usage_page=1, usage=6)
print("waiting for LED commands from computer")
while True:
out_report = keyboard_hid.get_last_received_report() # out from computer
if out_report:
print(["%02x" % x for x in out_report])
time.sleep(0.5)
# Note in Linux you can then toggle the LEDs with:
# echo "1" | sudo tee -a /sys/class/leds/input41::scrolllock/brightness
# echo "0" | sudo tee -a /sys/class/leds/input41::scrolllock/brightness
# and "input41" will change depending on when and where you plug in your CircuitPython device.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment