Home » Setting up an internet radio with a Raspberry Pi

Setting up an internet radio with a Raspberry Pi

by shedboy71

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

  1. Raspberry Pi (any model, though Pi 3 or newer is recommended).
  2. MicroSD card (8GB or larger).
  3. Raspberry Pi OS (Lite or Desktop version).
  4. Audio output device:
    • Headphones or speakers (via the 3.5mm jack, HDMI, or USB).
  5. USB Wi-Fi adapter or Ethernet cable (for internet connectivity).
  6. A basic LCD display (optional, for showing station info. We have a list of options later).
  7. 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

  1. Download and install Raspberry Pi Imager.
  2. Flash Raspberry Pi OS (Lite or Desktop) onto the microSD card.
  3. Enable SSH:
    • Create a file named ssh (no extension) in the boot partition of the microSD card.
  4. Insert the microSD card into the Raspberry Pi and power it on.

Access the Raspberry Pi

  1. Find the Pi’s IP address using your router’s admin panel or a network scanner.
  2. SSH into the Raspberry Pi:
    ssh pi@<IP_ADDRESS>
    

    Default username: pi, password: raspberry.

  3. 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

  1. Install the MPD server and MPC client:
    sudo apt install mpd mpc -y
    
  2. 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

  1. Edit the MPD configuration file:
    sudo nano /etc/mpd.conf
    
  2. 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"
      
  3. Save and exit the file.
  4. 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

  1. Create a playlist file:
    nano ~/.mpd/playlists/radio.m3u
    
  2. Add station URLs:
    http://stream1.example.com:8000/
    http://stream2.example.com:8000/
    
  3. Save and exit the file.
  4. Update the MPD database:
    mpc update
    

Play Radio Stations

  1. List available stations:
    mpc lsplaylists
    
  2. Load the playlist and start playing:
    mpc load radio
    mpc play
    
  3. 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:

  1. Install Mopidy:
    sudo apt install mopidy -y
    
  2. Add Mopidy configuration:
    nano ~/.config/mopidy/mopidy.conf
    

    Add the following:

    [http]
    enabled = true
    hostname = 0.0.0.0
    port = 6680
    
  3. Restart Mopidy:
    mopidy
    
  4. Access the web interface:
    • Open http://<Pi_IP>:6680 in a browser.

Connect to an LCD Display

  1. Install Python libraries for the LCD:
    sudo apt install python3-rpi.gpio python3-smbus -y
    
  2. 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:

  1. Waveshare 3.5″ Touchscreen IPS LCD Display: A popular and widely-used option, compatible with Raspberry Pi Pico and other models. (480×320 resolution)
  2. Waveshare 1.3″ OLED Display Module: A compact and low-power option, suitable for small projects. (64×128 resolution)
  3. 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)
  4. Waveshare 5″ DSI Capacitive Touch Display: A high-resolution option with a 5″ screen, compatible with Raspberry Pi. (800×480 resolution)
  5. Pimoroni HyperPixel 4.0 Square: A high-resolution, square-shaped display with a 4.0″ screen, compatible with Raspberry Pi. (752×752 resolution)
  6. Pimoroni HyperPixel 2.1 Round: A high-resolution, round-shaped display with a 2.1″ screen, compatible with Raspberry Pi. (320×240 resolution)
  7. 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)
  8. Waveshare 10.1″ IPS DVI Display Module: A high-resolution option with a 10.1″ screen, compatible with Raspberry Pi Pico. (1280×800 resolution)
  9. Waveshare 1.44″ LCD Display Module: A small and compact option with a 1.44″ screen, compatible with Raspberry Pi Pico. (128×128 resolution)
  10. 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

  1. Attach physical buttons to GPIO pins for play, pause, next, and previous controls.
  2. 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:

  1. NanoSound USB DAC: A popular option with 24-bit/96kHz resolution, featuring a Savitech SA9023 USB decoder and a headphone amplifier.
  2. 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.
  3. PecanPi DAC/Streamer: A single-package solution combining a Raspberry Pi and a DAC, available with Volumio (RaspyFi) pre-installed.
  4. Orchard Audio PecanPi DAC/Streamer: Similar to the above, but without a built-in power amp.
  5. 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

  1. Test Audio Output:
    speaker-test -t sine -f 440 -c 2
    
  2. Debug Issues: Check MPD logs:
    tail -f /var/log/mpd/mpd.log
    
  3. 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!

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More