Skip to content

Instantly share code, notes, and snippets.

from time import sleep_ms, sleep_us
from micropython import const
from machine import ADC, Pin
import rp2
import ttcontrol
a0 = ADC(Pin(45))
@MichaelBell
MichaelBell / synth.py
Created August 7, 2025 08:00
TinyQV pwl synth
import machine
import time
def play_raw(raw_period, amplitude, channel):
machine.mem16[0x800_01c0 + 2*channel] = raw_period
machine.mem16[0x800_01c8 + 2*channel] = amplitude
notes = {
'C': 909,
'C#': 801,
@MichaelBell
MichaelBell / tinyqv_ledstrip.py
Created July 27, 2025 21:12
TinyQV ledstrip peripheral example
# Demo for peripheral 18 on https://github.com/TinyTapeout/ttsky25a-tinyqv
import machine
import time
# HSV to RGB function for generating rainbows
def hsv_to_rgb(h, s, v):
if s == 0.0:
return v, v, v
i = int(h * 6.0)
f = (h * 6.0) - i
@MichaelBell
MichaelBell / bit_dump240.py
Created December 3, 2024 00:34
Bad Apple encoder
#!/usr/bin/env python3
import struct
from PIL import Image
out_file = open("badapple240x240.bin", "wb")
data_len = 0
colour_shift_changes = {
1: 6,
@MichaelBell
MichaelBell / power.py
Created December 1, 2024 22:39
RP2350 overclocking in Micropython
import machine
import time
machine.freq(100000000)
# Enable powman
machine.mem32[0x40100004] = 0x5AFEA050
def set_09():
# Reduce brownout
@MichaelBell
MichaelBell / lte-mqtt-bme.py
Last active January 15, 2025 18:45
Simple MQTT monitoring script using BME280 and LTE
from umqtt.simple import MQTTClient
from secrets import MQTT_SERVER, MQTT_USER, MQTT_PASS
import machine
import time
import ntptime
import gc
from breakout_bme280 import BreakoutBME280
from pimoroni_i2c import PimoroniI2C
PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5}
@MichaelBell
MichaelBell / pio_spi.py
Last active July 22, 2024 21:42
PIO SPI for RP2040 Micropython
# SPI using PIO, which is handy because you can use any pins.
import rp2
from machine import Pin
@rp2.asm_pio(out_shiftdir=0, autopull=True, pull_thresh=8, autopush=True, push_thresh=8, sideset_init=(rp2.PIO.OUT_LOW,), out_init=rp2.PIO.OUT_LOW)
def spi_cpha0():
out(pins, 1) .side(0x0)
in_(pins, 1) .side(0x1)
@MichaelBell
MichaelBell / OpenLane.md
Created February 9, 2024 21:45
Notes on patching OpenLane

Commit change to OpenROAD (or other tool), and push to GitHub

Patch dependencies/tool_metadata.yml with your repo and commit

In openlane/docker run make build-openroad_app. This will automatically build a build environment, and then build OpenRoad from the specified repo and commit. This takes about 30 mins, and unfortunately is re-done from scratch every time.

Run make openlane in the same directory

This prints the tag at the end of the build, set this as your OPENLANE_IMAGE to test.

@MichaelBell
MichaelBell / cell_auto.py
Created October 2, 2023 14:14
PicoVision Cellular Automata
import time
import math
import random
import machine
import gc
from picographics import PicoGraphics, PEN_RGB555, WIDESCREEN
machine.freq(125_000_000)
WIDTH = 360
@MichaelBell
MichaelBell / malloctest.c
Created March 17, 2021 19:06
Demonstration of malloc failure with 4KB heap left
#include <stdio.h>
#include <stdlib.h>
#include "pico/stdlib.h"
uint32_t use_almost_all_memory[63410];
int main()
{
stdio_init_all();