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) time.sleep(2) 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" else: 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") getTrack() while True: #take a reading key=getKey() if key == "UP": station += 1 if station > 7: station = 1 print(str(station)) os.system("mpc play " + str(station)) getTrack() elif key == "DOWN": station -=1 if station < 1: station = 7 print(str(station)) os.system("mpc play " + str(station)) getTrack()