ESP32 I2S Internet Radio. Full Tutorial & explanation of I2S. For PCM5102 & MAX98357A I2S Decoders.

This is a full tutorial for connecting up the PCM5102 or MAX98357A I2S decoder DAC’s. With the demo’s being how to use them for Internet Radio. It also includes a explanation of what I2S is and how it functions. I will build on this in future episodes which will show how to play MP3’s from SD card and add in an amplifier for the PCM5102. Note I talk about 16bit audio throughout, I am aware that both the chips featured support 24 and 32 bit sound. I have simplified for simplicity! Code referred to in video is at the bottom of this page.

Time codes, if you want to skip to a relevant part without watching everything.

00:53 I2S Explanation
05:37 What is Internet Radio?
06:34 Differences between MAX98357 & PCM5102
8:05 PCM5102 wiring
11:01 MAX98357A wiring
14:40 Libraries
18:31 PCM5102 Demo
20:15 MAX98375A mono demo
21:44 MAX98357A – how to do stereo
23:50 Round up waffle (inc. pleas to subscribe and like etc. Usual Desperation…)

Affiliate links for the items shown: Clicking these costs you the same price but gives me a small commission, please consider supporting this channel by using them 🙂

PCM5102 : https://amzn.to/3grijdT
(This has two units, you may only need one of these)

MAX98357A : https://amzn.to/3eovdrd
(You will need two of these for stereo sound)

ESP32 : https://amzn.to/2Xzhc3k

Breadboards: https://amzn.to/2THZTvy

Speakers : https://amzn.to/3gA2sdh

The Demo Code

21 Comments

  1. This is an interesting project. Although I have built Internet radios around the ESP32 previously, I used the Espressif EDF software to upload to the ESP32. This project uses the Arduino IDE so it is a new way of doing things. I have several VS1053 boards lying around but have not tried the PCM5102 or MAX98357A boards. So I am tempted to have a try at constructing this project. Thanks for taking the time to publish it.

    • Thank you for taking the time to give this feedback. I’m going to be adding a touch screen and SD card soon to create a sort of “media centre” ,if that’s of any use.

    • I have a couple built on the VS1053, one in a stand alone mode using some cells recovered out of a macbook that I burned up with a cup of hot coffee, she is rather heavy but sounds great with a couple quality speakers and a small 3 watt amplifier. The other I have set up as a deck that can plug into any amplifier, both using displays and each with around 50 preset stations. I use a rotery encoder to change stations and for basic volumn as a sort of preamp for the little amp that drives the speakers. These are a lot more elaborate then the one built in this project, however the one in this project is very compact and can drive earphones with no problem, since I only want to listen to one station on it anyhow it works great for that. I would urge you to go for it. I have even had one I tied into a replica of a tabletop radio I got from my mother I simply hooked her in at the volumn control on the radio and she plays well, I have another little gizmo I built from a kit that does an FM transmitter, I have hooked one through that and played Christmas Music over it last Christmas for my wonderful wife who, at this very minute lay in hospital fighting a loosing battle with cancer.

  2. Well I have my 3rd wifi radio up and running, this one is going to fit in an old transistor radio case that I got from my niece when my eldest sister died of cancer last year (damn cancer!). Some of the stuff is sort of missing since the video is no longer there but I did manage to find out the missing connections one to ground the other to vcc to make her work, then I inserted my favorite online station, a replay of the old AFRTS Armed Forces Radio and Television Service in Vietnam back in the late 60’s early 70’s, playing tunes I listened to on that station back when I was a young soldier serving our great nation over in that quaint little nation filled with very unfriendly little natives who wanted to kill us all. s5.voscast.com:8700 will get you there.

      • Thanks. I am still playing with this setup, I may well leave her as is as I love that station, it takes be back to that time when I was so damn young and knew I would live for ever, even when in a war zone with folks trying to kill me from time to time. Well I was right I guess, as I made it home. I am considering just putting it all in a tiny box with an earphone jack and making a single station out of her..

        • I was told to keep working on simple projects like this by my doctor, who is treating my wonderful wife and I both. She, because she is on her death bed as cancer eats her body, me as I try to hold it together on the brink of loosing her after 51 wonderful years together. So it is, I have made another step, I soldered both boards onto a strip board and wired it all direct so there are no wires to fall off. Now I am considering which small amplifier I want to run it through so I can hook it to speakers, or to just leave it as a earphone radio.

        • I was told to keep working on simple projects like this by my doctor, who is treating my wonderful wife and I both. She, because she is on her death bed as cancer eats her body, me as I try to hold it together on the brink of loosing her after 51 wonderful years together. So it is, I have made another step, I soldered both boards onto a strip board and wired it all direct so there are no wires to fall off. Now I am considering which small amplifier I want to run it through so I can hook it to speakers, or to just leave it as a earphone radio.

  3. hi….
    i.m looking since 2 years for an stupid internetradio for 1 station….

    and now… i need 3 raspberry pi´s they work for a couple of weeks….than
    they die—–i switch the light in the bathroom on….pi starts in 40 sek.
    but if the powerconnection lost ( light off)….sometimes the software died on sd

    and now
    buy esp32…pcm 5102….look the video….soldering the esp…..flash the code….finish…starts in 3 seconds

    thnx a lot from germany

    Eberhard

  4. Hi,
    Can you tell me what version of #include “Audio.h” you are using as I always get the following error.

    fatal error: DMAChannel.h: No such file or directory #include “DMAChannel.h”

    Many thanks,
    Paul

  5. Hi
    I am trying use this on a esp 32 with board ESP Dev in Arduino IDE. Library ESP32-audioI2S-master. But it will not compile. I keep getting this error.

    C:\Users\Al\Documents\Arduino\libraries\ESP32-audioI2S-master\src\Audio.cpp: In constructor ‘Audio::Audio(uint8_t, uint8_t, uint8_t)’:

    C:\Users\Al\Documents\Arduino\libraries\ESP32-audioI2S-master\src\Audio.cpp:134:17: error: ‘class WiFiClientSecure’ has no member named ‘setInsecure’

    clientsecure.setInsecure(); // if that can’t be resolved update to ESP32 Arduino version 1.0.5-rc05 or higher

    can you see what I am doing wrong !

    Thanks Al

    • Have the same problem. Additional message suggests updating to higher board version. This is the development version of the board which you can also get from the espressif git files. I took the highest (r.6) which allowed the program to compile ok but then I got load failures on my dev-kit-c wroom-32 which I have not yet resolved.

      • Further runtime problem causing reboots – solved by providing separate power for PCM5102A. Network connection issue – replaced String ssid and password with const char *ssid and *password and now works.

        One question: is it normal for the output to slowly unscramble from random buzzing to a proper output over several seconds (even upto a minute)?

        • no, well mine doesn’t do that. I’m scratching my head as to what is wrong. Are there any unused connections left floating? If so check what they do and tie to positive or negative as required.

    • I just finished building it and its giving me the same error! Updated all libraries but no improvement. Board is ESP32 DEVKITV1.0. Your other sketches like PlayWavBetter works.

  6. Further to our recent exchanges… I did try the MAX98357 today. Very nice, although a bit of a bugger about that Gain pin floating. I miss the 9dB and that’s not doing my OCD any favours:) So wacked it up to 15db with a 100k and there’s no distortion. Maybe because I’m only powering it at about 3.7V. Anyway you may remember I had snap-crackle-pop sounds with the PCM5102 I used on my retro radio conversion https://www.hackster.io/pnjorge/retroradio-wifi-pilot-05b075 when playing short audio announcements. Well I had the same with this MAX chip too. After a bit of fiddling I found a workaround. I’m using the SD shutdown pin to only unmute the audio just after I start the mp3 and mute it again just before it finishes. I include the track lengths into a config json file I’m using… maybe there’s a more elegant way (by way of reading the mp3 file info data perhaps. Anyway, it’s done and we’re cooking on gas:)

    • Thanks for that, I don’t remember any snap-crackle-pop but must have been there and if present on both devices it sounds like an issue with either the library or ESP32 libraries for supporting I2S. I’ll bare this in mind if I come across it. (Currently writing my own library). The Gain pin thing is weird, the docs say it can be left floating, but if you do the gain jumps about all other the place. I like the 15 Gain option – Max Volume!

Comments are closed.