ESP32 Internet Radio

Once you understand VS1053 codec processor , with just 15 lines of code you can build up your Internet radio running on your WIFI internet connection.
ESP32 Internet Radio
The cheap MP3 VS1053 codec processor that has come from aliexpress.com is told to be capable of decoding a variety of music formats, including Ogg Vorbis/MP3/AAC/WMA/MIDI audio, was lying on the table for quite sometime. VS1053 is also capable of recording in Ogg Vobis file but all the guidance that are available on Internet are either for proprietary boards or for ESP32-IDF which I hate to try due to excessive coding. A code more than 20 lines is enough to drive me out 100 miles !
The Idea:
The Internet radio on ESP32 was an interesting project but due to lack of understanding of the board or the codec format I was so far unable to tweak the board until one day I got the idea that if I can deliver a chunk of streaming data in exact quantity of 32 byte to the board in the form of stream, it will just keep on playing.
That means the ESP32 is to connect the streaming site at the fixed port and then receive the streaming data in an exact chunk of 32 byte at a time. On the other hand the board will keep on processing the data like an inflow / outflow machine and the stream will continue to play.
The main code is hardly 15 lines long !
Construction: The open source ESP32 VS1053 library is used , You can find a few examples included in the library. For changing stations I’ve used a GPIO (D13 ) pin as a push-to-on-switch to soft Reset the VS1053 board to tune in to the next station. For bounce free switching operation I’ve kicked in a boolean operator to become ‘false’ & ‘true’ alternatively to prevent multiple switching on single press of button.
VS1053 is a 5Volt device but you can easily rig it to operate on 3.3 volt as well. That way on ESP32 radio you will have only one supply voltage – 3.3volt, which can be fed from one LiPo battery. There are two voltage regulators [AM1117] on the VS1053 board – 3.3 volt and 2.5 volt. With a digital multi meter first find out which one is for what and then connect a jump wire from 3.3 volt to the input of 2.5 volt regulator and make that lead as 3.3 volt input to the board [see pic].
VS1053 wiring: Keep the connecting wires as small as possible. Longer, lengthy and overlapping wires may produce humming noise to the sound output which I’ve experienced with these kinds of boards. The sound out is stereophonic and amplified enough to power small speakers or ear phone but for running bigger speakers you may have to add amplifiers / ampli boxes.
Construction hurdle: A Li-Ion / Li-Po or a Li-Ion when fully charged can ramp up voltage to 4 which will not damage the ESP32 but you may loose the VS1053 board and then wait for another 40 days to arrive from aliexpress.com. Therefore, I recommend you to use a low power, low loss HT7333-1 3 pin voltage regulator which has very low drop out voltage and very low quiescent current loss. But the only problem is HT7111-1 is a tiny surface mount device. No problem , call me and keep my fees ready ,I will solder it for you !
Schematic with ( OLED – Optional) :
The rigged up 3.3 volt is connected to the output of HT7333-1 which is also the input power for ESP32.
Prototype:
[The red circled connection will go to the push-to-on switch - it’s a makeshift push-to-on switch now]
Testing: For connecting to the WiFi system ,replace the SSID & Password to the beginning of the code and then upload in the normal Arduino way. Once uploaded the ESP32 will first say ‘Hello’ to indicate that the VS1053 is up and ready. It will then wait for couple of seconds to get connected [ Keep an watch on the Serial output ] of the computer. Once on the Internet it will then tune to the station in host[6] and then the beautiful streaming voice of Beatles will start pouring in. Press the switch once [connected to D13] and the next station will be tuned. I’ve found quite a few good stations listed in the comment portions which you would love to listen right away! The char *sname[7] variable is optional. You can have your choice names against each radio stations which I’ve set for myself. Additional station names can be added in the host, path and port arrays.
ESP32 Radio with OLED (Optional) : The only problem left is – no display to know which station is playing! An I2C generic display is all that is required now to make it all complete now. But the problem is that the heavy weight Adafruit SSD1306 along with Adafruit_GFX library if used will make the sound jarring. Therefore, I’ve used a light weight SSD1306 library esp8266-oled-ssd1306-master which is particularly made for ESP8266 to run SSD1306 generic OLED displays. With this library the I2C display works just fine without any effect on the sound output. However, the OLED is optional – The radio works just fine without it !
BOM:
ESP32 $7.5
OLED 64*128 - $3
VS1053 codec shield - $6
HT-7333-1 -$1
8 Ohm speakers (0.3 watt) extra.
Softwares: I’ve added two sketches – bare_minimum_radio_player.ino & simple_esp32_radio_mod3.ino The first one is just a few lines of code to get a 32 byte data from a streaming site and then play. The 2nd one is an elaborate sketch to run the radio along with an OLED display and a push-to-on switch to change the station. Each sketch is accompanied with a small ‘helloMP3.h’ file which is actually code for a small music or a sound greeting. Compile the sketch along with this file.
The necessary arduino libraries are also added in the software bundle.
Bera S
Vindhyanagar
The cheap MP3 VS1053 codec processor that has come from aliexpress.com is told to be capable of decoding a variety of music formats, including Ogg Vorbis/MP3/AAC/WMA/MIDI audio, was lying on the table for quite sometime. VS1053 is also capable of recording in Ogg Vobis file but all the guidance that are available on Internet are either for proprietary boards or for ESP32-IDF which I hate to try due to excessive coding. A code more than 20 lines is enough to drive me out 100 miles !
The Idea:
The Internet radio on ESP32 was an interesting project but due to lack of understanding of the board or the codec format I was so far unable to tweak the board until one day I got the idea that if I can deliver a chunk of streaming data in exact quantity of 32 byte to the board in the form of stream, it will just keep on playing.
That means the ESP32 is to connect the streaming site at the fixed port and then receive the streaming data in an exact chunk of 32 byte at a time. On the other hand the board will keep on processing the data like an inflow / outflow machine and the stream will continue to play.
The main code is hardly 15 lines long !
Construction: The open source ESP32 VS1053 library is used , You can find a few examples included in the library. For changing stations I’ve used a GPIO (D13 ) pin as a push-to-on-switch to soft Reset the VS1053 board to tune in to the next station. For bounce free switching operation I’ve kicked in a boolean operator to become ‘false’ & ‘true’ alternatively to prevent multiple switching on single press of button.
VS1053 is a 5Volt device but you can easily rig it to operate on 3.3 volt as well. That way on ESP32 radio you will have only one supply voltage – 3.3volt, which can be fed from one LiPo battery. There are two voltage regulators [AM1117] on the VS1053 board – 3.3 volt and 2.5 volt. With a digital multi meter first find out which one is for what and then connect a jump wire from 3.3 volt to the input of 2.5 volt regulator and make that lead as 3.3 volt input to the board [see pic].
VS1053 wiring: Keep the connecting wires as small as possible. Longer, lengthy and overlapping wires may produce humming noise to the sound output which I’ve experienced with these kinds of boards. The sound out is stereophonic and amplified enough to power small speakers or ear phone but for running bigger speakers you may have to add amplifiers / ampli boxes.
Construction hurdle: A Li-Ion / Li-Po or a Li-Ion when fully charged can ramp up voltage to 4 which will not damage the ESP32 but you may loose the VS1053 board and then wait for another 40 days to arrive from aliexpress.com. Therefore, I recommend you to use a low power, low loss HT7333-1 3 pin voltage regulator which has very low drop out voltage and very low quiescent current loss. But the only problem is HT7111-1 is a tiny surface mount device. No problem , call me and keep my fees ready ,I will solder it for you !
Schematic with ( OLED – Optional) :
The rigged up 3.3 volt is connected to the output of HT7333-1 which is also the input power for ESP32.
Prototype:
[The red circled connection will go to the push-to-on switch - it’s a makeshift push-to-on switch now]
Testing: For connecting to the WiFi system ,replace the SSID & Password to the beginning of the code and then upload in the normal Arduino way. Once uploaded the ESP32 will first say ‘Hello’ to indicate that the VS1053 is up and ready. It will then wait for couple of seconds to get connected [ Keep an watch on the Serial output ] of the computer. Once on the Internet it will then tune to the station in host[6] and then the beautiful streaming voice of Beatles will start pouring in. Press the switch once [connected to D13] and the next station will be tuned. I’ve found quite a few good stations listed in the comment portions which you would love to listen right away! The char *sname[7] variable is optional. You can have your choice names against each radio stations which I’ve set for myself. Additional station names can be added in the host, path and port arrays.
ESP32 Radio with OLED (Optional) : The only problem left is – no display to know which station is playing! An I2C generic display is all that is required now to make it all complete now. But the problem is that the heavy weight Adafruit SSD1306 along with Adafruit_GFX library if used will make the sound jarring. Therefore, I’ve used a light weight SSD1306 library esp8266-oled-ssd1306-master which is particularly made for ESP8266 to run SSD1306 generic OLED displays. With this library the I2C display works just fine without any effect on the sound output. However, the OLED is optional – The radio works just fine without it !
BOM:
ESP32 $7.5
OLED 64*128 - $3
VS1053 codec shield - $6
HT-7333-1 -$1
8 Ohm speakers (0.3 watt) extra.
Softwares: I’ve added two sketches – bare_minimum_radio_player.ino & simple_esp32_radio_mod3.ino The first one is just a few lines of code to get a 32 byte data from a streaming site and then play. The 2nd one is an elaborate sketch to run the radio along with an OLED display and a push-to-on switch to change the station. Each sketch is accompanied with a small ‘helloMP3.h’ file which is actually code for a small music or a sound greeting. Compile the sketch along with this file.
The necessary arduino libraries are also added in the software bundle.
Bera S
Vindhyanagar
Discussie (4 opmerking(en))
Jan H. Kila 4 jaar geleden
bera 6 jaar geleden
This is actually I've used to select a new WiFi hot spot in case the existing WiFi hotspot becomes unresponsive. The counter will replace the new wifi hotspot number and next time when it rebbots will straight way log onto that wifi.
You can arrange a series of WiFi hotspot Id & passeords so that if one does not work it will keep on changing for the next working one...
That's it.
Thanks.
Bera
solar 5 jaar geleden
Hello Bera, good to hear from you again. I remembered you were very bussy so I jumpt in to help efo. About your clock idea: My first internet radio is "hidden" and only the sound is heard in the halway. I am working on a smaller housing and operating from one cel Li battery. I will use an ESP with integrated display. This should be a radio to take with you around the house. A clock in here would be welcome so if you have some code ready, please publish.
Kind Regards, Hans
bera 5 jaar geleden
Thanks for taking so much interest in this project.
...
How about taking this project to a newer height by
converting the ESP32 and the display into a world clock display.
Whenever, it tunes to a station, it also displays the Place & local time there...
It will get the clue from the station tuned or something else...
Besides, playing the station, it will also display the Place & local time etc...
We may have to use another arrays for " place" and "local time" ...
Thanks,
Bera
efo 5 jaar geleden
Solved!
The thing was to "cut" the ":" !
I understood that 8020 was the port.... but I didn't understood how to write it.
You helped me so much.
Really thank you Hans!
:)
solar 5 jaar geleden
Herewith a screenshot from my ESP32:
First line just confirms that the wifi connection succeeded. Than you see the the IP address which will be different in your case. Current counter is the station number which was used last time. In the four lowest lines you see what happens when you press the "change" button; the station number adds up and the name of the station is displayed.
The wifi connection works as I understood but are the new station numbers displayed?
I added a volume control so in line 4 you see "current volume level" which was used last time. Underneath you see the volume changing.
If everything works like here (apart from the volume control) that part is fine.
You tried to set some addresses.
In the sceenshot station url's you see on line 44 a typical example: 199.195.194.94 is the host address. This must be filled in between "..." behind host, line 51, the third station. All station separated by "," .
The :8109 in line 44 is the port number. forget the : and fill in the number behind port, line 57 at the third location. Alle seperated with , .
In line 44 /stream is the path name. Fill it in behind path. If a station has no path name just fill in the / .
In line 44 behind # is the station name. You can give any name you like because it is not used for navigation but only in the display and com screen.
Than another possible reason for not working.
The MP3 decoder can be equipped with either a VS1003 or VS1053. See the mark on the chip on your board. The VS1003 can only decode MP3 but many stations use different codings like AAC, WMA, Ogg Vorbis, etc. If you have a VS1003 you can only decode stations with mp3.
I hope this will help to get your radio working.
Kind Regards, Hans
station-urls.PNG (43kb)
efo 5 jaar geleden
I menaged to connect. I had to change the url (path , etcetera).
Now I'm trying without success to connect to radio with a streaming address like this:
tropicalisima.net:8020/stream/1/
who work on the pc but not with ESP32. I don't know how to divide it in host and path
Thank you Solar.
solar 5 jaar geleden
I also started with the program from Bera and modified a lot just for exercise.
If you change station with the pushbutton, do you see the resulting comments in the serial monitor?
Hans
efo 5 jaar geleden
Thank you for the great job!
I can't make it work. Excuse me if I'm not an experienced user. I'm used to program arduino, and this is my first experience with ESP32.
So...
I'm not connecting the Oled (I don't need it) and Im starting with your bare_minimum_radio_player.ino.
When I flash the chip by Arduino IDE it seems to work. Leaving connected the serial monitor on pc I can see that it return:
WiFi connected
Connected now
and the voice says "hello!" clearly!
But after it nothing happens! I tryed to manually change all over the 7 station to connect:
station_connect(1)
and checked it on my pc browser: at least 3 are streaming correctly.
Any suggestion?
In every case, thank you
solar 6 jaar geleden
It was fun to do and encouraged me to continue with other projects. A temperature control with thermocouple comes first and LoRa is #3 on the list. Maybe we have contact about that again.
Kind Regards, Hans
bera 6 jaar geleden
Thanks for your persistence.
In fact, some project / some work / sometimes some values , robs our entire attention so strongly and so convincingly that we get ourselves completely lost in it. Literally it becomes our destiny for that moments of time!
Finally the moment we get a handle of it [ in other words understands it or overcomes it ] we get ourselves out of it.
This project was also like that for me at the biginning and then when I got a start, built a model, I came out of it or move to the next project.
I thank you from my core of heart for persistently working on it and improving it further.
Thanks,
Bera
berasomnath@gmail.com
solar 6 jaar geleden
Thank you for your reaction.
Since I began with this project I have studied a lot in documents on internet and discussions on fora. That helped a lot and I am now able to understand the programm completely and even added new functions to it.
The first addition was to add a volume control. Two pushbuttons for increase resp. decrease the setting. To start with the right volume each time the radio is restarted I copied the "preference.putUInt" function and the related getUInt to save the value in EEPROM. So that is what your program does do with this commend: save the existing station number for use at restart.
Further I could rewrite a part in a more straight forward way and created functions for actions that are done more than once. Just call the function is than sufficient. One of the functions is to switch to the next station. This was useful because I added a kind of watch dog that will restart a station in case of too long no sound information and after too many restarts in a certain time switch to the next station. This watch dog works fine but the settings are somewhat dependent on the station behaviour so I am still thinking about a more robust solution. I also added a time out for the display. If nobody is watching the display can be off to save energy. A push on a button gives the display a new visable timeslot. I added a fourth button to light up the display and do nothing else. I added a program called "multy WiFi" which gives the possibility to give more than one accesspoint name and password. Because this takes edditional time I left the single accesspoint option also available. By commenting out you can choose between both. I just recieved a rotary encoder so the next thing is to replace the buttons by the encoder.
I'll try to upload the program as is now but when this does not succeed give me your e-mail and I can sent it direct.
Remark: The board you use for VS1053 is actually a board with the VS1003 chip on it. This chip can only decode MP3 and Midi. I now use a different board with a VS1053 on it and all other standards like AAC and WMA. Some stations use these formats.
Kind Regards, Hans
pafa 4 jaar geleden
I know that I am replying to an old post but I have only recently come across your radio sketch version 1.1. It has all the features that I need and I have successfully downloaded it to my esp32.
There seems to be a problem with it crashing occasionally.
It will not reload but seems to go into continous reboot.I have to erase the esp32 to get it to work again.I wonder if you have experienced this and if so is there a fix ?.Unfortunately I am a complete noob with regard to coding,this is my first project using esp32 and arduino ide I would be interested if you have an upgrade to version 1.1
Regards
Phil49
solar 4 jaar geleden
Welcome to the club and thanks that you contact me for help.
I have still some problems with stations that stop receiving and I have to restart to get music again. I tried to automate this by regurarly checking the availability of the station and when no response within a certain time to switch to the next station. Obviously I made mistakes so the switching happened many times per second. The WiFi could not follow this and the ESP 32 crashed. Result is, when starting the program, immediatly a reset will follow and a crash announcement with "panic" etc. pops up. This looks very much the same as you describe. I am not so experienced that I exactly know what happened but according internet/google the errorcode indicates some overflow into the program memory and that can only be undone by some other program. Because of other priorities I did not work on it further. Also because the ESP is not defect and it works fine for another program. If you know how to clear that memory area I am interested to hear.
I did work further on my version of the program and made some different versions for different situations. Therefore I changed numbering to differentiate between them. Herewith the today version of the basic design. I now see that version 1.1 has the automatic reconnect attempt so that could cause the problem. Version 011 is stable at that point. If you need some clarification about some functions, let me know. Be aware, I left many station information just to not get lost but I did not check them all so some may not work. There are various versions of the VS1053 decoder boards. Some with the older VS1003 chip on it. VS1003 does decode only a limited number of coding standards.
Note: I did not succeed in uploading the file. If you sent me an e-mail to hans.welschen@zonnet.nl I will sent it to you directly.
bera 6 jaar geleden
Thanks for taking interest in my project.
Here's few stations that I included in my sketch...
// Few Radio Stations
char *host[7] = {"streaming.shoutcast.com", "swr-swr1-bw.cast.addradio.de", "/swr/swr1/bw/mp3/64/stream.mp3", "airspectrum.cdnstream1.com", "skonto.ls.lv",
"icecast.omroep.nl", "beatles.purestream.net"
};
char *path[7] = {"/80sPlanet?lang=en-US", "/swr/swr1/bw/mp3/64/stream.mp3", "/1261_192", "/1604_128", "/mp3 ",
"/radio1-bb-mp3", "/beatles.mp3"
};
int port[7] = {80, 80, 8000, 8008, 8002, 80, 80};
...
And then look towards the end of setup() ...
station_connect(6);
Change the station number for other stations...
station_connect(4); is also a good station - skonto.ls.lv
Bera
Philippe Steelant 6 jaar geleden
please , how do i add another streaming station...beginner...nice project
solar 6 jaar geleden
My name is Hans. I use solar only as nickname because I have worked (and still do on low profile) in that field for 35 years now.
The issue with other radio stations is that you need to know the port number and most stations do not publish that. I noticed that they use all kind of numbers and not only the reserved ports for streaming. I found a website - http://fmstream.org/index.php?s=chill&cm=0 - where you can select on different criteria and get a list of many stations and many of them publish the portnumber as well. So I have my list complete and functioning. If there is no path, use only "/".
I did not notice any problem with activating a new station after pushing the button so the "player.softreset()" works fine. What I do not understand is the reason for counter, old_counter and new_ counter. Normally this is used to evaluate a change but in this case the number will be raised by one and can be used as "counter". The old_counter is only set in the setup stage and will remain the same for all other numbers except the one active at uploading time or after reset. the if statement old_counter != new_counter is not true and nothing happens. Moving this into the loop gives always the former station number and will be different all the time. So no new information for the loop. I will comment them out to see what happens. Can you explain what "preferences.putUInt("counter",new_counter); " is doing and where it comes from?
A more serious point is that the loop will stuck when a station is not answering and the button will be blocked. That I will try to solve by a time-out or something like that.
I added a volume control by adding a + and - button and a small loop comparable to the station forward loop to decrease or increase the volume. In my setup I use steps of 5 and go as low as 70. Lower is not usefull. Be aware that some inputs have weak pull-up resistors and the setting "input-pullup" does not work. You have to use an external resistor. (max 50k)
What I still have on my wishlist is to switch to mono. From the VS1053 document I can see there is a bit in a register for that but I do not now the corresponding command. Do you know that?
I'll keep you informed about the progress.
Hans
Philippe Steelant 6 jaar geleden
not much time for the moment , but i will check it out asap..thx
bera 6 jaar geleden
Thanks for taking interest in my project.
...
For changing station, I have inserted one softreset() command inside the loop.
That command should work and then only the next station gets selected.
Please see that softreset() is working properly.
---------------------------------------
if(old_counter != new_counter) {
player.softReset();
x=true;
station_connect(new_counter);
preferences.putUInt("counter",new_counter);
----------------------------------------
Rgds.
Bera
Philippe Steelant 6 jaar geleden
i do also have the same problem...about the selected stations , i have put Belgium stations in my list..
my email adres is : philippe.steelant@telenet.be...then we can communicate directly if you want...groetjes
solar 6 jaar geleden
To involve Bera also back to English.
I noticed some unexpected behaviour which I hope you could help me explain and solve.
1) Pushing the button for the next station works fine up to 3. Then pushing the button has no effect and after resetting, either the enable button or disconnecting the power, will help to reach the higher numbers. 5 > 6 > 0 works as expected most of the time. I am working on it by inserting print requests to see where the hangup is. No results yet.
2) Station 0 works fine as 5 and 6 but 1, 2 and 3 give no output. First I expected those stations not "in the air" but when puting the IP into the browser the stations are broadcasting. Reason why not via the ESP???
3) I wanted to insert another station and replaced the host from 1 by "mediaradioplayer.com" and the path from 1 by "/yr4/toronto1" . Putting the host IP in a browser gives the station website and adding the path to that IP gives music, but in the ESP it did not work. Expecting a problem with location 1 I repeated the procedure for location 0 but that also did not work. I assume the *sname is not relevant and only for the display.
So still some issues to find out and the more respect I got for Bera to get all this working. In my case I have to power from 5V anyway so I did not made the modification of the VS1053 and connected that to the 5 Volt and the display to the 3.3 from the ESP.
Kind Regards, Hans
Philippe Steelant 6 jaar geleden
i
solar 6 jaar geleden
I had to rearrange some files in Arduino_data and now everything works fine.
Thank you both for your help.
Hans
solar 6 jaar geleden
Thank you for your help.
Using the error comments comming from both boards I learned a usb driver was missing.
After installing, I got another comport and communication was possible. I first tried an example program, WiFiscan, which finally worked after using the boot button.
Compilation of the radio program still gives some errors: \VS1053-master\VS1053.cpp:11:26: fatal error: avr/pgmspace.h: No such file or directory.
Both files are available so I have to see what happened.
I'll let you know.
Hans
Philippe Steelant 6 jaar geleden
bera 6 jaar geleden
Thanks for taking interest in my project.
The board I use is - ESP32 Dev Module
Thanks.
Bera
solar 6 jaar geleden
I got troubles to get the ESP connected to the Arduino IDE. From your photo it looks like the same ESP as I purchased. Which board setting do you use and do you need to install a special driver?
Hans