I have been building several sound boxes lately (amps, sequencers), and when i thought of making an internet radio, i found the excellent Esp-radio project using the Arduino IDE to program the ESP8266 WiFi module (ESP-12E version). The documentation is quite complete, and the author Ed is happy to help out via questions on github. I was quite easy to get the prototype working; i spent far more time on putting it into a nice box. It’s a very functional project; the radio can be configured via a web server and i decided to have just 2 buttons on the box: channel up and down.
It uses the ESP8266 to connect to WiFi and select an internet radio station. The MP3 stream is passed on to a sound card (VS1053 chip) via SPI. I already had an Arduino MP3 shield with this exact chip so i used that in my prototype. For the ESP8266 i started with the NodeMCUv1.0 and i thought i would replace it later with a barebones ESP-12E module, but it’s very handy to have the USB connection and voltage regulator on the NodeMCU, and it’s quite cheap these days so i decided to keep the NodeMCU. Below a look into the box and a list of components:
- left: green perf board with NodeMCUv1.0 plugged into 2 rows of female headers, including a voltage divider series read the status of 2 push buttons with the 1 analog input (see Esp-radio doc)
- top left: 2 push buttons going in the voltage divider
- top center: 0.96” OLED screen connected to NodeMCU via SPI (different model from Esp-radio but similar connections)
- top right: double pole switch for the 2 separate power supply lines
- under switch: stereo potentiometer for volume control
- back: 2 speakers 3W 4ohm
- in between the speakers: class D stereo amplifier PAM8403 2x 3W at 4ohm
- front bottom: 2 Lithium ion cells 18650 (recovered from old laptop battery)
- bottom right (not visible): 2 protection/charger PCBs for the Lithium cells
- bottom right (not visible): DC/DC booster PCB for amplifier power supply
- right: blue Arduino MP3 shield with VS1053 chip, later replaced by this VS1053 breakout board
My first prototype was a lot more simple: the NodeMCUv1.0 on a breadboard, powered over USB, with SPI connections to the MP3 shield, powered from the 5V on the NodeMCU. I used the Arduino IDE 1.6.8 because it did not seem to work with 1.6.5. See Esp-radio PDF doc for details on which libraries to install. I figured out you also have to upload the ‘data’ folder into the ESP8266 SPIFFS, that’s a separate operation from the sketch upload. After some configuration (see doc) i got sound over the earphone jack output of my MP3 shield. The Serial output is very helpful for debugging.
Some of the further steps and challenges i encountered:
- i had glitches in my music playback, even with very fast internet access. finally i figured out it was interference from the SD card on my MP3 shield, that is also using SPI. as soon as i removed the SD card from the shield, the problem went away (later on i switched to a VS1053 breakout board without SD card).
- i added an OLED screen, the same cheap one that i always use, with this SSD1306 library. the major difference is that my display requires a RST pin; as we’re a bit short of I/O pins here, i first tried to use the same RST line as the VS1053 (combination with 2 diodes) but that reset does not happen immediately after power up and i wanted my display to switch on immediately. i ended up using GPIO0 for the OLED RST. i know, the screen is small, but it displays the relevant info. i did have to change the code quite a bit to work with my display library. (see below for version with standard 1.8” TFT screen)
- the Esp-radio also includes a web server with a homepage to select the channel, adjust the volume (0-100%) and even basic bass/treble control. also handy for debugging. with the 1 analog pin on the ESP8266 already in use for my 2 buttons, i could not think of an easy way to change this VS1053 volume with a potentiometer, so i just added a stereo potentiometer between the VS1053 output and the input line to the amplifier. the volume shown on screen (VS1053 volume) is the maximum, it can only be changed via a browser.
- adding an amplifier: this is quite straightforward if you power the amplifier from a different power source as the NodeMCU/MP3, but i hoped to use only 1 battery inside. the problem is that the VS1053 audio output is biased to 1.25V which seems common for earphones. so we cannot connect the output jack’s ‘GND’ (which is actually not 0V) to the common GND. this VS1053 doc describes a simple solution to get a line-out signal. however, when using a single power supply, this still had a lot of noise. it seems Class D amplifiers have particular requirements for power supply, so i decided to go for separate power supplies. i soldered 3 wires to the MP3 shield’s jack plug and connected them directly to the volume potentiometer and amp as above.
- i use 2 Lithium ion cells type 18650, recovered from an old laptop battery. they have a nominal voltage of 3.7V, which is too high for the NodeMCUv1.0 via the Vin pin, and the onboard voltage regulator is NOT low-dropout (LDO), it takes around 1V off the input voltage. as far as i could tell, the ESP stopped working at around 2.5V (streaming stopped). my solution was to add a real LDO 3.3V voltage regulator like the MCP1826 (with 220uF on input and 0.1uF on output). the MP3 shield can be connected straight to the battery output via its 5V pin. of course i included a protection/charger PCB for each cell, with the microUSB ports accessible in the side panel.
- the amplifier works at voltages below 5V but with these 4ohm speakers it gives a lot of distortion under 4V, so i included a DC/DC booster PCB to bring the voltage up to 5.45V to get maximum amplification.
The tabbed box is laser cut out of 5mm thick soft wood. I hot glued it together, except for the back panel. I went for an inclined top panel to make it easier to see the (small) screen, and i got a bit bored of my usual rectangular boxes. I glued 4 support blocks to the side panels for the screws that hold the back panel in place.
Here is a closer look at the 2 Lithium cell protection/charger PCBs at the bottom on the right.
And below with the smaller VS1053 breakout board.
I made a second version for a friend, using the standard 1.8” TFT display, with minor modifications to the sketch (1 Feb 2017 version).