Skip to content

Instantly share code, notes, and snippets.

View todbot's full-sized avatar
💭
doing the blink1

Tod Kurt todbot

💭
doing the blink1
View GitHub Profile
@todbot
todbot / !midi_host_issue.py
Last active May 12, 2024 20:40
demonstrate odd usb.core.USBError with max3421e, circuitpython
# demonstrate odd usb.core.USBError with max3421e
# requires "adafruit_usb_host_midi_todbot" below, which adds timeout on read()s
# 12 May 2024 - @todbot
import displayio
displayio.release_displays()
import time
import board
import usb
import max3421e
@todbot
todbot / !usb_host_midi_monitor.py
Last active May 8, 2024 23:14
Demonstrate trying to use the USBError of usb.core.Device.read()
# Demonstrate trying to use the USBError of usb.core.Device.read() as a
# "no bytes available" indicator. Unfortuately, it's VERY slow.
# Or more likely, it's missing messages mid-parse.
# 8 May 2024 - @todbot
#
# note, this requires two special libraries:
# - adafruit_usb_host_midi_hostreadhack
# - winterbloom_smolmidi_hostreadhack
import time
@todbot
todbot / waiting_for_midi_code.py
Created May 7, 2024 00:13
I'm always blocking for midi
# waiting_for_midi_code.py -- I'm always blocking for midi
# 6 May 2024 - @todbot
# works on PicoDVI RP2040 Feather / DVI Cowbell / etc.
import time, math, random
import board
import displayio
import bitmaptools
from adafruit_display_text import bitmap_label as label
num_colors = 16 # how many colors for our bitmap, can't be over 16 for DVI
@todbot
todbot / max3421_midi_test.py
Created May 5, 2024 01:24
CircuitPython midi, usb.core and max3421 blocking issues
# demonstrate blocking of usb.core.Device.read()
# 4 May 2024 - @todbot and @jedgarpark
"""
This sketch demonstrates how `device.read()` blocks infinitely, which is different from established behavior.
The normal semantics of `device.read()` when using either `busio.UART` or `usb_midi.PortIn`
is that the read() does not noticably block if a `timeout` is given.
(Explicitly in the constructor of `busio.UART` and apparently implicitly in just how `usb_midi` works)
But for the `usb.core.Device` that is returned (as demo'd below), the `device.read()` blocks forever.
# SPDX-FileCopyrightText: Copyright (c) 2023 Scott Shawcroft for Adafruit Industries
# SPDX-FileCopyrightText: Copyright (c) 2024 Tod Kurt
#
# SPDX-License-Identifier: Unlicense
#
# Forward MIDI from device on USB Host port to computer via USB MIDI
# and 5-pin serial MIDI via MIDI Feather Wing or similar MIDI output.
# Suppots hot-plug of the device on the USB Host port.
#
# adapted from https://github.com/adafruit/Adafruit_CircuitPython_USB_Host_MIDI/blob/main/examples/usb_host_midi_simpletest.py
@todbot
todbot / cpx_midi_controller.py
Last active May 1, 2024 15:15
Quick-n-dirty MIDI controller with Circuit Playground Express in CircuitPython
# quick-n-dirty MIDI controller with Circuit Playground Express
# 30 Apr 2024 - @todbot / Tod Kurt
# Works on Circuit Playground Express in CircuitPython 9,
# but will also work on also any board with touchio, like Trinket M0 or QTPy M0
# Uses the minimal number of libraries to save RAM on the tiny M0 in the CPX
# (e.g. cannot load `adafruit_circuitpython`, `adafruit_midi`, and `adafruit_debouncer` on CPX)
import board
import touchio
import usb_midi
@todbot
todbot / button_input_blink_led_samd_assembly.s
Last active April 21, 2024 22:13
Read button and control LED on SAMD21 in assembly
@todbot
todbot / blink_led_samd_assembly.s
Last active April 15, 2024 01:07
samd21 blink LED on PA06 on Trinket M0
@todbot
todbot / blink_led_samd.c
Last active April 13, 2024 20:53
samd21 blink LED in C, no SDK
@todbot
todbot / bitmapfilter_play3_code.py
Created April 3, 2024 15:00
bitmapfilter playing w/ channel ops and blur on random lines in CircuitPython
# bitmapfilter_play3_code.py -- chops + blur on random lines
# 2 Apr 2024 - @todbot / Tod Kurt
import time, math, random
import board
import rainbowio
import vectorio
import displayio
import bitmaptools
import bitmapfilter
import gc