Skip to content

Instantly share code, notes, and snippets.

View vitorio's full-sized avatar

Vitorio Miliano vitorio

View GitHub Profile
@vitorio
vitorio / boot.py
Last active March 17, 2024 22:53
Force a kiosk into BIOS to boot from a USB drive + offer ⊞ key after boot, Adafruit Neo Trinkey, CircuitPython 8.x
import board
import touchio
import storage
import usb_cdc
import usb_midi
import usb_hid
# Neo Trinkey
touch1 = touchio.TouchIn(board.TOUCH1)
touch2 = touchio.TouchIn(board.TOUCH2)
@vitorio
vitorio / font2x5fixedmononum.py
Last active January 15, 2024 01:30
CO2 monitor using Pimoroni Breakout Garden + 5x5 RGB Matrix + SCD41 breakouts, MicroPython 1.21
# Quick script to convert Adafruit GFX font into binary file.
# Author: Tony DiCola
# License: MIT (https://opensource.org/licenses/MIT)
# Taken from glcdfont.c from Adafruit GFX Arduino library.
FONT = bytes((
0x00, 0x00,
0x00, 0x00,
0x00, 0x00,
0x00, 0x00,
0x00, 0x00,
@vitorio
vitorio / main.py
Created January 15, 2024 01:18
CO2 monitor using Pimoroni Breakout Garden + 1.12" Mono OLED SPI + SCD41 breakouts, MicroPython 1.21
from pimoroni import BREAKOUT_GARDEN_I2C_PINS
from pimoroni_i2c import PimoroniI2C
import breakout_scd41
from machine import Pin, SPI
import sh1107 # https://github.com/peter-l5/SH1107
import random
MESSAGE = '0000'
co2 = 0
@vitorio
vitorio / main.py
Last active December 1, 2023 02:29
CO2 monitor using Adafruit Trinkey QT2040 + SCD-40 + ST25DV16K, CircuitPython 8.x
# SPDX-FileCopyrightText: 2021 Carter Nelson for Adafruit Industries
# SPDX-License-Identifier: MIT
import time
import board
import adafruit_scd4x
import neopixel
import adafruit_24lc32
## https://github.com/Neradoc/circuitpython-st25dv
@vitorio
vitorio / main.py
Last active July 21, 2023 02:42
CO2 monitor using Pimoroni Wireless Plasma Kit + Adafruit SCD40, MicroPython 1.20.3
# https://github.com/pimoroni/pimoroni-pico/blob/main/micropython/examples/plasma_stick/co2.py
# https://docs.micropython.org/en/latest/library/rp2.html#rp2.bootsel_button
# https://github.com/pimoroni/phew/blob/v0.0.3/phew/__init__.py
import time
import plasma
from plasma import plasma_stick
from machine import Pin
import breakout_scd41 as scd
from pimoroni_i2c import PimoroniI2C
@vitorio
vitorio / boot.py
Last active July 20, 2023 03:20
Force a kiosk into BIOS to boot from a USB drive, Adafruit Trinkey QT2040, CircuitPython 8.x
import board
import digitalio
import storage
import usb_cdc
import usb_midi
import usb_hid
# QT2040 Trinkey
button = digitalio.DigitalInOut(board.BUTTON)
button.switch_to_input(digitalio.Pull.UP)
@vitorio
vitorio / main.py
Last active July 20, 2023 03:19
CO2 monitor using Pimoroni Tufty 2040 + Adafruit SCD-40, MicroPython 1.20.3
# https://github.com/pimoroni/pimoroni-pico/blob/main/micropython/examples/tufty2040/main.py
# https://github.com/pimoroni/pimoroni-pico/blob/main/micropython/examples/tufty2040/pride_badge.py
# https://github.com/pimoroni/pimoroni-pico/blob/main/micropython/examples/breakout_scd41/scd41_demo.py
from picographics import PicoGraphics, DISPLAY_TUFTY_2040, PEN_RGB332
import time, math, random, gc
from pimoroni import Button, BREAKOUT_GARDEN_I2C_PINS
import breakout_scd41
from pimoroni_i2c import PimoroniI2C
@vitorio
vitorio / bongos.py
Last active January 20, 2023 04:16
Stadia gamepad + Bongos as synthetic/composite/hybrid Switch Pro controller for Taiko no Tatsujin
# sudo apt install python3-pip pkg-config libdbus-1-dev libglib2.0-dev
# sudo pip3 install nxbt
# sudo pip3 install jinja2==3.0.3 itsdangerous==2.0.1 Werkzeug==2.0.2 eventlet==0.33.0 dnspython==2.2.1
import pyjoystick.sdl2
import nxbt
import gpiozero
import sys
button3 = gpiozero.Button(24, pull_up=False)
@vitorio
vitorio / osx-rpiboot-homedir.md
Last active January 4, 2023 19:10
Compiling libusb and rpiboot natively on OS X within your home directory

NOTE: rpiboot doesn't actually work on recent OS X versions and/or Macs due to a bug in the RPi0/RPi1 chipset: https://www.raspberrypi.org/forums/viewtopic.php?f=98&t=90825

These instructions compile a native OS X version of rpiboot that lives in your home directory, and which cannot be moved around, but should always be discoverable by applications.

Assumes OS X with Xcode or Xcode command-line tools, not macports or homebrew

To install Xcode command-line tools in recent versions of OS X, open Terminal, type xcode-select --install and click "Install"

Older versions of OS X may need to manually download disk images of older versions of Xcode and/or the Xcode command-line tools, as various certificates may have expired (e.g. 10.7.4 requires a manual install from the Xcode 4.6.2 command-line tools image)

@vitorio
vitorio / mbox-unique-email-addresses.py
Created March 30, 2015 01:17
So, let's say you have an mbox full of mail and you want to get all the To: addresses out of it. And let's say you've seen a bunch of intimidating complicated examples like http://stackoverflow.com/questions/7166922/extracting-the-body-of-an-email-from-mbox-file-decoding-it-to-plain-text-regard or http://nbviewer.ipython.org/github/furukama/Mini…
# via http://stackoverflow.com/questions/14903664/determine-unique-from-email-addresses-in-maildir-folder
import mailbox
import email
mbox = mailbox.mbox('DADEOL/AOL Mail sorted/Saved.DADEOL Sent.mbox')
uniq_emails = set(email.utils.parseaddr(msg['to'])[1].lower() for msg in mbox)
for a in uniq_emails: