Tag Archives: NeoPixel Ring

AI on the Edge LESSON 54: Custom Hand Gesture Recognition and Dynamic NeoPixel Control

Welcome back, everyone! This is Paul McWhorter from TopTechBoy.com, and welcome to Lesson 54 in our AI on the Edge series.

In this lesson, we are taking our hand gesture recognition system to the next level by connecting it directly to real physical hardware! We’re going to take the normalized vector distance calculations and MediaPipe hand-tracking models we’ve been building over the past few lessons, and use them to drive a 12-LED NeoPixel Ring via SPI on the Raspberry Pi in real time.

If you’re following along in the series, pull up a chair, get yourself a nice hot cup of iced coffee, and let’s get right into it!

What We Are Building Today

In previous lessons, we learned how to extract 3D landmark coordinates from MediaPipe, scale them by the palm length to achieve scale-invariant gesture tracking, and store those relative Euclidean distances into a pickle database (gestureNEOPIXEL.pkl).

In Lesson 54, we map those live gesture detections directly to non-blocking LED animation patterns:

  1. Fist: Pulses a dynamic red “charge” sine wave.

  2. Open Palm: Drives the NeoPixel ring at full intensity white beacon.

  3. Peace Sign (✌️): Runs a dual-spinner pattern with opposing green and blue tracer LEDs over a low background red glow.

  4. Thumbs Up: Illumination of a solid, bright green “success” status.

  5. Point: Sweeps a fast green radar chaser dot across a red background array.

  6. Rock / Metal (🤘): Generates a smooth, sinusoidal cyan-to-green energy pulse.

  7. OK Sign: Cycles through a full spectrum RGB rainbow wheel.

  8. Unknown / Default: Gracefully turns off all LEDs.

Hardware Setup & Wiring (SPI Interface)

To ensure high frame rates without flickering, we drive our NeoPixels over the SPI bus using the neopixel_spi library.

Wiring Diagram Guide

  • NeoPixel VCC: Connect to 5V power supply (ensure adequate power if driving high brightness).

  • NeoPixel GND: Common ground with the Raspberry Pi GND pin.

  • NeoPixel DIN (Data In): Connect to GPIO 10 (SPI0 MOSI) on the Raspberry Pi pinout (Physical Pin 19).

Note: Ensure SPI is enabled in your Raspberry Pi system configuration (sudo raspi-config -> Interfaces -> SPI).

⌨️ Interactive Keyboard Controls

While running the main video processing loop, you can dynamically manage your trained gestures directly from your keyboard without interrupting the camera feed:

  • SPACE: Capture and train/overwrite the current gesture showing on screen.

  • T: Prompt the terminal to type in and add a brand-new gesture name on the fly.

  • D: Prompt the terminal to remove/delete an existing gesture from the active dataset.

  • Q: Cleanly turn off all NeoPixel LEDs, save the updated gesture data, and terminate the program.

Complete Python Source Code

Below is the complete, fully commented Python script for Lesson 54.

Homework Assignment

Your homework for this lesson is to modify the updateNeoPixels() function to add two new custom hand gestures of your own creation! Try implementing custom animations like a warm candle flicker or a pulsating dual-color pattern. Leave a link to your solution videos in the comments below!