Now my news ticker software is working well i thougt it would be nice to have an internet radio that uses the newsticker to display what radiostation and the song played. Apart from the other stuf that can be displayed such as time temperature/moisture/pressure, sunrise, sunset, date, a greeting and a custom message. What is displayed can be configured via the webpage. This turned out to be a rather complex project with 3 SPI clients (the display, the audio board and a memory chip) and 2 I2C clients (the BME280 and a mcp23o17). The memory chip was needed because there was'nt enough memory to buffer incoming mp3 bytes and the MCP23017 because there are not enough pins on the nodemcu.
This device has a.o. the following features:
Switchable via the webinterface or the pushbutton
timers can be configured directly from the webpage.
it has 2 on/off timers with extended options.
software can be updated over the air (OTA.
the ticker content can be configured via the webpage.
domotica sw /cron on a server/phone can switch the radio (only when it is secured).
when the radio switches, the amplifier power is switched also.
the radio has 9 configurable presets.
by choosing preset 0, its only a news ticker / wheather station.
This makes it a real smart device......
The hardware
There are only a few components involved. This hardware is realy simple and very cheap.
1 x ESP826612E 1.50
4 x MAX7219 display 4.50
1 x bme280 sensor 2.80
1 x VS1053 MP3 board 5.00
1 x AC 220V/5VDC Step-down 1.30
1 x MCP23017 0.20
1 x 23lc1024 SRAM 3.20
some small components 1.00
total 19.30
If you like to build a complete audio installation we need an amplifier/speakerset and an extra gpio to switch it on/off. For this we would need an MCP23017 gpio expander ic, an opto-coupler and a triac.
Time to build some hardware.
For this I ordered the several components on ebay. I soldered a little board with a 5V dc supply and a triac switch. Further its only a matter of soldering the wires between the components. It is also possible to use the USB on the nodeMCU for the power but you can't switch the speakerset then. 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 speakerset.
As for the memorychip i investigated some SRAM chips and found that the 23LC2014 was probably the best choice because we can write to without erasing first. Other rams can only write to empty locations which would mean that there is an erase routine needed. This would probably make the program too slow. Furthermore this chip has unlimited read/write cycles.
.
It's a real smart ip-device for less than 20 euro...
The software:
In the software there is a standard part that i use in all of my IOT projects. This part handles the internet connection and the timekeeping. Another part is borrowed from my newsticker project. For the radio part i stole software and completely changed it to use another (not asynchronous) webserver and to save the configurations in SPIFFS.
I had a very hard time to tweak everything because the complexity of the program and the need for a ringbuffer (fifobuffer or que). This buffer caused strange ubstable behaviour. I suspected this was due to memory shortage. After i switched to an external SRAM these problems were not totally over. Next i switched over to Asynchronous Webserver which saved me a lot of memory. After lots of experiments i found out that the large string that holds the website caused fragmentation of the memory. So i reserved a good amount of memory that can hold this string and that did the trick. The former instability is completely gone. It seems that there was no need for the external memory except for the fact that this SRAM has unlimited read/write cycles.
I managed to include an SD module in the radio so i can also play music from an SD card.
I tweaked most of the used libraries to erase unused functions in order to get more memory. The final program although is large, more than 100 A4 pages.