Setting up an internet radio with a Raspberry Pi is a fun and practical project that transforms your Pi into a fully functional streaming device for playing online radio stations.
Here’s an in-depth tutorial to guide you through the process.
Requirements
- Raspberry Pi (any model, though Pi 3 or newer is recommended).
- MicroSD card (8GB or larger).
- Raspberry Pi OS (Lite or Desktop version).
- Audio output device:
- Headphones or speakers (via the 3.5mm jack, HDMI, or USB).
- USB Wi-Fi adapter or Ethernet cable (for internet connectivity).
- A basic LCD display (optional, for showing station info. We have a list of options later).
- Amplifier or DAC (optional, for enhanced sound quality. We have a list of recommendations later.).
Step 1: Prepare the Raspberry Pi
Install Raspberry Pi OS
- Download and install Raspberry Pi Imager.
- Flash Raspberry Pi OS (Lite or Desktop) onto the microSD card.
- Enable SSH:
- Create a file named ssh (no extension) in the boot partition of the microSD card.
- Insert the microSD card into the Raspberry Pi and power it on.
Access the Raspberry Pi
- Find the Pi’s IP address using your router’s admin panel or a network scanner.
- SSH into the Raspberry Pi:
ssh pi@<IP_ADDRESS>
Default username: pi, password: raspberry.
- Update and upgrade the system:
sudo apt update && sudo apt upgrade -y
Step 2: Install Audio Player Software
The most popular software for playing internet radio on a Raspberry Pi is MPD (Music Player Daemon) with an MPD client.
Install MPD and mpc
- Install the MPD server and MPC client:
sudo apt install mpd mpc -y
- Check if MPD is running:
systemctl status mpd
If it’s not running, start and enable it:
sudo systemctl start mpd sudo systemctl enable mpd
Step 3: Configure MPD
- Edit the MPD configuration file:
sudo nano /etc/mpd.conf
- Ensure the following sections are configured correctly:
- Audio Output: Use alsa for the default audio output.
audio_output { type "alsa" name "My ALSA Device" mixer_type "software" }
- Music Directory: Set the music directory (useful if you have local audio files):
music_directory "/var/lib/mpd/music"
- Audio Output: Use alsa for the default audio output.
- Save and exit the file.
- Restart MPD to apply changes:
sudo systemctl restart mpd
Step 4: Add Internet Radio Stations
Find Radio Station URLs
You can find station URLs from services like:
Look for .m3u or .pls files and extract the streaming URL (e.g., http://streaming-url).
Add Stations to MPD Playlist
- Create a playlist file:
nano ~/.mpd/playlists/radio.m3u
- Add station URLs:
http://stream1.example.com:8000/ http://stream2.example.com:8000/
- Save and exit the file.
- Update the MPD database:
mpc update
Play Radio Stations
- List available stations:
mpc lsplaylists
- Load the playlist and start playing:
mpc load radio mpc play
- Control playback:
- Next station: mpc next
- Previous station: mpc prev
- Stop playback: mpc stop
Step 5: Optional Enhancements
Add a Web Interface
Install Mopidy for a web-based control interface:
- Install Mopidy:
sudo apt install mopidy -y
- Add Mopidy configuration:
nano ~/.config/mopidy/mopidy.conf
Add the following:
[http] enabled = true hostname = 0.0.0.0 port = 6680
- Restart Mopidy:
mopidy
- Access the web interface:
- Open http://<Pi_IP>:6680 in a browser.
Connect to an LCD Display
- Install Python libraries for the LCD:
sudo apt install python3-rpi.gpio python3-smbus -y
- Use a Python script to display the current station name and status on the LCD.
Here’s a list of just some of the LCD options for Raspberry Pi:
- Waveshare 3.5″ Touchscreen IPS LCD Display: A popular and widely-used option, compatible with Raspberry Pi Pico and other models. (480×320 resolution)
- Waveshare 1.3″ OLED Display Module: A compact and low-power option, suitable for small projects. (64×128 resolution)
- DFRobot Metal Case with 3.5″ TFT Touchscreen: A comprehensive kit that includes a metal case and a 3.5″ touchscreen LCD, compatible with Raspberry Pi 4. (480×320 resolution)
- Waveshare 5″ DSI Capacitive Touch Display: A high-resolution option with a 5″ screen, compatible with Raspberry Pi. (800×480 resolution)
- Pimoroni HyperPixel 4.0 Square: A high-resolution, square-shaped display with a 4.0″ screen, compatible with Raspberry Pi. (752×752 resolution)
- Pimoroni HyperPixel 2.1 Round: A high-resolution, round-shaped display with a 2.1″ screen, compatible with Raspberry Pi. (320×240 resolution)
- Waveshare 12.3″ IPS Capacitive 10-Point Touch Display: A large and high-resolution option with a 12.3″ screen, compatible with Raspberry Pi. (1920×720 resolution)
- Waveshare 10.1″ IPS DVI Display Module: A high-resolution option with a 10.1″ screen, compatible with Raspberry Pi Pico. (1280×800 resolution)
- Waveshare 1.44″ LCD Display Module: A small and compact option with a 1.44″ screen, compatible with Raspberry Pi Pico. (128×128 resolution)
- Waveshare 2.13″ Red/Black/White E-Ink E-Paper Display Module: A unique, e-paper-based option with a 2.13″ screen, compatible with Raspberry Pi Pico. (212×104 resolution)
Enable Physical Buttons
- Attach physical buttons to GPIO pins for play, pause, next, and previous controls.
- Write a Python script to map GPIO inputs to MPD commands.
Add a USB DAC or Amplifier
For better audio quality, connect a USB DAC or amplifier to the Raspberry Pi.
here are some USB DACs compatible with Raspberry Pi:
- NanoSound USB DAC: A popular option with 24-bit/96kHz resolution, featuring a Savitech SA9023 USB decoder and a headphone amplifier.
- Hiface Two: An async USB transport with an XMOS receiver, compatible with Raspberry Pi and other Linux distros, supporting up to 24/192 PCM and DSD64.
- PecanPi DAC/Streamer: A single-package solution combining a Raspberry Pi and a DAC, available with Volumio (RaspyFi) pre-installed.
- Orchard Audio PecanPi DAC/Streamer: Similar to the above, but without a built-in power amp.
- Topping D10s/D10 Balanced: A high-end option with balanced outputs and a range of digital audio formats supported, including 24/384 PCM and DSD128.
Step 6: Test and Maintain
- Test Audio Output:
speaker-test -t sine -f 440 -c 2
- Debug Issues: Check MPD logs:
tail -f /var/log/mpd/mpd.log
- Auto-start MPD: Ensure MPD starts on boot:
sudo systemctl enable mpd
By following this tutorial, you’ve transformed your Raspberry Pi into an internet radio that streams online stations seamlessly.
With optional enhancements like a web interface, physical buttons, and a display, you can customize the setup to fit your preferences. Enjoy your personalized music streaming device!