Fip Radio

I was tinkering with my Raspberry Pi / Arduino internet radio, and stumbled upon David Hepworth talking about Fip radio. This is France Inter Paris, which plays ‘French chanson, jazz, world music, film soundtracks, alt.rock and the occasional blast of classical music’ (according to The Guardian). I suspect that the French spoken links are at least as appealing as the music. So I added Fip to my roster of radio stations on my Raspberry Pi by typing
mpc add http://mp3.live.tv-radio.com/fip/all/fip-32k.mp3
at the command line. Up until now I’ve mostly been listening to BBC stations I can hear on DAB, so it’s nice to have a station I could only listen to on the internet – makes the project more worthwhile. I could still do with some more interesting internet stations – any suggestions?

I also tweaked the Python code for the radio player itself to account for the extra station – there are 8 on my radio not 7 now.

I also added some code to remember which station I was listening to last time, so that when I turn it on it’ll play that station, which is what most real radios do. It stores the station number in a file called station.txt every time you change channel.

Here’s the code below for lcd-soundsystem.py, which is in my /home/pi directory. It’s run when I turn the Pi on by adding the line
(sleep 65; python /home/pi/lcd-soundsystem.py)&
to /etc/rc.local. The ‘sleep 65′ is needed because I’m using wifi, and it takes an age (well, over a minute) for the wifi network to come up.

The radio itself was made by plugging an LCD shield into an Arduino Uno, plugging that into a Raspberry Pi’s USB socket. The Pi has music players mpc and mpd installed, plus nanpy, which allows the Pi to talk to the Arduino. The up and down buttons on the display change the channel up and down, left and right decrease and increase the volume and the SEL button acts as a pause / mute. At the moment the PAUSE display is over-written by the clock thread – I need to work out how to get the clock thread to know what state the pause button is in.

(NB – this code below was updated May 2014 – click here.)

#!/usr/bin/env python
import time
import os
import thread, itertools
from nanpy import Arduino
from nanpy import Lcd

# configure pins for Hobbytronics LCD shield
Arduino.pinMode(0, input)
lcd = Lcd([8, 9, 4, 5, 6, 7], [16, 2])

# read station number from text file
f = open('/home/pi/station.txt', 'r')
station = int(f.read())
f.close

# threaded function to show time twice a minute
def showTime():
   while True:
       now = time.localtime(time.time())
       lcd.printString(time.strftime("%H:%M   %d/%m/%y", now), 0, 1)
       time.sleep(30)

lcd.printString("MyLittleRadio1.3", 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)
  print L
  print sttn

# station = 4
os.system("mpc play " + str(station))
getTrack()
pause = 0

# start a new thread for displaying time
thread.start_new_thread(showTime, ())

while True:
  #take a reading
  key=getKey()
  if key == "UP":
    station += 1
    if station > 8:
       station = 1
    print(str(station))
    os.system("mpc play " + str(station))
    getTrack()
    f = open('/home/pi/station.txt', 'w')
    f.write('%d' % station)
    f.close
  elif key == "DOWN":
    station -=1
    if station < 1:
       station = 8
    print(str(station))
    os.system("mpc play " + str(station))
    getTrack()
    f = open('/home/pi/station.txt', 'w')
    f.write('%d' % station)
    f.close
  elif key =="LEFT":
    os.system("mpc volume -3")
  elif key =="RIGHT":
    os.system("mpc volume +3")
  elif key == "SEL":
    if pause == 0:
      pause = 1
    elif pause == 1:
      pause = 0
    os.system("mpc toggle")
    if pause == 1:
      lcd.printString("      PAUSE     ", 0, 1)
    elif pause == 0:
      noo = time.localtime(time.time())
      lcd.printString(time.strftime("%H:%M   %d/%m/%y", noo), 0, 1)

# added for key press debounce
  time.sleep(0.1)
This entry was posted in Arduino, Raspberry Pi and tagged , , . Bookmark the permalink.

5 Responses to Fip Radio

  1. James says:

    NPR have an API. Is that any use for you?

  2. Pingback: Scrolling LCD text on Arduino – Raspberry Pi | Blog My Wiki!

  3. Pingback: Quick and dirty Raspberry Pi radio scheduling | Blog My Wiki!

  4. Tony Brough says:

    I work a lot in Switzerland and they have 3 internet stations there that are worth listening to. A lot of my friends and family agree and some seem to be permanently tuned in to the Pop station.

    They are: Radio Swiss Pop, Radio Swiss Classic and Radio Swiss Jazz.
    All are pretty much continous music – 24/7

    Cheers
    TonyB

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>