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 <stonehippo@gmail.com>
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 & 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 / LICENSE
Last active November 9, 2022 20:00
A class for the SparkFun moto:bit for use with BBC micro:bit micro python
MIT License
Copyright (c) 2022 George White
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@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 August 26, 2022 14:13
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 August 23, 2022 20:27
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 July 27, 2022 14:49
Installing modern Marlin firmware on a PrintrBot Simple Maker 1405

Installing a modern Marlin firmware on PrintrBot Simple Maker 1405

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 of version I've installed) and a far cry from the laser-cut plywood assembly I started with. The chassis was upgraded from the original Maker design to the newer 1405 version, and the PrintrBoard is a Rev F5 (I still have the Rev D PrintrBoard I just as a replacement when the original died).

I have a lot of affection for my PrintrBot, even though I have now got a far more modern and capable printer, a

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

CircuitPython support for WiFi and Bluetooth LE on Seeed WIO Terminal

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) library on the Arduino side. This is good news, because it means that there is a chance that the driver can be implemented in CP! In theory, this can be built o