Monday, June 02, 2025

xNT Hand Implant to Webhook to Home Assistant Event Trigger



 https://www.instagram.com/p/DKZQHQBi4Eq/ 


#include <WiFi.h>
#include <HTTPClient.h>
#include <SPI.h>
#include <MFRC522.h>

// === Wi-Fi credentials ===
const char* ssid = "SSID";
const char* password = "password";

// === Home Assistant Webhook endpoint ===
const char* webhook_url = "http://HA_IP_ADDRESS:8123/api/webhook/rfid_trigger";

// === SPI Pin Assignments for Xiao ===
#define RST_PIN 3
#define SS_PIN 7

MFRC522 mfrc522(SS_PIN, RST_PIN);

// === Setup ===
void setup() {
Serial.begin(115200);
while (!Serial);

Serial.println("Connecting to Wi-Fi...");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nWi-Fi connected.");

Serial.println("Initializing RFID...");
SPI.begin(8, 9, 10); // SCK, MISO, MOSI
mfrc522.PCD_Init();
Serial.println("Ready to scan tags.");
}

// === Send UID to Home Assistant via Webhook ===
void sendWebhook(String uid) {
if (WiFi.status() != WL_CONNECTED) return;

HTTPClient http;
http.begin(webhook_url);
http.addHeader("Content-Type", "application/json");

String payload = "{\"uid\": \"" + uid + "\"}";
int code = http.POST(payload);
Serial.print("Sent UID: "); Serial.print(uid);
Serial.print(" | HTTP Response: "); Serial.println(code);
http.end();
}

// === Main loop ===
void loop() {
if (!mfrc522.PICC_IsNewCardPresent() || !mfrc522.PICC_ReadCardSerial()) return;

String uid = "";
for (byte i = 0; i < mfrc522.uid.size; i++) {
if (mfrc522.uid.uidByte[i] < 0x10) uid += "0";
uid += String(mfrc522.uid.uidByte[i], HEX);
}
uid.toUpperCase();

Serial.println("Scanned UID: " + uid);
sendWebhook(uid);

delay(2000); // debounce
mfrc522.PICC_HaltA();
}

Sunday, June 01, 2025

Teensy Basics: Distance Sensing with VL53L0X Laser Sensor

Overview

The VL53L0X is a ranging sensor that uses time-of-flight of a laser to determine the distance to the next surface correct to the mm with a maximum of 2m. The sensor uses an i2c interface with a default address of 0x29. The xshut pin allows for address control and start up / shut down during setup. 


Hardware Setup

Here are the pinouts for the Teensy 4.1 and the VL53L0X: 



Make the following connections between the Teensy 4.1 and the sensor: 

  • Teensy GND to VL53L0X GND
  • Teensy 3v3 to VL53L0X VIN
  • Teensy pin 0 to VL53L0X XSHUT
  • VL53L0X unconnected
  • Teensy pin 18 to VL53L0X SDA
  • Teensy pin 19 to VL53L0X SCL

No other passive components are required. 





Software setup

This sensor example requires the Pololu vl53l0x library, which is available from the Arduino library manager. 


Example: Reading distance and printing to the serial monitor

#include <Wire.h>
#include <VL53L0X.h>

VL53L0X sensor;

// XSHUT pin for VL53L0X
const int XSHUT_PIN = 0;

void setup() {
Serial.begin(115200);
Wire.begin(); // SDA = 18, SCL = 19 on Teensy 4.1
delay(100);

// Initialize XSHUT pin
pinMode(XSHUT_PIN, OUTPUT);
digitalWrite(XSHUT_PIN, LOW); // Reset sensor
delay(10);
digitalWrite(XSHUT_PIN, HIGH); // Power up sensor
delay(10);

// Initialize VL53L0X
sensor.setTimeout(500);
if (!sensor.init()) {
Serial.println("Failed to detect VL53L0X.");
while (1);
}

sensor.startContinuous();
Serial.println("VL53L0X started.");
}

void loop() {
uint16_t distance = sensor.readRangeContinuousMillimeters();

Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" mm");

if (sensor.timeoutOccurred()) {
Serial.println("TIMEOUT");
}

delay(20);
}

Saturday, April 26, 2025

Max Gen Filter Cookbook


256 tap manual finite response filter

https://github.com/little-scale/littlescale-max-patches/blob/master/manual_fir_filter.maxpat 


Morphing-type biquad filter

https://github.com/little-scale/littlescale-max-patches/blob/master/biquad_testing.maxpat 

https://github.com/little-scale/littlescale-max-patches/blob/master/biquad-full-basic.gendsp



12 stage biquad lowpass with outputs at 12, 48, 96 and 144 db per octave

https://github.com/little-scale/littlescale-max-patches/blob/master/duodecim-biquad.maxpat

https://github.com/little-scale/littlescale-max-patches/blob/master/duodecim-biquad.gendsp


50 stage single pole lowpass

https://github.com/little-scale/littlescale-max-patches/blob/master/singlepole-cascading.maxpat

https://github.com/little-scale/littlescale-max-patches/blob/master/singlepole.gendsp

https://github.com/little-scale/littlescale-max-patches/blob/master/singlepole.maxpat


Basic biquad implementation of lpf, hpf, bpf, notch, all, shelves in one gen~ patch

https://github.com/little-scale/littlescale-max-patches/blob/master/biquad-full-basic.maxpat

https://github.com/little-scale/littlescale-max-patches/blob/master/biquad-full-basic.gendsp


Moog-style ladder filter with resonance and saturation

https://github.com/little-scale/littlescale-max-patches/blob/master/ladder-filter.maxpat

https://github.com/little-scale/littlescale-max-patches/blob/master/ladder-filter.gendsp


Harmonic resonant bandpass bank with 16 partials and controls for central partial and gain spread.

https://github.com/little-scale/littlescale-max-patches/blob/master/reson-bpf-harmonic-bank.maxpat

https://github.com/little-scale/littlescale-max-patches/blob/master/reson-bpf-harmonic-bank.gendsp


Resonant bandpass filter

https://github.com/little-scale/littlescale-max-patches/blob/master/reson-bpf.maxpat

https://github.com/little-scale/littlescale-max-patches/blob/master/reson-bpf.gendsp




Third order (3ff / 3fb) filter with LFO modulation across all co-efficients

https://github.com/little-scale/littlescale-max-patches/blob/master/filter-3ff-3fb.maxpat



Friday, October 04, 2024

Building Supercollider for Raspberry Pi Zero 2

 


Sunday, March 10, 2024

Pyramid Controller

 

My pyramid controller is almost identical to my sphere controller. The difference in shape means that each side feels a little like a preset, and its easier to have an intuition about rotation and orientation compared to a sphere. The code is slightly different as it doesn't adjust brightness; this looks better in my opinion. The code and model files can be found here: https://github.com/little-scale/Music-Sphere-Controller alongside a Max patch that makes it easy to get the data from the pyramid. The board will transmit x y and z data streams for acceleration, gyroscope and magnetometer. The acceleration values determine the colour of the onboard LED. Printing in white or clear PLA makes the colour shine through nicely.