Project Overview & Difficulty Rating
When makers search for fun things to do with a Raspberry Pi, they often land on basic media centers or ad-blockers. But if you want a project that combines physical computing, SPI communication, I2S digital audio, and PWM-driven lighting, building an RFID Retro Jukebox is the ultimate bench project. You will program physical RFID cards to trigger specific audio tracks, complete with a synchronized RGB LED light show and high-fidelity I2S audio output.
Target Board: Raspberry Pi 4 Model B (4GB RAM)
OS: Raspberry Pi OS (Bookworm, 64-bit, Lite or Desktop)
Difficulty: Intermediate (Requires SPI/I2S config and basic soldering)
Time to Build: 3–4 hours
Estimated Cost: $65–$85 (assuming you already own the Pi 4)
Hardware Spec Sheet & Pin Mapping
To ensure the code below compiles and runs without hardware conflicts, you must use the exact board variants and pin mappings listed here. The Raspberry Pi 4's GPIO header has specific hardware PWM and SPI channels; mixing these up will cause silent failures or kernel panics.
Parts List
- Compute: Raspberry Pi 4 Model B (4GB variant recommended for audio buffering)
- RFID Scanner: RC522 SPI RFID Module (13.56 MHz) with MIFARE 1K tags
- Lighting: WS2812B RGB LED Strip (5V, 16 LEDs minimum, 60 LEDs/m density)
- Audio DAC: MAX98357A I2S DAC Breakout Board (Adafruit 3006 or generic equivalent)
- Speaker: 3W 4-Ohm enclosed speaker
- Power: 5V 3A USB-C Power Supply (Official Raspberry Pi)
GPIO Pin Mapping Table
| Module | Module Pin | Pi 4 GPIO / Physical Pin | Function / Notes |
|---|---|---|---|
| RC522 | SDA (SS) | GPIO 8 (Pin 24) | SPI0 CE0 |
| RC522 | SCK | GPIO 11 (Pin 23) | SPI0 SCLK |
| RC522 | MOSI | GPIO 10 (Pin 19) | SPI0 MOSI |
| RC522 | MISO | GPIO 9 (Pin 21) | SPI0 MISO |
| RC522 | RST | GPIO 25 (Pin 22) | Reset (Active Low) |
| RC522 | 3.3V | 3.3V (Pin 1) | DO NOT use 5V |
| WS2812B | DIN | GPIO 12 (Pin 32) | Hardware PWM0 |
| WS2812B | 5V | 5V (Pin 2 or 4) | Draws ~1A at full white |
| MAX98357A | BCLK | GPIO 18 (Pin 12) | PCM_CLK (I2S) |
| MAX98357A | LRCLK | GPIO 19 (Pin 35) | PCM_FS (I2S) |
| MAX98357A | DIN | GPIO 21 (Pin 40) | PCM_DOUT (I2S) |
Step-by-Step Assembly & System Config
- Enable Interfaces: Boot your Pi 4, open a terminal, and run
sudo raspi-config. Navigate to Interface Options and enable SPI. Exit and reboot. - Configure I2S Audio: Open the boot config file:
sudo nano /boot/firmware/config.txt. Adddtparam=audio=offto disable the onboard PWM audio (which conflicts with WS2812B PWM), and adddtoverlay=hifiberry-dacordtoverlay=justboom-dacto map the I2S pins to the MAX98357A. Reboot. - Wire the RC522: Connect the SPI pins exactly as mapped above. Keep SPI wires under 10cm to prevent signal degradation at 10MHz.
- Wire the WS2812B: Connect DIN to GPIO 12. Warning: If using more than 16 LEDs, inject 5V power directly into the LED strip's middle and end points; do not pull >2A through the Pi's GPIO header.
- Install Libraries: Run
pip3 install mfrc522 rpi_ws281x pygamein a virtual environment, or globally withsudo pip3 install --break-system-packages mfrc522 rpi_ws281xon Bookworm.
The Python Control Code
This script initializes the RFID reader, maps specific card UIDs to local MP3 files, and triggers a synchronized WS2812B color wipe. It targets the Raspberry Pi 4 Model B and uses GPIO 12 for LEDs to avoid the I2S clock conflict on GPIO 18.
import time
import sys
import subprocess
import os
from mfrc522 import SimpleMFRC522
from rpi_ws281x import PixelStrip, Color
# --- PIN DEFINITIONS & CONFIG ---
LED_PIN = 12 # GPIO 12 (PWM0) - Avoids I2S conflict on GPIO 18
LED_COUNT = 16 # Number of WS2812B LEDs
LED_BRIGHTNESS = 128 # 0-255
AUDIO_DIR = '/home/pi/jukebox_tracks/'
# Map RFID Card IDs to Audio Files and LED Colors
TRACK_MAP = {
123456789012: {'file': 'track_01.mp3', 'color': Color(255, 0, 0)}, # Red
987654321098: {'file': 'track_02.mp3', 'color': Color(0, 255, 0)}, # Green
555555555555: {'file': 'track_03.mp3', 'color': Color(0, 0, 255)} # Blue
}
# Initialize LED Strip
strip = PixelStrip(LED_COUNT, LED_PIN, 800000, 10, False, LED_BRIGHTNESS, 0)
def color_wipe(target_color, wait_ms=50):
for i in range(strip.numPixels()):
strip.setPixelColor(i, target_color)
strip.show()
time.sleep(wait_ms / 1000.0)
def clear_leds():
color_wipe(Color(0, 0, 0), 10)
def main():
try:
strip.begin()
print('Jukebox initialized. Awaiting RFID scan...')
reader = SimpleMFRC522()
while True:
try:
id, text = reader.read()
print(f'Scanned ID: {id}')
if id in TRACK_MAP:
track_info = TRACK_MAP[id]
filepath = os.path.join(AUDIO_DIR, track_info['file'])
# Trigger LEDs
color_wipe(track_info['color'])
# Play Audio via mpg123 (non-blocking)
if os.path.exists(filepath):
subprocess.Popen(['mpg123', '-q', filepath])
time.sleep(10) # Play for 10 seconds
else:
print(f'Error: File not found: {filepath}')
clear_leds()
else:
print('Unknown card. Flashing white.')
color_wipe(Color(255, 255, 255))
time.sleep(1)
clear_leds()
time.sleep(2) # Debounce delay
except Exception as read_err:
print(f'Read error: {read_err}')
time.sleep(1)
except RuntimeError as init_err:
print(f'FATAL INIT ERROR: {init_err}')
sys.exit(1)
except KeyboardInterrupt:
print('Shutting down...')
clear_leds()
sys.exit(0)
if __name__ == '__main__':
main()
Debugging: Resolving the WS281x mmap Error
When working with PWM-driven addressable LEDs on the Pi 4, you will inevitably hit memory mapping restrictions. If your script crashes immediately upon calling strip.begin(), look for this exact error string:
Ranked Causes & Fixes:
- Missing Root Privileges (Most Likely): The
rpi_ws281xlibrary requires direct memory access to the Pi's DMA controller. You must run the script withsudo python3 jukebox.py. Standard users cannot map this memory. - PWM Audio Conflict: If
dtparam=audio=onis still active in/boot/firmware/config.txt, the onboard audio driver claims the PWM clock. The WS281x library will fail to initialize the DMA channel. Setdtparam=audio=offand reboot. - SPI/PWM Core Frequency Scaling: The Pi 4 dynamically scales its core clock, which ruins PWM timing. Add
core_freq=500andcore_freq_min=500to yourconfig.txtto lock the clock speed.
1. Run
ls /dev/spidev0.* to verify SPI is actually enabled in the kernel.2. Ensure you are executing the script via
sudo.3. Verify your WS2812B DIN wire is on GPIO 12 (PWM0) or GPIO 18 (PWM1), not a random GPIO pin which lacks hardware PWM.
Extending and Simplifying the Build
How to Simplify: If I2S audio and config.txt overlays are giving you grief, drop the MAX98357A DAC. Instead, use a standard USB Audio Adapter (like the Sabrent USB-SBCV). Change the Python code to use pygame.mixer instead of subprocess and mpg123. You lose some audiophile fidelity, but you eliminate all I2S kernel overlay conflicts, freeing up GPIO 18 and 19.
How to Extend: Turn this into a networked IoT device. Add an ESP32 as a secondary microcontroller to handle the WS2812B animations via Adafruit's NeoPixel protocols, communicating with the Pi over UART. This offloads the strict timing requirements of the LEDs from the Pi's Linux kernel, allowing you to run complex, non-blocking audio visualizations while the Pi focuses purely on streaming audio via MQTT or Spotify Connect.
FAQ: More Fun Things to Do with a Raspberry Pi
What are some fun things to do with a Raspberry Pi for beginners?
For beginners, the best projects avoid complex kernel overlays and soldering. Building a Pi-hole network-wide ad blocker or a RetroPie emulation console are the gold standards. Both require only flashing an SD card, plugging in Ethernet or a controller, and following a GUI setup. They teach you basic Linux navigation and network configuration without risking GPIO hardware damage.
What are fun things to do with a Raspberry Pi without a monitor?
Headless projects are incredibly rewarding. You can build a automated time-lapse camera rig using the Pi Camera Module V3 and a Python cron job, a Weather Underground personal weather station using an I2C BME280 sensor, or a headless FLAC music streamer using Volumio. All of these are managed via SSH or a web dashboard from your main PC or phone.
What are the most fun things to do with a Raspberry Pi 4?
The Pi 4's dual 4K micro-HDMI ports and USB 3.0 bus open up heavy-duty projects. The most fun, high-performance builds include a dedicated OpenMediaVault NAS utilizing USB 3.0 SSDs for fast network storage, a local AI object-detection security camera running TensorFlow Lite with a Coral USB Accelerator, or a flight simulator instrument panel where the Pi drives multiple physical stepper motors and gauges via USB serial for desktop simulators like MSFS 2020.






