Skip to content

sirbrasscat/Templates

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

Raspberry Pi Zero W Bluetooth Audio Receiver

Transform your Raspberry Pi Zero W with Pirate Audio HAT into a Bluetooth audio receiver for any stereo system.

Hardware Requirements

  • Raspberry Pi Zero W (original with BCM2835)
  • Pimoroni Pirate Audio HAT (any variant with headphone amp)
  • MicroSD card (8GB minimum)
  • Power supply (5V 2A recommended)
  • 3.5mm audio cable (to connect to your stereo)

Software Requirements

  • Raspberry Pi OS Lite (Legacy, 32-bit) - based on Debian Bullseye
  • SSH enabled
  • WiFi configured

Quick Start

1. Flash Raspberry Pi OS

Use Raspberry Pi Imager to flash the SD card:

  1. Choose Device: Raspberry Pi Zero
  2. Choose OS: Raspberry Pi OS (other) → Raspberry Pi OS Lite (Legacy, 32-bit)
  3. Choose Storage: Your SD card
  4. Configure Settings (click gear icon):
    • Set hostname: pi or bt-receiver
    • Enable SSH with password authentication
    • Set username: pi and password
    • Configure WiFi (SSID and password)
    • Set locale and timezone

2. Boot and Connect

  1. Insert SD card into Pi Zero W
  2. Power it on and wait ~60 seconds for first boot
  3. Connect via SSH:
    ssh pi@pi.local
    # or
    ssh pi@<IP_ADDRESS>

3. Run Setup Script

Copy the script to your Pi and run it:

# From your computer
scp setup-bt-receiver.sh pi@pi.local:~

# SSH into the Pi
ssh pi@pi.local

# Run the setup script
bash setup-bt-receiver.sh

The script will:

  • Update system packages
  • Install Pirate Audio HAT drivers
  • Install and configure Bluetooth and PulseAudio
  • Set up automatic Bluetooth discovery
  • Create systemd service for auto-start on boot
  • Configure the device as "BT-Audio-Receiver"

4. Reboot

After the script completes, reboot when prompted:

sudo reboot

Usage

Connecting Your Phone/Device

  1. Open Bluetooth settings on your phone
  2. Search for available devices
  3. Connect to "BT-Audio-Receiver" or "pi"
  4. Pair (no PIN required)
  5. Play audio - it will output through the Pirate Audio HAT

Important Notes

  • The Pi will remain discoverable at all times
  • Previously paired devices will automatically reconnect
  • Only one device can stream audio at a time
  • Audio quality: 44.1kHz/48kHz, 16-bit stereo

Troubleshooting

Pi Not Discoverable

Check if Bluetooth is powered and unblocked:

# Check rfkill status
sudo rfkill list

# Unblock if necessary
sudo rfkill unblock bluetooth

# Power on Bluetooth
bluetoothctl power on
bluetoothctl discoverable on
bluetoothctl pairable on

# Check status
bluetoothctl show

Should show:

  • Powered: yes
  • Discoverable: yes
  • Pairable: yes

No Audio Output

Check if Pirate Audio HAT is detected:

# List audio devices
aplay -l
cat /proc/asound/cards

# Should show "sndrpihifiberry" or similar, not just HDMI

If HAT not detected, verify /boot/firmware/config.txt:

sudo nano /boot/firmware/config.txt

Ensure these lines exist:

#dtparam=audio=on    # Must be commented out
dtoverlay=hifiberry-dac
gpio=25=op,dh

Then reboot:

sudo reboot

Audio Going to Wrong Output

Set the correct default audio device:

# Check current sinks
pactl list sinks short

# Set HiFiBerry as default
pactl set-default-sink <SINK_NUMBER_OR_NAME>

Or configure ALSA default:

sudo tee /etc/asound.conf > /dev/null <<EOF
pcm.!default {
    type hw
    card 0
}
ctl.!default {
    type hw
    card 0
}
EOF

Connection Issues

Monitor Bluetooth events in real-time:

bluetoothctl
# Watch for connection attempts and errors

Check service status:

# Bluetooth service
sudo systemctl status bluetooth

# Audio receiver service
sudo systemctl status bt-audio-receiver

# View recent logs
journalctl -u bt-audio-receiver -n 50

PulseAudio Not Running

# Check status
pulseaudio --check && echo "Running" || echo "Not running"

# Restart PulseAudio
pulseaudio --kill
pulseaudio --start

# Check for errors
journalctl --user -u pulseaudio -n 50

Useful Commands

Bluetooth Management

# Make discoverable again
bluetoothctl discoverable on

# List paired devices
bluetoothctl devices

# Remove a device
bluetoothctl remove <MAC_ADDRESS>

# Trust a device (auto-reconnect)
bluetoothctl trust <MAC_ADDRESS>

Service Management

# Check Bluetooth service
sudo systemctl status bluetooth

# Check receiver service
sudo systemctl status bt-audio-receiver

# Restart receiver service
sudo systemctl restart bt-audio-receiver

# View logs
journalctl -u bt-audio-receiver -f

Audio Testing

# Test audio output
speaker-test -c2 -t wav

# List audio devices
aplay -l

# Check PulseAudio sinks
pactl list sinks short

# Monitor audio routing
pactl list sinks

Configuration Files

Main Configuration Locations

  • Bluetooth config: /etc/bluetooth/main.conf
  • Boot config: /boot/firmware/config.txt
  • PulseAudio user config: ~/.config/pulse/client.conf and ~/.config/pulse/default.pa
  • PulseAudio system config: /etc/pulse/default.pa
  • Bluetooth service: /usr/local/bin/bt-speaker-init.sh
  • Systemd service: /etc/systemd/system/bt-audio-receiver.service

Modifying Device Name

Edit the init script:

sudo nano /usr/local/bin/bt-speaker-init.sh

Change this line:

hciconfig hci0 name "BT-Audio-Receiver"

Then restart:

sudo systemctl restart bt-audio-receiver

Changing Audio Quality

Edit PulseAudio config:

nano ~/.config/pulse/default.pa

Modify:

default-sample-format = s16le      # or s24le for 24-bit
default-sample-rate = 44100        # or 48000
alternate-sample-rate = 48000      # or 96000

Restart PulseAudio:

pulseaudio --kill
pulseaudio --start

Uninstallation

To remove the Bluetooth receiver setup:

# Stop and disable services
sudo systemctl stop bt-audio-receiver
sudo systemctl disable bt-audio-receiver

# Remove files
sudo rm /etc/systemd/system/bt-audio-receiver.service
sudo rm /usr/local/bin/bt-speaker-init.sh

# Reload systemd
sudo systemctl daemon-reload

# Optional: Remove packages
sudo apt-get remove --purge bluez pulseaudio pulseaudio-module-bluetooth

Performance Notes

The Raspberry Pi Zero W has limited resources:

  • Single-core 1GHz CPU
  • 512MB RAM
  • Bluetooth 4.1

Expected performance:

  • ✅ Streaming from phone/tablet
  • ✅ Standard audio quality (44.1kHz/48kHz)
  • ✅ Low latency for music playback
  • ⚠️ High-res audio may have dropouts
  • ⚠️ Multiple simultaneous connections not supported

Security Considerations

  • The device is always discoverable (no timeout)
  • Auto-pairing is enabled (no PIN required)
  • Consider setting DiscoverableTimeout in /etc/bluetooth/main.conf for better security
  • Add PIN pairing by changing the agent type in the init script

License

MIT License - Feel free to modify and distribute

Credits

  • Pimoroni for the Pirate Audio HAT
  • Raspberry Pi Foundation
  • BlueZ Bluetooth stack
  • PulseAudio project

Support

For issues or questions:

  1. Check the Troubleshooting section
  2. Review system logs: journalctl -xe
  3. Check Pimoroni support forums
  4. Verify hardware connections

Version History

  • v1.0 - Initial release with automatic setup script
    • Bluetooth audio receiver functionality
    • Pirate Audio HAT support
    • Auto-discovery and pairing
    • Systemd service for persistence

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages