Internet Radio Project Part 1

I’m planning to make an internet radio using my Raspberry Pi.

First off I plan to control it entirely using a web interface which I guess I’ll write. The popular alternative is to use MPD with one of its cli/web/Android clients. I don’t fancy all of the bloat of XBMC.

Eventually I may add an LCD display and a couple of GPIO buttons at least for play and skip. Edit: I’m really considering this now as I could do with an alarm clock that uses NTP, I could even get it to turn the display off at night until a GPIO button is pressed (which could double as a snooze button). I’ve bought an incredibly cheap (God bless ebay China!) HD44780 LCD module and header pins, jees I hope I can find my soldering iron!

I plan to be able to use internet radio stations as well as playing MP3 files from the NFS server and local storage on the SD card or USB stick.

I’ve bought a wifi dongle and USB soundcard as apparently the built-in 3.5mm line out is pathetic and suffers from popping. It will all be powered by a 7-port USB hub that I have a couple of already for my Pi.

Speakers will be the complicated part – I could go the easy route and get some USB-powered speakers which could be powered from the same hub, or I could use some old PC speakers and a DC-DC power adaptor to convert whatever the speakers use (12V?) to 5V for the Pi, thus still only using one mains plug. Edit: I’ve decided to go for these cheap’n’cheerful USB speakers which I’ll canabalise. Edit: the speakers are going back, they emit a lot of static when not in use – even on my laptop/desktop machines. I also noticed that the Pi’s 3.5mm jack does indeed suffer from popping and not being very loud.

Then finally I need to find a case to put it all in.

I’m going to get the system initially setup using my Model-B, but am thinking that eventually I could use a cheaper Model-A (and a smaller SD card) as I don’t need ethernet or 2 USB ports, or case. I wonder how well Debian+MPD+nginx would run in 256Mb though…..

So far the current cost is £22.19 for speakers, LCD, DAC, 802.11n dongle and 0.1″ header pins. That doesn’t include the Pi (£18.88 for Model-A) and some sort of case, and I already have the USB hub (about £4) and various USB cables, resistors/pots, GPIO cables, breadboard etc. Not bad considering a Logitech radio would be £130+ and not half as tweakable.

RPi Traffic Lights Demo

My cables have arrived and I’ve made my first Raspberry Pi hardware demo. If you press the button the computer will send the voltages to the GPIO pins to simulate a traffic light system (red, red & amber, flashing amber, green).

I noticed that a few tutorials seemed to leave out the 10K pull-down resistor, 3.3V line and 1K protective resistor (just connecting the button to GND and GPIO) and so the voltage change wasn’t detected on the input pin, also without the 1K resistor you could damage the pin if you accidentally configure the GPIO connected to the switch as an output rather than an input.

Also it seems that as the RPi doesn’t have any analogue inputs, things like photoresistors can’t be used without an ADC chip or some unreliable capacitor charging circuits and code.

The breadboard image was created with the excellent Fritzing program and the Adafruit RPi parts:

The code is written in Python:

#!/usr/bin/env python

# import modules
import RPi.GPIO as GPIO
import time

# disable debugging

# use pin numbers instead of gpio numbers

# setup gpio2 as output/led
RED = 3

# setup gpio3 as output/led

# setup gpio4 as output/led

# setup gpio17 as input/button

# loop waiting for button
while 1:    
    if GPIO.input(BUTTON):  
        # red
        print "RED"
        GPIO.output(RED, GPIO.HIGH)

        # red and amber
        print "RED & AMBER"
        GPIO.output(AMBER, GPIO.HIGH)

        # flashing amber
        print "FLASHING AMBER"
        GPIO.output(RED, GPIO.LOW)
        GPIO.output(AMBER, GPIO.LOW)
        GPIO.output(AMBER, GPIO.HIGH)
        GPIO.output(AMBER, GPIO.LOW)
        GPIO.output(AMBER, GPIO.HIGH)
        GPIO.output(AMBER, GPIO.LOW)
        # green
        print "GREEN"
        GPIO.output(AMBER, GPIO.LOW)
        GPIO.output(GREEN, GPIO.HIGH)
        # all off
        GPIO.output(RED, GPIO.LOW)
        GPIO.output(AMBER, GPIO.LOW)
        GPIO.output(GREEN, GPIO.LOW)

I also have another version of the code that uses eSpeak to say the colours rather than print them to the screen. I found that Festival was too slow to initialise and Flite didn’t produce quite such good sound.

Raspberry Pi First Look

I’ve just received my Raspberry Pi miniature computer and some SD cards to go with it to experiment with.

First off I inserted the Raspbian (Debian Wheezy for ARM) SD card, which I’d written to disk in 8mins using the following as root:

dd if=2012-12-16-wheezy-raspbian.img of=/dev/sdc bs=4M

Or for RISC OS (2Gb took 7mins):

dd if=ro519-rc6-1876M.img of=/dev/sdc bs=4M

Or for Chameleon (4Gb took 15mins):

dd if=chameleon_v02.img  of=/dev/sdc bs=4M

Next I plugged in all my cables – HDMI to the TV, powered hub to the micro-USB port and a regular USB port on the Pi, then into the hub my Logitech EX100 wireless keyboard and mouse transmitter. That’s kind of cool as it means I don’t have to have an extra couple of wires hanging around and I could just put the kb+mouse in a cupboard somewhere and leave the transmitter plugged in. That was the plan anyway. I think I’ve sorted it now with a few presses of the “Connect” buttons, but I’ve had a terrible time trying to get the Pi to see both kb+mouse rather than one or the other. I think that’s the issue I had with it when I used it with a regular PC though, it was pretty flaky and lost its config then, so not really a Pi issue I don’t think.

Anyway, after configuring things on first boot via raspi-config I got an LXDE desktop. Well all I can say at this point is whomever thinks they can replace their laptop with a Pi hasn’t actually tried it yet! Its slow as molasses and I’ll be changing to runlevel 2 on next boot lol; Hell an apt-get dist-upgrade took about 2 hours with the screen redrawing every 30secs or so. OK this is using a Class4 SD card, but the main problem was CPU was at 100% throughout.

I’ve got to re-run raspi-config in a bit to fix the black borders on the screen, apparently turning off overscan will fix that. Edit: disabling overscan has stretched the display to fill the screen now, but actually its a tiny bit too wide and chops off the left and right of the screen. Mplayer stuttered and didn’t actually display anything when trying to play a 1080p or 720p .mkv file over NFSv4, hopefully raspbmc does better. Edit 2: I found a better fix is to add this lot to /boot/config.txt, which also overclocks a little to 800MHz:


I tested that a couple of programs I compiled for ARMv6 worked which they did, I used the official toolchain from GitHub. First off was a simple “Hello, World!”:

arm-bcm2708hardfp-linux-gnueabi-gcc -o test test.c

Then I compiled iperf, which gave me an error regarding malloc which I fixed using the instructions here which allowed me to compile it using:

export PATH=$PATH:~/raspberrypi/tools/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin
export ac_cv_func_malloc_0_nonnull=yes
./configure --host=arm-bcm2708hardfp-linux-gnueabi

The case that comes from CPC doesn’t allow access to the GPIO headers so I’ve got to try opening it up in a bit. Edit: it was easy enough to open, in fact I did it when it was turned on and all the cables plugged in!

The Raspbmc installer is rubbish, after running and re-running it three times I gave up, I think i’ve got it to the point where its just failing to umount the drive now, it should have written the distro and config ready to boot on the Pi. Edit: Turns out that the installer is only a basic image – when you first boot it goes and downloads the actual installation! Its runs pretty well too – 1080p/720p MKV’s played fine over NFS, even over 100BaseT, as did 480p XviDs. I can see how you could replace your Atom HTPC with one of these (and a remote control) although the menus run a bit slowly and I’ve not tried Library mode.

Edit: RISC OS 5 runs fine on it, including my my old Assembler/BASIC programs – just had to set the filetypes and the ones that were crunched I had to reset to their original BASIC sourcecode and up the memory allocated a bit. Screenshot. It does seem pretty dated though, all those weird mouse button combinations that could be so easily just be replaced using keyboard shortcuts, even drag’n’drop saving doesn’t seem so natural anymore. It seems to get files onto the Pi you have to use Fat32FS with a USB stick, odd that its not included with the OS, as RISC OS 3 even could read FAT32 disks….?

Chameleon is fun too, there’s a lot of old computers I recognise that it emulates – ZX Spectrum, Atari ST, C64, VIC-20…. They don’t do much without any ROM’s though.

Edit: I found rpi-update which fetches the bleeding-edge firmware image for the Pi including a 3.6 kernel.

Edit 2: It seems that the Pi’s USB stack doesn’t like my USB webcam driver (PWC) as Motion doesn’t create any output. I do recall that even on my desktop machine when plugged into a hub the PWC driver would kernel panic, and really even the built-in USB ports on the Pi are hubs, so its not surprising I guess.

I also upgraded WordPress