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 / xiao_esp32c6_blink_button.ino
Last active September 24, 2025 23:07
Arduino code to read a button & blink a normal LED and a Neopixel on XIAO ESP32C6 w/ Adafruit Button BFF
@todbot
todbot / http_request_byhand.c
Last active September 8, 2025 02:22
simple "HTTP by hand" in ESP-IDF
// simple "HTTP by hand" in ESP-IDF
// add "REQUIRES esp_wifi esp_netif nvs_flash" to CMakeLists.txt
#include <string.h>
#include <sys/socket.h>
#include <netdb.h> // getaddrinfo()
#include "esp_wifi.h"
#include "esp_event.h"
#include "esp_log.h"
#include "nvs_flash.h"
@todbot
todbot / default.conf
Created August 9, 2025 21:35 — forked from SurajDadral/default.conf
Enable PHP and CGI in user directory (public_html) in nginx
# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
@todbot
todbot / circuitpython_font_play_code_simple.py
Last active August 14, 2025 21:43
playing with adafruit circuitpython-fonts package
# circuitpython_font_play_code_simple.py -- playing w adafruit circuitpython-fonts
# 8 Aug 2025 - @todbot / Tod Kurt
# developed on a Lilygo T-Display S3 w/ ST7789 display in paralleldisplaybus mode
# To use this, first install 'circup' and do what's described here:
# https://github.com/adafruit/circuitpython-fonts/
# e.g.:
# circup bundle-add adafruit/circuitpython-fonts # You only need to do this once
# circup show | grep 48 | grep font # find fonts that are size 48
# circup install font_... # find a font you like & install it, like:
# circup install font_raleway_medium_48
@todbot
todbot / analog_buttons.py
Last active July 30, 2025 21:10
Use ADC and resistors to give you multiple buttons on single analog pin, for CircuitPython
# AnalogButtons - use ADC to give you multiple buttons
# 29 Jul 2025 - @todbot / Tod Kurt
# from an issue https://github.com/adafruit/circuitpython/issues/105272
# wiring is similar to https://www.instructables.com/How-to-Multiple-Buttons-on-1-Analog-Pin-Arduino-Tu/
import time
import board
import analogio
from collections import namedtuple
@todbot
todbot / kicad-diff-pcb.sh
Last active July 26, 2025 20:50
Git diff for Kicad PCB layouts
#!/bin/bash
#
# kicad-diff-pcb -- Git diff for Kicad PCB layouts
# 22 Jul 2025 - @todbot / Tod Kurt
#
# Install steps:
# 1. Make sure `kicad-cli` is in your PATH
# 2. Save this file somewhere in your PATH, I prefer "~/bin"
# 3. Make this script executable: "chmod +x kicad-diff-pcb"
# 4. Add the following to your ~/.gitconfig
@todbot
todbot / espnow_simple_hacky_receiver.py
Last active July 10, 2025 02:04
Simple demo of ESPnow broadcast function on CircuitPython
# espnow-simple_hacky_receiver.py -- show ESPnow working broadcast on CircuitPython
# 9 Jul 2025 - @todbot
# tested on QTPY ESP32-S2 and FunHouse (ESP32-S2)
import time
import wifi
import espnow
# https://github.com/adafruit/circuitpython/issues/9380#issuecomment-2463013607
# hack to switch channel that is used for ESPNow
# this takes just a few milliseconds, so doesn't waste a lot of power
@todbot
todbot / cirpy-showpins.py
Last active July 30, 2025 11:25
Find the defined board.* pins for a CircuitPython board, given a repo directory
#!/usr/bin/env python3
# Find all the defined pins for a CircuitPython board
# 5 Jul 2025 - @todbot / Tod Kurt
# e.g. "cirpy-showpins.py qtpy_m0 ~/projects/adafruit/circuitpython"
# Note: you need a checkout of the CircuitPython github repo for this tool to work
# e.g. "mkdir -f ~/projects/adafruit && cd ~/projects/adafruit && git checkout https://github.com/adafruit/circuitpython/"
import os, sys, re
if len(sys.argv) <= 1:
@todbot
todbot / code_audio_demo44k.py
Created May 19, 2025 19:38
CircuitPython Pico 2 RP2350 audio playback example at 44.1kHz 16-bit
import time
import board
import audiocore, audiobusio, audiomixer
SAMPLE_RATE = 44100
BUFFER_SIZE = 2048
CHANNEL_COUNT = 2
i2s_bck_pin = board.GP20
i2s_lck_pin = board.GP21
@todbot
todbot / pyplot_example.py
Created May 13, 2025 18:11
reminder to me about how to use pyplot and np.polyfit
import numpy as np
import matplotlib.pyplot as plt
# Original data points
x_vals = np.array([-0.5, -23.6, -58.3])
y_vals = np.array([1, 47, 110])
# Linear regression (best-fit line)
coeffs = np.polyfit(x_vals, y_vals, 1)
linear_fit = coeffs[0] * x_vals + coeffs[1]