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 / qteye_picodvi.py
Last active May 20, 2024 01:16
qteye.py but on a PicoDVI RP2040 board in CircuitPython
# qteye_picodvi.py - qteye.py but on a PicoDVI RP2040 board
# 19 May 2024 - @todbot, on a DJDevon3 suggestion in Discord
# 23 Oct 2022 - @todbot / Tod Kurt
# Part of https://github.com/todbot/CircuitPython_GC9A01_demos
# also see: https://twitter.com/todbot/status/1584309133263532033
# and: https://twitter.com/todbot/status/1584309133263532033
# Copy this file as "code.py" and the two eyeball BMP files to CIRCUITPY drive
# To install needed libraries: "circup install adafruit_imageload"
#
# Video demo below as a comment to this gist
// esp32s3_i2s_simple_sine.ino
// demonstrate I2S on ESP32S3
// origally from guiguig on Discord: https://discord.com/channels/327254708534116352/422210663507558401/1240067408660795424
// video demo below in comment
#include <I2S.h>
#define BCK 16 // feather esp32s3 A2
#define DOUT 17 // feather esp32s3 A1
#define LCK 18 // feather esp32s3 A0
@todbot
todbot / fireworks_sprites.py
Last active May 15, 2024 00:05
Fireworks display using sprites in CircuitPython
# fireworks_sprites.py - show a bunch of fireworks
# 4 Jul 2022 - @todbot / Tod Kurt
import time, random
import board
import displayio
import rainbowio
import adafruit_imageload
fireworks_count = 5
sprite_fname = "fireworks_spritesheet.bmp"
@todbot
todbot / raise_vs_return_code.py
Created May 14, 2024 20:45
Attempt to estimate cost of exception raise vs return in CircuitPython
# raise_vs_return_code.py -- Attempt to estimate cost of exception raise vs return in CircuitPython
# 14 May 2024 - @todbot
import time
import random
import gc
num_runs = 50000
# functions that do a small amount of something but really nothing
@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 / rawhid_code.py
Last active May 6, 2024 14:49
circuitpython raw hid demo
# rawhid_code.py -- copy to CIRCUITPY as "code.py"
# don't forget to install rawhid_boot.py as "boot.py" and press reset
# works with report IDs up to 63 byte report count
# test with hidapitester like:
# ./hidapitester --usagePage 0xff00 --usage 1 --open -l 64 --send-output 2,3,4,5 --timeout 1000 --read-input 1
# adapted from code presented here:
# https://github.com/libusb/hidapi/issues/478
import time
import usb_hid
@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