DIY Digital Audio Music Player with I2S and ESP32

Building a DIY Digital Audio Music Player with I2S and ESP32 


ESP32 audio player

Suppose you found a microcontroller board like this ESP32 and you just recorded an amazing sound in a clip that sounds like: “Stay Art!” Now you want to play this sound with help of  ESP32, so what do you do? Yes, the installation side is straightforward by simply adding a micro SD card relaxation board to ESP32 using its SPI interface. Thanks to this instant data line, all pieces of The original audio file can be read by ESP32 without losing the audio quality. That means we still have a real 16-bit correction that explains how many steps our first analog audio signal was converted by digits. As a sixth rule, when we get a lot of fragments, we get very close to the original analog signal. Also, a sample rate of 44.1 kHz is kept constant indicating how often the analog signal voltage is normally to get samples; in this case almost every 22.7uS. And the higher the sample rate, the closer we get to a real analog signal but let me tell you that 16 and 44.1kHz pieces sound very good. So the installation side is a member done with the output side, we can use DAC aka Digital internal Analog Converter for ESP32 to create an analog audio signal. But sadly it only comes with a solution of 8 pieces that can work as a bottle with our audio quality. Instead, I wanted to use this MAX98357A amplifier breakout board that uses I2S to connect.
DIY Digital Audio Music Player with I2S and ESP32

Now, we will find out what I2S is and why it is so useful to use it, and along the way, it will not learn not only to work with the I2S magnification board but also the I2S microphone board. Let's get started! make an I2S audio player.


I2S audio player

First of all, I want to say that we are not compelled to use the I2S DAC Amplifier output board. We can also build a 16 bit R-2R DAC but that would require 16 ESP32 and therefore it is not at all usable. Or we can just get a 16 bit DAC IC that we can connect to ESP32 using for example I2C. But also if we are already using the communication protocol, why not use the existing I2S designed specifically for audio applications. I2S stands for Inter-IC Sound and is an electric bus interface used to visually connect digital audio devices. It communicates with PCM audio data representing Pulse-Code Modulation and that is a digital representation of digital-analog sample signals used by our .wav audio file. It basically keeps the binary values ​​of all analog voltage sample values ​​in it and that is exactly what we want to send you via I2S.With the first example that works, however. let's start with the soundboard but instead with this INMP441 Microphone breakout board. With it, the concept of I2S will be easier to understand as we only have to read data through a microphone while we will have to learn data and send data with a micro sd card and amplifier board. However, the microphone has 6 of its 2 power anchors, 3 I2S connectors, and one type of bonus to choose whether the microphone removes its data from the left or right channel. the microphone has 6 of its 2 power anchors, 3 I2S connectors, and one type of bonus to choose whether the microphone removes its data from the left or right channel. the microphone has 6 of its 2 power anchors, 3 I2S connectors, and one type of bonus to choose whether the microphone removes its data from the left or right channel.
DIY Digital Audio Music Player with I2S and ESP32

The three connectors required for I2S are called word select, serial clock, and serial data. In the case of a soundboard later it has slightly different words but still means the same thing. So as a preliminary experiment I sold the cables to 5 key pins and proceeded to look at the ESP32 pinout diagram to find out where to connect the I2S pins and was surprised that no specific pins were mentioned. As it turns out the ESP32 comes with two I2Speripherals but you can choose the pins yourself. So I decided to install 15, 2, and 4 pins according to this wiring diagram and after connecting the Micro USB cable, I quickly looked at the ESP32 I2S configuration guide page. I simply copied the coded code so that I not only set the resolution to 16 bits and the sample rate to 44.1kHz but also started and started the I2S connection.The only thing I had to add was a few lines to extract the data obtained using a serial monitor. And after loading the code and opening the serial monitor we see that by whistling on the microphone or touching it, the serial or better yet the serial builder seems to respond appropriately, surprisingly. That means everything is working fine and it was time to look at the three I2S pins on the oscilloscope. First, we see that the word select lines always change between low and low. The reason is that this bus transmits stereo sound so the low level of the word select line indicates the left channel and the high country represents the right channel. By the way in this example, we only found data on the left channel because the offline L / R pins explain that. After that, we got a Serial Clock made by ESP32 where its Serial Data got a sample.In this way, the audio data fragments sent by the microphone can be read by ESP32 which is an excellent interface for the communication connector you should know from my SPI, I2C,
DIY Digital Audio Music Player with I2S and ESP32

But what is special about this connection is the frequency of the clock signal. It is really flexible and depends on the sample size, low resolution, and whether you want to transfer mono or stereo. In our microphone model, we have selected 44.1kHzith 16 bits and stereo which means we have to multiply 44.1kHz 16 by 2 equal to 1.411MHzwhich and the frequency we measure. Now, at this point, we can modify the microphone data we have received to make an example to make a sound change or a good scientific sound meter but that was not the purpose of this video. Instead, I sold the wires to my I2S amplifier board and Micro SD cardboard and connected the whole to the ESP32 according to the wiring drawing chart. At this point even though coding was not only part of I2S coding but also SPI which is why instead of writing all my code which could take months, I decided to use the ESP8266 library available and other coding code from Spark is fun. But in the code, we can still see that part of I2S is straightforward to use. And after coding, connecting the speaker, and inserting a Micro SD card and audio file, we can hear this. So ESP32 audio player.


“StayCreative!” It's scary! And just like that, you are now familiar with the basics of I2S, and in all, I can say that it is very easy to use and it helps to use the communication interface when it comes to receiving and sending digital audio. And if you are interested in the most advanced video on this topic then I highly recommend you check out the video units by creating an ESP32 audio player or ESP32 ULP audio driver. But still, I hope you enjoyed this video and learned something new. And I’ll see you next time. It's DIY Digital Audio Music Player with I2S and ESP32.


  Download-  ESP32.....Code 
    Download Data sheet





Our Vlog

Technology Vlog: Bengal Tick-Tech 

Motivational story vlog: Bengal Motivational story 


Food & Cooking Vlog: Bengal Fresh Food




أحدث أقدم