Skip to content

cstaelen/oakhz-diy-pizero-speaker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

17 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽต OaKhz Audio - Complete DIY Bluetooth Speaker System

High-quality DIY Bluetooth speaker built with Raspberry Pi Zero 2W, HiFiBerry MiniAmp, and CamillaDSP equalizer with web interface, sound feedback, and physical rotary controls.

This educational project aims to build a prototype of a Bluetooth speaker that is detachable, reusable, and repairable, using open-source softwares, standards, and norms as much as possible.

GitHub Repository: https://github.com/cstaelen/oakhz-diy-pizero-speaker

-- Written with Claude AI


Final render Final render Inside Inside Inside

๐Ÿ“ฆ What's Included

This complete system includes three main components:

1. ๐Ÿ”Š Base System - Bluetooth Speaker (Required)

The core audio system with Bluetooth streaming and CamillaDSP parametric equalizer.

Features:

  • โœ… Bluetooth A2DP streaming (auto-pairing, no PIN)
  • โœ… 10-band parametric equalizer (CamillaDSP 48kHz)
  • โœ… Professional audio pipeline: Bluetooth โ†’ PulseAudio โ†’ Loopback โ†’ CamillaDSP โ†’ HiFiBerry DAC
  • โœ… ALSA loopback for flexible routing
  • โœ… Automatic device pairing (NoInputNoOutput)
  • โœ… Hostname: "OaKhz audio" (visible via Bluetooth)

๐Ÿ“– Read Full Installation Guide โ†’


2. ๐ŸŽ›๏ธ Web Equalizer Interface (Optional)

Web-based control panel for CamillaDSP equalizer with real-time adjustments.

Features:

  • ๐ŸŒ Web interface accessible from any device
  • ๐ŸŽš๏ธ 10-band parametric EQ with visual feedback
  • ๐Ÿ’พ Preset management (save/load custom configurations)
  • โšก Real-time updates via WebSocket
  • ๐Ÿ“Š Frequency response graph
  • ๐Ÿ“ฑ Mobile-responsive design (warm wood theme)
  • ๐ŸŽต Media player controls (Play/Pause/Next/Previous)
  • ๐Ÿ“ป Real-time metadata display (Artist, Title, Album, Status)

Access: http://[raspberry-pi-ip] or http://192.168.50.1 (AP mode)

๐Ÿ“– Read Full Documentation โ†’


3. ๐Ÿ”” Sound Feedback System (Optional)

Audible notifications for system events through PulseAudio.

Features:

  • ๐ŸŽต Ready sound (Bluetooth discoverable - C major arpeggio)
  • ๐ŸŽต Connection sound (device connects/reconnects - high chime)
  • ๐ŸŽต Shutdown sound (system powering off - descending arpeggio)
  • ๐Ÿ”Š All sounds at 80% volume via paplay (shutdown at 25%)
  • ๐ŸŽฏ Automatic PulseAudio routing through equalizer
  • ๐Ÿ”„ Single device mode (auto-disconnect old connections)

๐Ÿ“– Read Full Documentation โ†’


4. ๐ŸŽ›๏ธ Rotary Encoder Control (Optional)

Physical rotary encoder for tactile volume and media control.

Features:

  • ๐Ÿ”„ Rotate: Volume up/down (ยฑ3% per step)
  • ๐Ÿ”˜ Short press (<1s): Play/Pause (Bluetooth media control)
  • ๐Ÿ”˜ Medium press (1s): Skip track
  • โฑ๏ธ Long press (3s): System shutdown
  • ๐ŸŽฏ BlueZ MediaControl1 integration via D-Bus
  • ๐ŸŽต Smart play/pause toggle (checks current status)
  • ๐Ÿ”’ Thread-safe with 150ms throttling
  • ๐Ÿ‘ค Runs as user oakhz (gpio + audio groups)

GPIO Pins: CLK=23, DT=24, SW=22

๐Ÿ“– Read Full Documentation โ†’


5. ๐Ÿ“ก WiFi Access Point Fallback (Optional)

Automatic WiFi client/Access Point switching for equalizer access anywhere.

Features:

  • ๐ŸŒ Auto-connect to home WiFi when available
  • ๐Ÿ“ก Auto-switch to AP mode when no WiFi
  • ๐Ÿ”„ Smart monitoring and switching (every 30s)
  • ๐Ÿ”’ WPA2 secured Access Point
  • ๐ŸŽฏ Equalizer accessible in both modes
  • ๐Ÿ’ป SSH always available

Access: Home WiFi โ†’ http://[IP] | AP mode โ†’ http://192.168.50.1

๐Ÿ“– Read Full Documentation โ†’


๐Ÿš€ Quick Installation

Prerequisites

  • Raspberry Pi Zero 2W or Raspberry Pi 4
  • Raspberry Pi OS Lite 64-bit
  • HiFiBerry MiniAmp (or compatible DAC)
  • 2x 4ฮฉ 3W speakers
  • KY-040 rotary encoder (optional)

Installation Steps

# 1. Base System (Required)
sudo bash scripts/install.sh
sudo reboot

# 2. Web Equalizer Interface (Optional)
sudo bash scripts/setup-equalizer.sh

# 3. Sound Feedback (Optional)
sudo bash scripts/setup-sound.sh

# 4. Rotary Encoder (Optional)
sudo bash scripts/setup-rotary.sh

# 5. WiFi Access Point Fallback (Optional)
sudo bash scripts/setup-accesspoint.sh
sudo reboot

After Installation

  1. Connect Bluetooth: Look for "OaKhz audio" on your phone
  2. Access Web Interface (if equalizer installed): http://[Pi-IP]
  3. Use Rotary Control (if rotary installed): Turn for volume, press for play/pause/skip

๐Ÿ› ๏ธ Hardware Requirements

Essential Components

Component Model Price
Raspberry Pi Zero 2W ~โ‚ฌ20
SD Card 16GB+ Class 10 ~โ‚ฌ10
Audio DAC HiFiBerry MiniAmp ~โ‚ฌ25
Power Supply 5V 3A USB-C ~โ‚ฌ10
Speakers 2x 4ฮฉ 3W ~โ‚ฌ15
Total ~โ‚ฌ80

Optional Components

Component Model Price
Rotary Encoder KY-040 ~โ‚ฌ2
Enclosure 3D printed or custom Variable

๐Ÿ“Š System Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    User Interfaces                      โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  Web Browser     โ”‚  Bluetooth Device  โ”‚  Rotary Encoder โ”‚
โ”‚  (Equalizer)     โ”‚  (Audio Source)    โ”‚  (Volume/Skip)  โ”‚
โ”‚  Port 80         โ”‚                    โ”‚  GPIO 23/24/22  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚                   โ”‚                   โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                 Audio Processing Layer                   โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  Flask Server  โ”‚  PulseAudio    โ”‚  pactl (Volume)       โ”‚
โ”‚  (Python)      โ”‚  (System Mode) โ”‚  (Rotary Control)     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚               โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚              Sound Feedback & Routing                    โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  Audio Events  โ”‚  Bluetooth     โ”‚  Auto-routing         โ”‚
โ”‚  (paplay 65%/75%) โ”‚  Monitor    โ”‚  (switch-on-connect)  โ”‚
โ”‚  - Ready       โ”‚  - Connection  โ”‚                        โ”‚
โ”‚  - Shutdown    โ”‚  - Single dev  โ”‚                        โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚               โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                 ALSA Loopback Layer                      โ”‚
โ”‚  hw:Loopback,0 โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ†’ hw:Loopback,1                โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                         โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                  CamillaDSP (Equalizer)                  โ”‚
โ”‚  10-Band Parametric EQ @ 48kHz                           โ”‚
โ”‚  WebSocket: 1234                                         โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                         โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚              HiFiBerry MiniAmp (I2S DAC)                 โ”‚
โ”‚              hw:1,0 (Card 1)                             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                         โ”‚
                    โ”Œโ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚ Speakers โ”‚
                    โ”‚  ๐Ÿ”Š ๐Ÿ”Š   โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐ŸŽฏ Key Features

Audio Quality

  • 48kHz/16-bit audio pipeline
  • Professional DSP with CamillaDSP
  • Zero latency Bluetooth routing
  • HiFiBerry DAC for superior sound quality

User Experience

  • Auto-pairing Bluetooth (no PIN)
  • Web interface with media player controls (natural wood theme)
  • Real-time metadata display (Artist, Title, Album, Status)
  • Physical media controls with rotary encoder (Play/Pause/Next)
  • Audio feedback for system events
  • Real-time equalizer adjustments
  • Preamp master volume control

Technical Excellence

  • Thread-safe volume control with locking
  • Debounced controls (150ms throttling)
  • BlueZ D-Bus integration for media controls (MediaControl1 & MediaPlayer1)
  • Smart play/pause toggle (status-aware)
  • Single device mode (auto-disconnect old devices)
  • PulseAudio system mode for stability
  • Systemd services for automatic startup

๐Ÿ“ฑ Usage

Bluetooth Playback

  1. On your phone, look for "OaKhz audio" in Bluetooth settings
  2. Connect (no PIN required)
  3. Play music - audio routes automatically through equalizer

Web Interface

  1. Open http://[Raspberry-Pi-IP] or http://oakhz.local
  2. Now Playing section shows:
    • ๐ŸŽต Current track (Artist, Title, Album)
    • โฏ๏ธ Playback status (Playing/Paused/Stopped)
    • Auto-updates every 2 seconds
  3. Media Controls:
    • โฎ Previous track
    • โ–ถ๏ธ/โธ Play/Pause (smart toggle)
    • โญ Next track
  4. Equalizer:
    • 10-band parametric EQ (-12dB to +12dB per band)
    • Preamp master volume control (-12dB to +12dB)
    • 8 presets: Flat, Rock, Pop, Jazz, Classical, Bass, Treble, Vocal
    • Changes apply in real-time

Rotary Controls

  • Turn left/right: Volume ยฑ3%
  • Press briefly (<1s): Play/Pause Bluetooth media
  • Press medium (1s): Skip to next track
  • Hold 3 seconds: Shutdown system

๐Ÿ”ง Services Overview

Service Purpose Status Command
bluetooth.service Bluetooth stack sudo systemctl status bluetooth
bt-agent.service Auto-pairing sudo systemctl status bt-agent
pulseaudio.service System audio sudo systemctl status pulseaudio
camilladsp.service Equalizer sudo systemctl status camilladsp
oakhz-equalizer.service Web interface sudo systemctl status oakhz-equalizer
oakhz-audio-events.service Sound feedback sudo systemctl status oakhz-audio-events
oakhz-rotary.service Rotary control sudo systemctl status oakhz-rotary

๐Ÿ” Troubleshooting Quick Links

Common Issues

No Bluetooth connection? โ†’ See Base System Troubleshooting

No sound output? โ†’ See Base System - No Sound

Sound feedback not playing? โ†’ See Sound Feedback Troubleshooting

Rotary encoder not responding? โ†’ See Rotary Encoder Troubleshooting

Volume control not working? โ†’ See Rotary - Volume Not Changing

Web interface not accessible? โ†’ See Web Equalizer Troubleshooting


๐Ÿ“š Documentation Structure

OAKHZ_DOC/
โ”œโ”€โ”€ README.md                         # Project overview
โ”œโ”€โ”€ docs/                             # Documentation
โ”‚   โ”œโ”€โ”€ README-v2-install.md          # Base system installation guide
โ”‚   โ”œโ”€โ”€ README-v2-equalizer.md        # Web equalizer interface
โ”‚   โ”œโ”€โ”€ README-v2-sound.md            # Sound feedback system
โ”‚   โ”œโ”€โ”€ README-v2-rotary.md           # Rotary encoder control
โ”‚   โ””โ”€โ”€ README-v2-accesspoint.md      # WiFi Access Point fallback
โ”œโ”€โ”€ scripts/                          # Installation scripts
โ”‚   โ”œโ”€โ”€ install.sh                    # Base system installer
โ”‚   โ”œโ”€โ”€ setup-equalizer.sh            # Web equalizer installer
โ”‚   โ”œโ”€โ”€ setup-sound.sh                # Sound feedback installer
โ”‚   โ”œโ”€โ”€ setup-rotary.sh               # Rotary encoder installer
โ”‚   โ””โ”€โ”€ setup-accesspoint.sh          # WiFi AP installer
โ””โ”€โ”€ sounds/                           # Audio files

๐ŸŽจ Customization

Each component can be customized independently:

  • Base System: Change Bluetooth name, adjust CamillaDSP config
  • Web Equalizer: Customize web UI theme, add custom presets, change port
  • Sound Feedback: Replace WAV files, adjust volumes, change polling intervals
  • Rotary Encoder: Modify GPIO pins, adjust volume steps, change button timings

See individual documentation for detailed customization guides.


๐Ÿ“ฆ Component Dependencies

Base System (Required)
    โ†“
    โ”œโ”€โ”€ Web Equalizer (Optional) โ† Depends on CamillaDSP from base
    โ”œโ”€โ”€ Sound Feedback (Optional) โ† Depends on PulseAudio from base
    โ”œโ”€โ”€ Rotary Encoder (Optional) โ† Depends on PulseAudio from base
    โ””โ”€โ”€ WiFi AP Fallback (Optional) โ† Independent, works with all components

Installation order:

  1. Always install Base System first
  2. Add optional components in any order
  3. WiFi AP Fallback is completely independent

๐Ÿ”’ Security & Performance

  • User separation: Services run as appropriate users (oakhz, pulse, root)
  • Minimal permissions: Only required groups (gpio, audio)
  • Low resource usage: ~50MB RAM total for all services
  • No network exposure: Only local web interface (port 80)
  • Automatic updates: Use sudo apt update && sudo apt upgrade

๐Ÿ“ Changelog

v4.0 (October 2024) - Media Controls Update

  • โœจ Added Bluetooth media controls via BlueZ D-Bus (MediaControl1)
  • ๐ŸŽต Rotary button: Changed from Mute/Unmute to Play/Pause
  • ๐ŸŒ Web interface: Added Now Playing section with Artist/Title/Album display
  • ๐ŸŽฎ Web controls: Added Play/Pause, Next, Previous buttons
  • ๐Ÿ”Š Preamp fix: Master volume preamp now properly applied to CamillaDSP
  • ๐Ÿ”„ Smart toggle: Play/Pause checks current status before sending command
  • ๐Ÿ“ก Real-time updates: Metadata refreshes every 2 seconds

v3.0 (October 2024)

  • Initial release with 10-band equalizer, rotary controls, and web interface

๐Ÿ“œ License

GPL-3.0 License - Free to use, modify, and redistribute


๐Ÿ™ Credits

Software:

  • Raspberry Pi OS
  • BlueZ (Bluetooth + D-Bus media control)
  • PulseAudio (Audio routing)
  • CamillaDSP (Equalizer)
  • Flask (Web interface)
  • gpiozero (GPIO control)

Hardware:

  • HiFiBerry (Audio DAC)
  • Raspberry Pi Foundation

OaKhz Audio - v4.0 - October 2024

About

DIY Solar Bluetooth speaker experiment with a Pi Zero and Moode Audio

Resources

Stars

Watchers

Forks

Packages

No packages published