Home Introduction Contact Search Sitemap Raspberry Pi

Pi Simple Radio
 
Home
Up
Pi Traffic Lights
Pi I2C Traffic Lights
Pi Simple Radio
Raspberry Pi bootcamp
Pi Motor Relay

 


Comments ?
Email:


 

 

 

bulletSimple Raspberry PI Internet Radio

  Below are the instructions to make a very simple Internet radio using the Raspberry PI. Any prototyping board can be used. The design uses four push buttons to change channel and adjust the volume.
 
 
 

Features

bulletRaspberry PI
bulletFour button operation. Channel Up/Down and Volume Up or Down
bulletControlled by a Python application. See source below.
bulletUses the Music Player Daemon (MPD) andclient (MPC)
bulletCan use any standard MPD client.

 

 
.

horizontal rule

 
bulletParts  List
Part Description Supplier
Raspberry PI Raspberry PI credit card computer Farnell or RS
4 Gigabyte SD card For the operating system Any computer or photographic store
Four 1K resistor For GPIO input switches Tandy or Farnell Element 14
Four push to make switches Either PCB mount or wired Tandy or Farnell Element 14
Prototype board Any suitable  
26 way ribbon cable To connect to Rasberry PI  
Single strand wire Various colours Any electronics shop

 

bulletWiring
GPIO header Component wiring
1 +3.3v  supply
6 Ground 0 Volts
15 Channel Down Switch -->  1K --> 3v3
16 Channel Up Switch -->  1K --> 3v3
11 Volume  Down Switch -->  1K --> 3v3
12 Volume Up Switch -->  1K --> 3v3

 

bulletMusic Player Daemon Installation

 To install the Music Player Daemon and client run the following

$ apt-get install mpd mpc

 

bulletCode for the Raspberry PI internet Radio (radio.py)

# Simple Raspberry PI Internet radio using four buttons
import RPi.GPIO as GPIO
import os
import atexit
from time import sleep

# Register exit routine
def finish():
    exec_command("service mpd stop")
    print("Radio stopped")

atexit.register(finish)

# Switch definitions
VOLUME_UP = 11
VOLUME_DOWN = 12
CHANNEL_UP = 15
CHANNEL_DOWN = 16

# Execute system command sub-routine
def exec_command(cmd):
     result = ""
     p = os.popen(cmd)
     for line in p.readline().split('\n'):
          result = result + line
     return result

### Main routine ###
if __name__ == "__main__":
     GPIO.setmode(GPIO.BOARD)
     GPIO.setup(VOLUME_UP,GPIO.IN,pull_up_down=GPIO.PUD_DOWN)
     GPIO.setup(VOLUME_DOWN,GPIO.IN,pull_up_down=GPIO.PUD_DOWN)
     GPIO.setup(CHANNEL_UP,GPIO.IN,pull_up_down=GPIO.PUD_DOWN)
     GPIO.setup(CHANNEL_DOWN,GPIO.IN,pull_up_down=GPIO.PUD_DOWN)
     exec_command("service mpd start")
     exec_command("mpc clear")
     exec_command("mpc load mylist.pls")
     exec_command("mpc play")
     exec_command("mpc volume 70")

     while True:
          newChannel = False
          if GPIO.input(VOLUME_UP):
               exec_command("mpc volume +4")
          if GPIO.input(VOLUME_DOWN):
               exec_command("mpc volume -4")
          if GPIO.input(CHANNEL_UP):
               exec_command("mpc next")
               newChannel = True
          if GPIO.input(CHANNEL_DOWN):
               exec_command("mpc prev")
               newChannel = True
          if newChannel:
               current = exec_command("mpc current")
               print current
          sleep(0.2)

 

bulletInstall mpc and mpd music player

$ sudo apt-get install mpc mpd

bulletTo run the PI internet Radio

$ sudo python radio.py
 

 

 

 

Back Next
Copyright 2004 Bob Rathbone. All rights reserved