FEATURES
Using the raspberry zero means that we have only one usb port that we can use to play music files. Furthermore there are many gpio pins and communication ports like i2c spi so we can use them to extend the functionallity of the device. It has a.o. the following features:
- Controllable via the webinterface and a pushbutton.
- Its easy to pick a station from a select list.
- The chosen station can also be played in the browser.
- It has an easy to use mp3 player with various options.
- explore an usb stick to play individual mp3 files or entire maps.
- It has a 10 channel equalizer to adjust the sound.
- artist and songtitle is displayed on webpage and lcd.
- In case of no wifi connection it opens a wifi config portal.
- The user can easely maintain a custom stations list.
- It has a timer that can be used as wake-up alarm.
- With a BME280 connected it can work as weather station.
I am exploring the possibility to use it also as a domoticz system. This would mean that we have to giveup the mp3player as the USB is needed for the RFLINK GATEWAY device. Or maybe the usb can be extended?
I am working on a version with an LED matrix display. This opens the possibility to use the device as news ticker.
The hardware
There are only a few components involved. This hardware is realy simple and very cheap.
- 1 x Raspberry pi Zero W ~$10
- 1 x 20x4 lcd display ~$3.5
- 1 x PCM5102 I2S DAC GY-PCM5102 ~$3,5
- an usb power unit (or a diy power supply)
- some small components
If you like to build a complete audio installation we need an amplifier/speakerset. We can make the Raspberry switching the power on/off of the speakerset. For this we would need an opto-coupler and a triac. And a wall outlet to mount at the back of the housing.
schematic
The hardware:
Building it only means connecting wires between the components. And installing the software on an SDcard. So almost everybody could build this.
In my case i want to switch the power of the speakerset also. This means that i have to build a power supply board with a triac that can switch the main power. So i soldered a board with 220v AC and a 5v DC power supply. There is a triac and an optocoupler that i connect to the gpio headers of the raspberry.
I build a case for the radio that has a wall outlet that is switched by the triac. So we just have to plug-in the powerplug of the speakerset.
I had a very hard time installing the DAC, the Chinese seller forgot to solder some small configuration pads at the underside of the minescule board. It took me almost a day to find this out.
The software:
I started with the installation of a simple linux version without a GUI. So i needed to install ssh and samba and apache2 webserver.
The next thing was getting the sound system to work. The internet provides enough information on that.
The musicstreamer is mpg123. This program provides icy metadata so we can show the artist and songtitle on the display and on the webpage.
As for the rest is was a matter of building the html pages and scripts to get it all to work.
I had a very hard job to get the artist and song information on the webpage and lcd screen. At the moment it works by having a job running in the background that sleeps 10 secs before checking if there is new meta data available from the streamer. Probably not the best solution but for the moment it does the job.
The equalizer was also a puzzle because the alsamixer can not be controlled via the commandline. I discovered that the settings are keeped in a binary file. I could analize this file with 'hexedit' to see what values were changed when i moved the sliders in the gui of the alsa-equalizer. So i had to develop a script that edits the corresponding values in that binary file when the sliders in the webpage are changed. This works fine with just a bit of lag because the settings must be keeped. This is done by storing them in a textfile. When the webpage is loaded it uses these values to put the sliders back in their right positions.
Another "todo" is mounting of the usb stick. When the mp3 player is called it should check if there is an USB device plugged and if so, mount it. This is also a brainchallenge because only root can do that.
Getting an AP to work was also not simple. But finally it works as it should. When there is no wifi connection, the Raspberry starts an accespoint. We can connect to it with a wifi equiped device and visit the webpage at 192.168.4.1. Here we can provide new wifi credentials and save them. The Raspberry reboots now and connects to the wifi. It shows the IP on the LCD. Very simple and do-able by a noob.
After some months the radio proves very stable. Some improvements have been made. I replaced the button with a touch sensor, this works better because the housing had to be stopped when the button was pressed. I added a led that shows the triggering of the touch sensor.
The connection manager has one disadvantage. When your router is on the same electricitygroup and there is a shut off, the raspberry starts quicker than the router and finds no network. It will start in ap then. Maybe i can build something in that when in AP the raspberry reboots very 5 minutes or so. This will ensure than when you're not at home, your raspberry has network. This is important when you have domoticz running.