Raspberry Pi Version!

A project log for Adabox Internet Radio

1-Button Internet Music Box based on ESP8266

Matthew GorrMatthew Gorr 07/02/2017 at 14:520 Comments

I implemented essentially the same project using a Raspberry Pi B+ instead of a Feather HUZZAH. This version uses omxplayer to load streams from the same URLS.TXT used by the HUZZAH version. This project still hasn't passed cardboard box phase:


omxplayer can play internet music streams! Try the command below for yourself!

The newer versions also include built-in hotkeys, including "q" to quit. I used the Pi Key Daemon make the Pi recognize a button connected to GPIO 4 as the Q key.

A bash script (shown below) reads the contents of the playlist file into an array, then calls omxplayer with the first stream. When the user presses GPIO 4 Button, omxplayer quits, and the bash script takes care of calling omxplayer with the next stream. Between omxplayer calls, the script also triggers a shutdown call if the button is held down for two seconds.

Raspberry Pi Radio Hardware Setup

Raspberry Pi Radio Software Setup

NOTE: Because the script is executed in .bash_profile, it will try (and fail) to execute a second instance of omxplayer each time you login over ssh. I have been able to avoid system crashes by pressing CTRL+C immediately after entering my password during ssh.



# omxplaylist script
# Matt Gorr
# July 5th, 2017
# Portions borrowed from

HALT=4                # Halt button GPIO pin (other end to GND)

gpio -g mode $HALT up  # Initialize GPIO states
gpio -g mode $HIGHPIN out

mapfile -t channels < /boot/urls.txt
gpio -g write $HIGHPIN 1

while :
	for (( i=0 ; i<${#channels[@]} ; i++ ))
		wall ${channels[$i]}
		omxplayer http://${channels[$i]}
		currenttime=$(date +%s)
		while [ $(gpio -g read $HALT) -eq 0 ]; do
			if [ $(($(date +%s)-currenttime)) -ge 2 ]; then
				wall "Shutting Down..."
				gpio -g write $HIGHPIN 0
				shutdown -h now
	#echo "****End of While Loop"