A simple application to run on a Raspberry Pi to control a turntable based radio station.
README.md

Turntable Radio #

Automated vinyl streaming system for Raspberry Pi that monitors turntable operation and automatically manages streaming, audio recognition, and metadata updates.

Features #

  • 🎵 Turntable Detection: Hall effect sensor detects when turntable is spinning
  • 🎙️ Audio Recognition: Automatically identifies playing tracks using AudD API
  • 📻 Stream Management: Starts/stops Darkice streaming automatically
  • 🏷️ Metadata Updates: Updates Icecast2 stream metadata with recognized tracks
  • 🌐 Remote GPIO: Debug and control GPIO pins on remote Raspberry Pi over network
  • ⚙️ Systemd Service: Runs as a background service on boot

Hardware Requirements #

  • Raspberry Pi (any model with GPIO pins)
  • Hall Effect Magnetic Sensor (e.g., A3144, KY-003)
  • Small neodymium magnet
  • Audio input device compatible with Darkice

Wiring:

Hall Sensor -> Raspberry Pi
VCC         -> 3.3V (Pin 1 or 17)
GND         -> Ground (Pin 6, 9, 14, 20, 25, etc.)
OUT/DATA    -> GPIO 17 (Pin 11) or your chosen GPIO pin

Attach the magnet to the edge of your turntable platter so it passes by the Hall sensor with each rotation.

Quick Start #

1. Install #

git clone <repository-url> turntable-radio
cd turntable-radio
sudo ./install.sh

2. Configure #

sudo nano /opt/turntable-radio/.env

Required settings:

AUDD_API_TOKEN=your_token_here          # Get from https://dashboard.audd.io/
ICECAST_HOST=localhost
ICECAST_PORT=8000
ICECAST_MOUNT=/stream
ICECAST_ADMIN_PASSWORD=your_password
TURNTABLE_HE_GPIO_PIN=17                # GPIO pin for Hall sensor

3. Start #

sudo systemctl start turntable-radio
sudo systemctl status turntable-radio

4. Test #

Watch the logs while spinning your turntable:

sudo journalctl -u turntable-radio -f

How It Works #

  1. Detection: Hall effect sensor detects magnet passing on turntable platter
  2. Stream Start: Darkice streaming service is started after turntable rotation detection
  3. Recognition: System samples audio and identifies album using AudD API
  4. Metadata: Track information updates Icecast2 stream metadata
  5. Stream Stop: When turntable stops, Darkice stops after timeout period
  6. Repeat: Cycle continues automatically

Service Management #

# Control service
sudo systemctl start turntable-radio
sudo systemctl stop turntable-radio
sudo systemctl restart turntable-radio
sudo systemctl status turntable-radio

# View logs
sudo journalctl -u turntable-radio -f

# Enable/disable on boot
sudo systemctl enable turntable-radio
sudo systemctl disable turntable-radio

# Or use Makefile shortcuts
make start
make stop
make logs
make status

Configuration Options #

Edit /opt/turntable-radio/.env:

# Required
AUDD_API_TOKEN=your_token_here
ICECAST_HOST=localhost
ICECAST_PORT=8000
ICECAST_MOUNT=/stream
ICECAST_ADMIN_USER=admin
ICECAST_ADMIN_PASSWORD=your_password

# Optional
SAMPLE_DURATION=10                    # Audio sample duration (seconds)
TURNTABLE_HE_GPIO_PIN=17             # GPIO pin for Hall sensor
TURNTABLE_HE_TIMEOUT=3.0             # Timeout before considering stopped
TURNTABLE_HE_PULL_UP=true            # Enable internal pull-up resistor
TURNTABLE_HE_BOUNCE_TIME=0.01        # Debounce time
TURNTABLE_HE_ENABLE_LOGGING=true     # Enable state logging

# Remote GPIO (for debugging)
# PIGPIO_ADDR=192.168.1.100
# PIGPIO_PORT=8888

Troubleshooting #

Service won't start:

sudo ./check-system.sh               # Check installation
sudo journalctl -u turntable-radio -n 50  # View errors

Hall sensor not detecting:

  • Check wiring connections
  • Verify GPIO pin number in .env
  • Test with: .venv/bin/python examples/example_turntable_detector.py
  • Ensure magnet passes close enough to sensor

Audio recognition fails:

  • Verify AUDD_API_TOKEN is valid
  • Check Icecast stream is accessible
  • Ensure stream URL is correct

Metadata not updating:

  • Verify Icecast admin credentials
  • Check mount point is active
  • Test: curl http://admin:password@localhost:8000/admin/metadata?mount=/stream&mode=updinfo&song=test

Development #

Project structure:

turntable-radio/
├── main.py                    # Main application
├── turntable_detector.py      # Turntable detection
├── audio_recognition.py       # Audio recognition
├── icecast_metadata.py        # Metadata updates
├── stream_metadata_sync.py    # Stream sync
├── gpio_config.py             # GPIO configuration
└── examples/                  # Example scripts

Remote GPIO debugging:

On remote Pi:

sudo pigpiod

In your .env:

PIGPIO_ADDR=192.168.1.100
PIGPIO_PORT=8888

Test:

python examples/example_remote_gpio.py

Uninstall #

sudo ./uninstall.sh

Resources #