Audio Book: Raspberry Pi Zero Internet Radio with pHAT BEAT

A couple of days ago I laid my hands on a pHAT BEAT and two small speakers. Together with a Raspberry Pi Zero (and an Internet connection of course) this makes building an internet radio easily possible. And yes, inspiration for this project was also the Pirate Radio Kit.
The pHAT BEAT comes along with stereo output, an amplifier, a couple of buttons for adjusting the volume, playing/pause, forward/backward and powering off and a number of bright and shiny LEDs. Just the perfect audio hardware component for an internet radio.

Hardware

Raspberry Pi Zero with Micro SD card and up-to-date OS
USB WiFi stick (not needed if a Raspberry Pi Zero W is used)
pHAT BEAT
2
small speakers
some cables
USB power supply

Assemble the hardware as required. This implies some soldering for the headers of the Raspberry Pi Zero and the pHAT BEAT as well as the connections to the speakers. This tutorial is a good guideline to see what to do.

Software

Once the Raspberry Pi Zero is accessible headless in the local WLAN network (see this blog post for setup instructions) install the pHAT BEAT Python library.

Luckily the software for an internet radio project already exists. The setup is really made simple by running the setup script only. The setup script installs the required software and adjusts the whole configuration on the Raspberry Pi Zero. See https://github.com/pimoroni/phat-beat/tree/master/projects/vlc-radio for further reference.

Once the installation is complete, reboot. After reboot the internet radio will be automatically started and will play some example music.

The pHAT BEAT’s buttons directly work with the example projects software. Adjusting the volume or switching between different items on a configurable playlist (see configuration below) is directly possible. Even the off button immediately works: it turns off the radio and fully shuts down the Raspberry Pi Zero.

Configuration

Configure Internet Radio Streams

Collect the URLs of your favourite internet radio streams. Create the file /home/pi/.config/vlc/playlist.m3u . Insert the URLs into the playlist as in this example:

Example playlist.m3u
#EXTM3U
#EXTINF:0,station1
#EXTVLCOPT:network-caching=1000
http://station1.net/.../...
#EXTINF:0,station2
http://station2.com/.../.../mp3/...
#EXTINF:0,station3
http://station3.something/...

Alternatively create a playlist containing the radio stream URLs of your choice in VLC and save the playlist to a file. This file can be copied to the Raspberry Pi Zero to /home/pi/.config/vlc/playlist.m3u.

After reboot the forward/backward buttons of the pHAT BEAT can be used to switch between the different internet radio streams.

Wrapping: The Result

The wrapping was simple in this case: an old book became a nice „audio book“! Similar to my ‚book book shelves‘ an old book is hollowed inside with a sharp knife so the hardware fits in.
Surprisingly well is the sound of the speakers inside the book!
All I need now is to find a way to operate the small buttons of the pHAT BEAT…

Info & Links

https://github.com/pimoroni/phat-beat

 

sleepy pillow

Quite a while ago I had the idea to create a pillow with a Lilypad MP3 . The „Sleepy Pillow“ should play songs at random for approx. 45 minutes and then power down as good as possible to save battery.

The Lilypad MP3 is an Arduino board that takes an SD card with audible files and plays them with speakers attached.

This is how the Sleepy Pillow was realized:

components used

Lilypad MP3
speakers
conductive thread, needle for sewing
LiPo, additional JST connectors
Lilypad switch
fabric
pillow filling
for testing: alligator clips
mini SD card with MP3 songs

make it happen

First I set up the main components with alligator clips before sewing. That way the source code could be conveniently tested.

IMG_20151003_141823_sleepypillow_setup

I put something below the speakers to prevent them from vibrating too much while testing.

From my song collection I chose several songs in MP3 format and placed them on the mini SD card using an adapter. The filenames are consecutive numbers.

When the source code was working so far I started to sew the components on the fabric I selected as a pillowcase. For the LiPo I created a small bag.

I added a switch for turning the power completely off manually.

to consider

The Lilypad MP3 can not play songs when attached via USB to a computer. Only serial output can be seen! The player starts to play the files but the playback stops after a few seconds. The reason is that there is not enough power to drive the speakers via USB. An additional power supply such as a LiPo is required. The program can only be fully tested attaching a battery to the Lilypad.

The audio files on the SD card may be of the type MP3, WAV, MP4, FLA, OGG, WMA or AAC. The filenames should be in the format 8.3 which is up to 8 digits for the filename and 3 digits for the file extension. I went for consecutive numbers as filenames to ease random selection.

the source code

The source code is based on the examples that can be found for the Lilypad MP3. The sleep code originates from the Arduino playground.

SleepyPillow.ino

I used the latest Arduino Software from https://www.arduino.cc/en/Main/Software. Great tutorials to get started with the Lilypad MP3 are at the sparkfun website.

how it works

When the Sleepy Pillow is turned on it starts to play songs from the SD card at random. The music stops after the desired time limit is reached. Then the Lilypad MP3 is „put to sleep“ to save battery. Additionally it is possible to use the power switch…

The volume is automatically turned down approx. 10 s before the time limit is reached.

IMG_20151007_194819_sleepypillow