RaspberryPi internet radio with display

I liked the simple elegance of my Really Simple Raspberry Pi internet radio that just had a push button to change the channel… but I saw this project that connected a RaspberryPi radio to an Arduino LCD shield for displaying station names and for controlling the radio with buttons.

I happen to have an unused Arduino Uno and LCD shield lying around, so I decided to have a go at this myself. My LCD is a different kind, so I had to change the code for my shield – it’s one of these: http://www.hobbytronics.co.uk/arduino-lcd-keypad-shield

The main steps were:

1) Install mpc & mpd, add 7 internet radio stations.

2) Install nanpy.

3) Add the code below.

So far my code only changes the channel up and down, next step is to do volume as well. I had to use a USB port to drive the display, so I’m back to using the Pi’s internal headphone jack rather than USB. It’s also not very stable – sometimes it is better to keep things simple. It’s usually fairly obvious which station you’re listening to, so does a radio need an LCD display?

Here’s my rough Python code. I called it lcd-soundsystem.py. Ahem.

#!/usr/bin/env python
import time
import os
from nanpy import Arduino
from nanpy import (Lcd)
Arduino.pinMode(0, input)

lcd = Lcd([8, 9, 4, 5, 6, 7], [16, 2])

lcd.printString("MyLittleRadio v1", 0, 0)
lcd.printString("by @blogmywiki  ", 0, 1)

def getKey():
   val = Arduino.analogRead(0)
   if val == 1023:
      return "NONE"
   elif val < 100:
      return "RIGHT"
   elif val < 200:
      return "UP"
   elif val < 400:
      return "DOWN"
   elif val < 600:
      return "LEFT"
   elif val < 800:
      return "SEL"
      return "KBD_FAULT"

def getTrack():
  L= [S.strip('\n') for S in os.popen('mpc').readlines()]    # Get the Track info from the stdout of the mpc command
  sttn = L[0][0:15]                                                         # Pick out the Station and Track info
  lcd.printString(16*" ", 0, 0)                                            # Send it out to the LCD Display
  lcd.printString(sttn, 0, 0)
  lcd.printString(16*" ", 0, 1)
  print L
  print sttn

station = 4
os.system("mpc play 4")

while True:
  #take a reading
  if key == "UP":
    station += 1
    if station > 7:
       station = 1
    os.system("mpc play " + str(station))
  elif key == "DOWN":
    station -=1
    if station < 1:
       station = 7
    os.system("mpc play " + str(station))
This entry was posted in Arduino, Raspberry Pi, Raspbian and tagged , , , . Bookmark the permalink.

4 Responses to RaspberryPi internet radio with display

  1. Raveendranath says:

    I am writing to you from Muscat, Oman in Arabia.
    Thank you very much for your tutorials on RPi! These are very helpful and I have made the internet radio as you have proposed and it work very well!

    I am now planning to add the Arduino and the LCD screen to it. I have the Arduino UNO and a plain 16×2 LCD. Could this plain LCD screen be used in place of the shield? Kindly provide me with the hardware connection details of the set up.

    Thanks and regards

    • blogmywiki says:

      Hi there, glad you find my blog useful. The easiest way would be to use an LCD display designed to plug straight into the Raspberry Pi, such as this one. I only used the Arduino because I already had an Arduino and an LCD shield sitting around not doing anything. The code would need tweaking for the Adafruit screen, but it would be a more elegant solution.

    • Jiraslan says:

      Hello Adrian,This is my firs Arduino and I also want to make exactly the same thing as you did but i have stlmbued across a serios of problems because some of the code that I am using in my arduino is writen in romanian and I don’t know exactly what to change in my code.Could you please help me ? The thing is that my arduino has Temperature, Humidity, Pressure and light sensor and there is a lot of code I must go through.Kind Regards,Flaviu Vlaicu

  2. Michael says:

    I would love to do the same thing, though I have this kind of LCD shield.
    How can I do the wiring to Raspberry PI?



Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>