Skip to content

Instantly share code, notes, and snippets.

View RobCranfill's full-sized avatar

Rob Cranfill RobCranfill

View GitHub Profile
@RobCranfill
RobCranfill / test_pcm5102.py
Last active July 26, 2023 01:09
Output stereo audio via a RPi Pico and a PCM5102 board
# Test outputting stereo audio via a PCM5102 board
# cran, based on:
# SPDX-FileCopyrightText: 2018 Kattni Rembor for Adafruit Industries
# SPDX-License-Identifier: MIT
import board
import audiocore, audiobusio, audiomixer, synthio
# Pico
@RobCranfill
RobCranfill / .bashrc
Created July 7, 2023 05:28
A bash function to mount a CircuitPython device to a WSL mount
# put this in .bashrc - or .bash_aliases?
function mountcirc() {
# mount drive $1 to /mnt/CIRCUITPY
sudo mount -t drvfs $1 /mnt/CIRCUITPY/
echo "Mounted $1 to /mnt/CIRCUITPY"
ls -l /mnt/CIRCUITPY
}
@RobCranfill
RobCranfill / runcode.py
Created February 25, 2023 00:36
Run code on a micropython device.
# to see the name of the file(s) on the device:
import os
os.listdir()
# to run the code
# (ok actually you would do this in a separate step)
exec(open('code.py').read())
@RobCranfill
RobCranfill / repo.sh
Created January 6, 2023 17:35
Back up and document work from a circuitpython thumb drive
#!/bin/bash
# copy work files from thumbdrive to a folder here
# params: {new folder name}
NEWFOLDER="$1"
mkdir "$NEWFOLDER"
cp /mnt/f/*py "$NEWFOLDER"
ls -Al /mnt/f/lib >>"$NEWFOLDER"/liblist.text
tree /mnt/f/ >>"$NEWFOLDER"/dirtree.text
// Adapted from https://github.com/ambotaku/pico-getLine
// Trivial code change to allow compiling with plain C on Pico.
//
const uint startLineLength = 8; // the linebuffer will automatically grow for longer lines
const char eof = 255; // EOF in stdio.h -is -1, but getchar returns int 255 to avoid blocking
/*
* read a line of any length from stdio (grows)
*
* @param fullDuplex input will echo on entry (terminal mode) when false
* @param linebreak "\r" may be needed for terminals
@RobCranfill
RobCranfill / display-8x8.py
Created November 25, 2022 20:42
Display a scrolling message on an Adafruit 8x8 LED matrix. For the Adafruit RP2040 Feather board (or any CircuitPython board?).
# Display a scrolling message on an Adafruit 8x8 LED matrix.
# For the Adafruit RP2040 Feather board (or any CircuitPython board?).
#
import board
from adafruit_ht16k33.matrix import Matrix8x8
import time
import font # This is my data for a simple 8x8 font, found in this directory.
# For the given string, create the big list of bit values (columns), left to right.
# TODO: This might display faster if we didn't pack these bits, but just
@RobCranfill
RobCranfill / extract.py
Created November 18, 2022 04:08
Extract headers from online email and create a CSV file to import all found email addresses as contacts into GMail.
import imaplib
import email
import csv
import sys
"""
Extract headers from online email and create a CSV file
to import all found email addresses as contacts into GMail.
(c)2022 [email protected]
based on https://qr.ae/pvQWFi
#!/bin/bash
# compare the boot files on the RPi's SSD with the files on the SD card
sudo mount -r /dev/mmcblk0p1 /mnt/sdboot 2>/dev/null
# SSD BOOT FILES
FILE1="/boot/bcm2710-rpi-3-b.dtb"
# SD CARD BOOT FILES
FILE2="/mnt/sdboot/bcm2710-rpi-3-b.dtb"
#!/bin/bash
# check the weather station's battery by screen-scraping the WeeWX main page
# and send a status email
WX_URL="http://pi4.local/weather"
MAIL="/home/rob/.local/bin/cransend.sh"
EMAIL_TO="[email protected]"
TEMP_FILE="/tmp/checkWxBatt.html"
@RobCranfill
RobCranfill / showTime.html
Created December 27, 2020 01:34
Simple HTML page showing use of setInterval and mucking with the DOM.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="30">
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<link href='https://fonts.googleapis.com/css?family=Stylish' rel='stylesheet'>