Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
doing the blink1

Tod Kurt todbot

💭
doing the blink1
View GitHub Profile
@todbot
todbot / bitmaplines.py
Created Sep 22, 2022
simple "generative art" using CircuitPython and displayio.Bitmap
View bitmaplines.py
# bitmaplines.py -- simple "generative art" using CircuitPython and displayio.Bitmap
# 22 Sep 2022 - @todbot / Tod Kurt, from @jedgarpark's 22 Sep 2022 CircuitPython Parsec
# Video: https://youtu.be/5TFOlvQUbn8
import board, displayio, time
import random
display = board.DISPLAY
num_colors = 5
bitmap = displayio.Bitmap( display.width, display.height, num_colors )
@todbot
todbot / midi_visualizer.py
Last active Aug 31, 2022
Show incoming MIDI as raining MIDI notes on Neopixel grid / matrix in CircuitPython
View midi_visualizer.py
# midi_visualizer.py -- show incoming MIDI as raining MIDI notes on Neopixel grid / matrix
# 31 Aug 2022 - @todbot / Tod Kurt
# inspired by
# https://www.reddit.com/r/esp32/comments/wwah4v/i_made_a_midi_to_led_interface_with_an_esp32_more/
# uses SmolMIDI from Winterbloom: https://github.com/wntrblm/Winterbloom_SmolMIDI
import time
import board
# libraries installed with circup
@todbot
todbot / circuitpython_native_module_Aug2022.md
Last active Aug 26, 2022
Adding new native module to CircuitPython Aug 2022
View circuitpython_native_module_Aug2022.md

Intro

"You want to make a native module for CircuitPython" as of 25 Aug 2022.
Short answer: copy what rainbowio does. It does everything the below describes and is known to work well.

What we'll be changing

Let's assume your library is called chicken, with no port-specific functionality, and a single function called bokbok(), that takes an int and returns an int.

Your CircuitPython code to use it would look like:

@todbot
todbot / udp_recv_code.py
Last active Aug 25, 2022
UDP sender and receiver in CircuitPython
View udp_recv_code.py
# udp_recv_code.py -- receive UDP messages from any receiver, can be another CircuitPython device
# 24 Aug 2022 - @todbot / Tod Kurt
# cribbing from code at https://github.com/adafruit/circuitpython/blob/main/tests/circuitpython-manual/socketpool/datagram/ntp.py
import time, wifi, socketpool
from secrets import secrets
print("Connecting to WiFi...")
wifi.radio.connect(ssid=secrets['ssid'],password=secrets['password'])
print("my IP addr:", wifi.radio.ipv4_address)
pool = socketpool.SocketPool(wifi.radio)
View fakeycapsense_demo.ino
// fakeycapsense_demo.ino -- implement a fakey capsense touch sensor using same technique as in CircuitPython
// 2 Aug 2022 - @todbot / Tod Kurt
///////////////
class FakeyTouch
{
public:
FakeyTouch( int apin, int athreshold = 200 ) {
pin = apin;
thold = athreshold;
@todbot
todbot / displayio_hx8357_framerate_test.py
Last active Jul 31, 2022
Test how fast doing full screen refresh is on Feather RP2040 and HX8357 480x320 FeatherWing display over SPI
View displayio_hx8357_framerate_test.py
# displayio_hx8357_framerate_test.py
# 31 Jul 2022 - @todbot / Tod Kurt, from DJDevon3 full-screen spritesheet bitmap
import time
import board, digitalio, busio
import displayio, terminalio
import adafruit_hx8357
from adafruit_display_text import label
import adafruit_imageload
sprite_fname = "Clouds_22_Spritesheet256nc_crop-0.bmp" # only half screen, and scaled 50%
@todbot
todbot / vectorio_rotate_example.py
Created Jul 21, 2022
Demo rotation of a vectorio polygon
View vectorio_rotate_example.py
# vectorio_rotate_example.py
# 21 Jul 2022 - @todbot / Tod Kurt
# Demo rotation of a vectorio polygon
import time
import board
import displayio
import vectorio
import math
#import ulab.numpy as np
@todbot
todbot / touch_analog_code.py
Last active Jul 21, 2022
Demo analog touch value using raw_filter and filtering with CircuitPython touchio
View touch_analog_code.py
# touch_analog_code.py -- demo analog touch value using raw_filter and filtering
# 21 Jul 2022 - @todbot / Tod Kurt
# A simpler version of concept in "Trinkey Theramin" (sic)
# https://gist.github.com/todbot/50c0f388add780f9d75489e0bebad96c
import time
import board
import touchio
touch_pin = touchio.TouchIn(board.A3) # can be almost any pin on most boards
@todbot
todbot / gamepad16_boot.py
Last active Jul 20, 2022
Simple 16-button gamepad demo in CircuitPython
View gamepad16_boot.py
# gamepad16_boot.py -- this must be named "boot.py" on CIRCUITPY drive
# 19 Jul 2022 - @todbot / Tod Kurt
# Copies heavily from: https://github.com/adafruit/Adafruit_CircuitPython_HID/blob/main/examples/hid_gamepad.py
# and https://learn.adafruit.com/customizing-usb-devices-in-circuitpython/hid-devices#custom-hid-devices-3096614
# Use https://gamepadtest.com/ to see it work
#
# Note all '##' comments: the values in the GAMEPAD_REPORT_DESCRIPTOR must match the "gamepad" object
import usb_hid
@todbot
todbot / slidertest.swift
Last active Jul 18, 2022
Playing around with SwiftUI Sliders, copying Carlyn
View slidertest.swift
//
// slidertest - copy into a blank Playground
//
// Created by Tod Kurt on 7/17/22.
//
import SwiftUI
// given 0-1 val, return 0-1 with log curve