Skip to content

Instantly share code, notes, and snippets.

@stonehippo
stonehippo / neopixels.py
Last active January 22, 2025 03:19
Messing with NeoPixels in Micropython
from machine import Pin
from neopixel import NeoPixel
import time
pixels = NeoPixel(Pin(0), 12, bpp=4)
WHITE = (0,0,0,255)
RED = (255,0,0,0)
GREEN = (0,255,0,0)
BLUE = (0,0,255,0)
import asyncio
import time
import board
import neopixel
from rainbowio import colorwheel
import adafruit_lsm303_accel
import adafruit_lis2mdl
@stonehippo
stonehippo / tt_data.md
Last active January 11, 2025 20:26
Downloading a bunch of videos from TikTok

Downloading a bunch of videos from TikTok on macOS

First, get homebrew if you don't already have it.

Then, in your terminal, get things set up:

cd ~/Downloads
mkdir tiktok_stuff
cd tiktok_stuff
@stonehippo
stonehippo / circuitpython_bluetooth_to_phone.md
Last active December 16, 2024 19:50
Setting up Bluetooth between a CircuitPython board and your phone or computer

Setting up CircuitPython to talk to devices via Bluetooth LE

If you have a CircuitPython development board that has Bluetooth LE (Bluetooth Low Energy, or BLE) compatibility, fairly easy to get it connected a phone or PC over a virtual UART (for simple, text-based communications.

Dependencies

In addition to a CircuitPython-compatible development board that supports Bluetooth LE, you'll need to have CircuitPython installed. The build of CP for your board needs to include the _bleio library; you can check to see if you're board is supported here.

You will most likely want to install a few support libraries for working with BLE (the first one is required, the second is optional but highly recommended). You can install these with circup or get them from the CircuitPython library bundle

@stonehippo
stonehippo / adafruit_circuitpython_blinka_macos_setup.md
Last active December 13, 2024 18:24
Installing Adafruit Circuitpython Blinka on a modern MacOS system

Installing Adafruit CircuitPython Blinka on a modern MacOS

Adafruit Blinka is a CircuitPython compatability layer for standard Python (CPython) on desktops, laptops, and single board computers. Installing Blinka is a great way to access the hardware drivers and other helpers available in CircuitPython. For example, CP has a very nice interface to Bluetooth LE that can make setting up your laptop as a central device much easier!

See Adafruit's installation guide for more details on setting up Blinka. You might also want to tale a look at the guides below for methods for setting up Blinka with computers for hardware hacking:

Installing Blinka and all of its dependencies

@stonehippo
stonehippo / cp_lsm6dsv16x_notes.md
Created November 17, 2024 21:19
Notes on writing a CircuitPython driver for the LSM6DSV16X IMU.

LSM6DSV16X CircuitPython Driver

Notes on writing a CircuitPython driver for the LSM6DSV16X IMU.

First steps

For starts, I went to the Adafruit CircuitPython driver for LSM6DS-class chips. It covers several models with similar setups, so it seemed liked a good place to start.

Once I figured out that the Sparkfun dev board that I'm using was set up for the alternate I2C address (0x6b instead of 0x6a) and that I needed to use the chip ID specific to the LSM6DSV16X (0x70), I was able to connect with the LSM6DS library, using a new implemenation file (which really only setup the new CHIP_ID):

@stonehippo
stonehippo / micropython_tools.md
Created August 27, 2024 16:39
Tools for working withMicropython

ESP8266 and Micropython Tools

I use Micropython sometimes. It's a great port of Python to microcontrollers, and the basis of CircuitPython. Unlike CircuitPython, MicroPython doesn't typically provide a mounted drive via native USB, which means that you need some tooling to best interact with the board. For example, I am using MP on some ESP8266 dev boards, because CP support there isn't great (no UF2 bootloader, no native USB).

  • esptool.py - Needed for flashing the board
  • mpremote - a handy toolkit for working with MP boards, including console access, package management, and file management
  • ampy - a handy tool for copying files to and from a MicroPython board. This is somewhat redundant if you use mpremote
@stonehippo
stonehippo / display.py
Created August 14, 2024 14:10
Code from my little CircuitPython display
import board
import time
import adafruit_bme680
import adafruit_veml7700
import neopixel
from adafruit_led_animation.animation.rainbow import Rainbow
from adafruit_led_animation.color import RED
from ulab import numpy as np
i2c = board.I2C()
@stonehippo
stonehippo / using_circuitpython_native_used_for_serial_data.md
Last active September 1, 2024 23:41
A note to self about using the CircuitPython native USB for serial data with usb_cdc

Using the CircuitPython native USB for serial data

I was trying to get some CP code to talk to Processing over a serial port interface. Of course, the CP REPL is normally available on whatever serial port the board mounts by default. This is a little complicated, because although you can use something like print from the REPL (or code.py) to print a value to the console, sys.stdin and sys.stdout are text-based streams, which may not be what you want. And you'll get REPL noise to boot. Not ideal.

This is where usb_cdc comes in. It's a handy library for managing the USB CDC (serial) on most CircuitPython boards. First, usb_cdc can be used to control how many serial ports CP will provide at startup. You can modify boot.py to make this work:

import usb_cdc

usb_cdc.enable(console=True, data=False)
@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 <[email protected]>
Written for the Adafruit Metro M0, but will work with any board with
4 PWM-capable pins.
"""
import board
from pwmio import PWMOut