Skip to content

Instantly share code, notes, and snippets.

@stonehippo
stonehippo / RGB_strip_control.py
Created November 16, 2023 15:30
Some CircuitPython to control an RGBW LED strip.
"""
Simple CircuitPython control of an RGB strip via Mosfetti or plain MOSFETS.
Copyright (c) 2023 George White <[email protected]>
Written for the Adafruit Metro M0, but will work with any board with
4 PWM-capable pins.
"""
import board
from pwmio import PWMOut
@stonehippo
stonehippo / update_circuitpy.sh
Created September 4, 2023 20:08
shell script to update CircuitPython build files
cd ~/circuitpython
git pull
git submodule sync
git submodule update --init
cd $OLDPWD

Hallowing M4: Enable audioio & touchio

The Adafruit Hallowing M4 is a feature-filled development board, including four capacitve touch "teeth" at the bottom of it's skull-shaped circuit board.

CircuitPython has a nifty module for working cap touch pins, touchio. However, the Hallowing M4 uses an Atmel SAMD51, which doesn't handle cap touch in hardware (unlike the SAMD21 in the Hallowing M0). If you try to use the cap touch pins without some additional setup, you'll get an error.

import board
import touchio
@stonehippo
stonehippo / micropython_motobit.md
Last active November 28, 2024 19:31
A class for the SparkFun moto:bit for use with BBC micro:bit micro python

SparkFun moto:bit driver for BBC micro:bit micropython

The SparkFun moto:bit is a motor controller carrier for the BBC micro:bit. This board is also available as part of the SparkFun micro:bot kit.

SparkFun provides a MakeCode extension for using this board, but no driver for working with the board using micro:bit-flavored micropython. Given the spiffy new micro:bit Python Editor, it would nice to be able to program this motor controller in micropython. This class makes that easy to do.

The code has been moved to a new repo: https://github.com/stonehippo/micropython_motobit.

Usage

@stonehippo
stonehippo / README.md
Last active December 29, 2023 00:49
Making a little dice roller in modern Python

A tiny dice roller in modern Python

I have been reading Fluent Python, and I can tell that it's going to help me be a better Python coder right away.

A while ago, I started a Javascript library for rolling common dice types, which I intended to use for various games. While reading Fluent Python, I realized that I could write the same logic in a much more compact form, thanks to listcomps, generator functions, and unpacking. In fact, the core implementation takes only four lines of code:

sides = [4, 6, 8, 10, 12, 20]
d4, d6, d8, d10, d12, d20 = [range(1, count + 1) for count in sides]
@stonehippo
stonehippo / knock_knock.ino
Last active November 27, 2024 23:06
A simple Arduino piezo knock sensor that cycles through a series of RGB LED patterns
// define pins for the RGB LED
byte led_red_pin = 3;
byte led_green_pin = 5;
byte led_blue_pin = 6;
int piezo_pin = A0;
int piezo_threshold = 250; // This may have to be tuned for your piezo
int wait = 10000; // the time before the last night and the cycle resets
int debounce = 200; // the number of milliseconds we'll wait to reject bad input
@stonehippo
stonehippo / ssd1306_I2C_setup.py
Last active January 7, 2025 22:50
Basic setup of an SSD1306-based I2C display using CircuitPython Display
import board
import displayio
import terminalio
import adafruit_displayio_ssd1306
from adafruit_display_text import label
from adafruit_displayio_layout.layouts.grid_layout import GridLayout
# release any displays that have already been set up
displayio.release_displays()
@stonehippo
stonehippo / pseudo-screamer.ino
Created August 8, 2022 02:19
A quick test of the screamer
#define SOUND_TRIGGER 9 // the pin attached to a trigger on the sound FX board
void setup() {
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
// set up the pin for the sound trigger, including pulling it high
pinMode(SOUND_TRIGGER, OUTPUT);
digitalWrite(SOUND_TRIGGER, HIGH);
@stonehippo
stonehippo / printrbot_simple_maker_modern_marlin.md
Last active December 25, 2024 02:55
Installing modern Marlin firmware on a PrintrBot Simple Maker 1405

Installing a modern Marlin firmware on PrintrBot Simple Maker 1405

note: I created a repo with the firmware I generated at the time I wrote this gist. If you want to see the config, try out the firmware, or have a go at building your own, you can check it out at https://github.com/stonehippo/printrbot_simple_maker_1405_firmware

The first 3D printer I acquired is a PrintrBot Simple Maker, a little 3D printer kit from the early days of DIY RepRap. I've had this little mostly plywood printer for years, and it taught me a lot about additive manufacturing and 3D design. I have updated and upgraded it multiple times, and like a robotic Ship of Theseus, I've replaced enough components that it's fair to say the device I'm using now is barely the same machine I put together the first time I opened that box of parts. The extruder now is a pretty nice aluminum unit (the second metal version I've installed) and a far cry from the laser-cut plywood assembly I started with. The chassis was upgraded from the origina

@stonehippo
stonehippo / wio_terminal_cricuitpython_rtl_support_notes.md
Last active December 1, 2024 22:22
Working notes for getting Seeed WIO Terminal WiFi & BLE working with CircuitPython

CircuitPython support for WiFi and Bluetooth LE on Seeed WIO Terminal

I won't be updating this gist any longer. Updated versions of these notes can be found here.

Context

The Seeed WIO Terminal is generally supported by CircuitPython, but there is no implementation for access to the WiFi or Bluetooth LE networking functions on the board. After taking a look at the Arduino support for these features, I can see that the RealTek RTL8720D is set up to be driven by a UART connection from the SAMD51 that acts as the main controller for the WIO Terminal. In other words, the RTL8720D is set up as a co-processor, similar to the ESP32 in Adafruit's Airlift modules.

The UART driver is based on an [embedded remote procedure call (eRPC) libr