Saturday 15 June 2013

Making yet another Internet Radio project with Raspberry Pi

For years I've been using my old looking replica of Bush TR82 radio to listen our local radio stations, but recently I decided to push its reception limits a bit further and upgraded it with help of Raspberry Pi to an Internet Radio.

So, with some extra components from a few broken things now it looks like this:
Actually, it is not just a radio anymore - it is a weather station as well :) It monitors and displays current temperature, pressure and relative humidity. Why? Just because after connecting screen and control buttons I still had a few IO pins available plus it will help me in future to build intelligent house heating system

Some new exterior features:

 Screen (used to be Nokia 3210 phone) displays 6x14 lines (from top to bottom):
  • Current mode (Radio if Internet Radio mode is on or current relative humidity), WiFi signal strength, current time
  • Radio station name
  • Current song title (scrolls if does not fit to 14 characters)
  • Current temperature and pressure.

If radio is in Internet mode, screen is highlighted by blue LEDs (used to be Logitech G-15 keyboard).

Control buttons (used to be Canon 300D camera) allows to select different radio stations from a play list or to bring up control menu with  some system info (CPU load and network transfer rate):

There is also a simple CLI to control some functionality remotely or to get sensors reading:

Rear side has a window for Temperature/Pressure/Relative Humidity sensors:
The window is covered with a mesh which used to be office paper holder.

Raspberry Pi itself is located in radio's battery compartment:

Flat cable connects RPi to a board fastened inside to top of the battery compartment:
Shielded power supply for RPi sits beside radio power transformer. Note a power switch I've added (used to be table lamp switch).

Front panel with a bit of hot glue and insulation tape to hold screen and buttons:

List of main components used:
  • Raspberry Pi Model A with WiHi dongle
  • Nokia 3210 screen
  • MPL3115A2 Pressure/Temperature Sensor breakout
  • RHT02 Relative Humidity/Temperature Sensor
A bunch of small components: buttons, resistors, optocoupler to detect Radio/Internet mode, LEDs, transistor to drive LEDs, small sockets and cables - mainly salvaged from different broken appliances I kept in the attic for occasions like this :)

Third party software:
  • mpd as media player 
  • mdpclient library to control mpd
  • bcm2835 library by Mike McCauley to  read/write IO pins and to communicate with MPL3115 sensor which uses I2C with repeated start.
Everything glued together by C with a bit of C++ extensions to a single thread. Control buttons monitored by poll() with 100ms timeout used to increment all sort of counters. Nokia screen sits on SPI interface, nothing fancy there, standard RPi Linux SPI driver is used. To read RHT03 humidity sensor instead of tight loop polling I'm using interrupt handler.

Next steps:


  1. I'm really interested to see how you control the MPL3115 as I've been battling this for a couple of days.
    Following your lead I installed the bcm2835 library but even Mikes examples I can't get working, all I/O reports NAK.
    I know the device I have is OK, its on a Sparkfun breakout board with builtin pullups and works fine on Arduino.
    Any insight gratefully received.

    1. Hi,
      I've created new repo with two header files. Example main() is in, have not tried it, just created extraction from my code for the radio. Let me know how it works for you.


    2. Thanks for the help.
      When I run the code I get
      Invalid device ID: 01, must be C4
      t=200.88 P= 0kP
      i.e. in mpl_config the rpi_i2c_read_reg returns NACK
      so nothing has changed.
      I know the device is hooked up OK because i2cdetect shows device address 0x60 present (have to do modprobe i2c_bcm2708, modprobe i2c-dev for that to work.
      How did you hook up the mpl3115, with discrete pullups or is it in a breakout board?

      Regards, David

    3. Actually I removed pullups from Sparkfun breakout board, so I use pullups which are on RPi itself. As I remember, initially I had some problems with this breakout but it turned out to be just a bad connection on my breadboard.
      I have spare MPL3115 breakout board so I can try it sometime this week whith my example code and will let you know.

      Regards, Andrey

    4. Just tried it - works perfect. I've added main.c and Makefile to the repo.
      This time I did not modify breakout, just connected it to RPi.
      Actually i2cdetect does not detect MPL3115A2 sensor, because of repeated start? In your case it detects it, so maybe your version does not require repeated start? You can try to remove RPI2C_RS_READ from mpl_config() and rpi_i2c_read_regs() call in the main.

      Regards, Andrey

  2. Hi Andrey,
    Well thats weird. First I ran it out of the box and got 0 for both temp & pressure.
    Then I removed RPI2C_RS_READ as you said and got 0xEE for ID instead of 0xC4.
    So I replaced RPI2C_RS_READ and now get 0xC4 and correct temperature & pressure.
    Being curious I removed RPI2C_RS_READ again but it still works fine.
    Finally, I powered down the board and powered it up again and it still works fine.
    The bottom line is that it works for which I'm eternally grateful, buts its niggling that I don't still do't fully understand what happened.

    Thanks again,