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:
Introduction
omxplayer can play internet music streams! Try the command below for yourself!
omxplayer http://ice1.somafm.com:80/u80s-128-mp3
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
- Connect button so that pushing the button pulls GPIO4 to ground. I also used an external 10k pull up resistor to 3.3V, but that may be unecessary.
- (optional) set GPIO17 high to provide voltage for button pull up, because the pins were physically closer on the B+.
- Connect 1/8" output to external audio amplifier input. I used a half-watt DIY amp I got from RadioShack (RIP)
Raspberry Pi Radio Software Setup
- Raspbian Jessie Lite
- Download/Install
- Add network info to /etc/wpa_supplicant/wpa_supplicant.conf
- Force analog audio output in raspi-config
- Install omxplayer - sudo apt-get install omxplayer
- PiKeyD - https://github.com/mmoller2k/pikeyd
- Download/Make
- NOTE: PiKeyD comes configured for RPi1. If using a 2 or 3, you need to edit the source code before compiling - https://github.com/mmoller2k/pikeyd/issues/3
- Copy pikeyd executable to home directory
- Edit configuration File to register GPIO 4 as "Q" key
- Add "sudo /home/pi/pikeyd -d" to /etc/rc.local
- Download/Make
- Playlist
- Populate /boot/urls.txt with list of stream URLs, one per line.
- Do not use "http://" at the beginning of line
- Bash Script
- code is shown below. I named the file "omxplaylist"
- make it executable "chmod +x omxplaylist"
- add "sudo /home/pi/omxplaylist" to ~/.bash_profile
- That's it for software! Reboot and rock out!
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.
/home/pi/omxplaylist
#!/bin/bash
# omxplaylist script
# Matt Gorr
# July 5th, 2017
# Portions borrowed from https://learn.adafruit.com/raspberry-pi-wearable-time-lapse-camera/software
HALT=4 # Halt button GPIO pin (other end to GND)
HIGHPIN=17
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 :
do
for (( i=0 ; i<${#channels[@]} ; i++ ))
do
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
exit
fi
done
done
#echo "****End of While Loop"
done
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.