No video

ESP32 Audio Output with I2S DMA and the MAX98357A Class D Amplifier

Hey Everyone, we’ve spent a couple of videos getting audio into the ESP32.
I2S input - • ESP32 Audio Input Show...
ADC input - • ESP32 Audio Input Usin...
If you like ESP32 audio videos - I've got a complete set on this playlist: • ESP32 Audio
In this video, we’re now going to switch it up a bit and get audio out of the ESP32!
We're going to using the MAX98357A breakout board from Adafruit.
This is a class D amplifier with an I2S interface which is great because it means our audio signal stays digital all the way up to the speaker output.
You'll need a speaker to use the board with at least a 4ohm impedance and you can get up to 3W output.
Thanks for watching this video and if you found it useful please subscribe to the channel - there are more videos coming!
GitHub project is here: github.com/ato...
Componetns:
MAX98357 - amzn.to/3cg88Z5
TinyPico - amzn.to/3vVoONp
ESP32 Dev board: amzn.to/3gb6fyc
Speakers: amzn.to/3pjWFgq
---
Want to help support the channel? I'm accepting coffee on ko-fi.com/atom...

Пікірлер: 81

  • @atomic14
    @atomic143 жыл бұрын

    Interested in ESP32 Audio: kzread.info/head/PL5vDt5AALlRfGVUv2x7riDMIOX34udtKD Looking for all my ESP32 projects: kzread.info/head/PL5vDt5AALlRdN2KyL30l8j7kLCxhDUrNw

  • @Kai-Made

    @Kai-Made

    2 жыл бұрын

    I am curious how the pinout and wiring would be affected if I use the Firebeetle esp32 from DFRobot? The firebeetle has a rather distinct series of pins exposed and while it supports i2s I am not sure where to connect this. Googling ended me up finding this...so I am gonna poke it and see what happens...

  • @atomic14

    @atomic14

    2 жыл бұрын

    @@Kai-Made In theory, you should be able to use any of the pins on the firebeetle as the ESP32 is pretty flexible when it comes to GPIO pins and will route the peripherals to whatever pins you tell it to use.

  • @Kai-Made

    @Kai-Made

    2 жыл бұрын

    @@atomic14 you are correct. A little trial and error. Using the pre-designed library I was concerned it was pointing to certain pins and I just wanted to make sure my MC had them. I figured it out. The max98357 amp module is not very loud though, and I have done the resistor pull to make it 15dB, still not noticeably loud. I was hoping to use the combo to sound an alarm and have a device speak to the user... like "buzz buzz do something xyz". But I am floating around 20dB, might have to get a larger amp...not sure yet. more testing required.

  • @atomic14

    @atomic14

    2 жыл бұрын

    @@Kai-Made That's interesting, I've always found it too loud! How are you powering it? You should connect it directly to the 5v power. Also, by default, it plays (right+left)/2. You can either set it up to only plat the left or right channel or output both left and right. What kind of speaker are you using - that can make a big difference.

  • @Kai-Made

    @Kai-Made

    2 жыл бұрын

    @@atomic14 2.5 inch 4ohm speaker from bluetooth thing I cabbaged. I was using 3.3V, I will try using 5V next chance I get. I will try it with the pulldown to boost to 15dB as well...and see how it goes. I just don't think I will be getting a useable audible alarm from this...was hoping to use it in the field on a project I am trying to sort out. We need a 80dB alarm and piezos just aren't doing it...because the encasement/box we put it in. It would have to be external, and all the "waterproof" piezos we have sources are terrible, but the water proof speakers we have found seem to work well and that is why I was testing...

  • @balintarszenovits2430
    @balintarszenovits24302 жыл бұрын

    Thank you for your videos, I am new into electronics, and I learned a lot by them! :) I am working on a project, which uses the MAX98357A amplifier with an 8 ohm 1.5W speaker for now, and I have encountered a weird issue. Hardware: Nodemcu 32S, MAX98357A, 8ohm 1.5W speaker, which I want to exchange to a 4ohm 3W one. The power supply is a 5/3.3V breadboard power supply at the moment. I want to feed 5 Volts for both the MAX98357A, and for the ESP32. I connected the power source positive side to the 5V pin of the ESP32, and to the VIN pin of the MAX98357A. Both the groundings of the ESP32 and MAX98357A meet in a common star shape before going back to the negative side of the power source. When I powered the system, the speaker was completely silent almost, I heard some extremely quiet cracking from it. I tried to check the speaker by a multimeter, if does it receive any Voltage. When I connected the negative needle to the negative side of the speaker, the speaker starting giving sound, but a very cracky distorted one. After I connected to positive needle of the multimeter too, the sound became clear. If I remove the multimeter, no sound again. Then I pulled out the grounding of the MAX98357A completely, and it started giving the cracky sound again. In the end, I tried connecting the gain pin to a GND pin on the ESP32, then it gave proper sound. The same effect happens with both the 3V3 and GND pin of the ESP32. Connecting the GAIN into the star shaped grounding wires of the ESP32 and MAX98357A, no sound again. Could you help me please, what am I doing wrong? What is the issue with my 5V configuration? Why does the star shaped grounding solution not work, and why did it start working when I connect the GAIN pin to the 3V3 or GND pin of the ESP32?

  • @LongWayToCome
    @LongWayToCome3 жыл бұрын

    Just amazing. Thanks you a lot

  • @GilgaFrank
    @GilgaFrank3 жыл бұрын

    Many thanks for this video series! The ESP32 is a great platform for I2S audio, I've abandoned the STM32 and build a Linux box to take advantage of PlatformIO.

  • @atomic14

    @atomic14

    3 жыл бұрын

    PlatformIO is great - I struggle to see how people use the Arduino IDE for anything more than one file.

  • @GilgaFrank

    @GilgaFrank

    3 жыл бұрын

    @@atomic14 I would recommend the ESP-Prog JTAG debugger as well, it's great to be able to step through code. Andreas Speiss has a video on it.

  • @atomic14

    @atomic14

    3 жыл бұрын

    I’ll have to have a look at that. Being able to debug on device would be amazing.

  • @imignap
    @imignap9 ай бұрын

    Thought I would add this, BUT for the ESP32S3 i2sconfig I had to add/set the .left_align = true to get the serial data to most significant byte first or the audio was complete garbage. Only found this by creating a generated count up int16_t buffer and outputting thru i2s_write and using the saleae logic analyzer to see this was the issue.

  • @chrisgallagher85
    @chrisgallagher85 Жыл бұрын

    Great video - and thanks you good sir

  • @tryssss
    @tryssss3 жыл бұрын

    on my MAX I2s amp, i need to tied "gain" to the ground for this work !

  • @atomic14

    @atomic14

    3 жыл бұрын

    Interesting - I was testing mine last night and it works without the gain connected - though I am wondering if should be connected - the docs are not clear.

  • @tryssss

    @tryssss

    3 жыл бұрын

    @@atomic14 After i try to let it open....and it works too with higher gain.

  • @mrcalomx
    @mrcalomx2 жыл бұрын

    In the video you mention that you put the 100k resistor connected to the GDN to get the maximum gain but in the image it is connected to the VIN. What is correct? Thanks

  • @axramar1992
    @axramar19927 ай бұрын

    Hi sir ,How to upload multiple wav/amr/mp3 files to external 8mb Winbond flash memory and use Esp32 as an audio player?

  • @Clebrw
    @Clebrw Жыл бұрын

    Hello, great video. I would like to know if it is possible to put an amplifier at the output of the i2s max98357 to amplify even more?

  • @noweare1

    @noweare1

    17 күн бұрын

    I think he said you could not use it as a pre-amp.

  • @itdecoder2018
    @itdecoder20183 ай бұрын

    Can we use LM386 or PAM8403 Audio Amplifier instead of MAX98357A?

  • @alexandrepiel
    @alexandrepiel Жыл бұрын

    @atomic14 Thx for this nice video. How can we know which pin are working for I2S? Is it also working on ESP32C3? What would be the pins for the Seeed Studio XIAO ESP32C3?

  • @machinelearning3917
    @machinelearning39172 жыл бұрын

    Thank you for making this type videos!!! They are very cool and useful!! Are this notebooks and libraries still valid for microspeech keyword spotting for esp32 or have they al ready been deprecated? I am tryig different ways, but Tensorflow moves too fast and there is no much support. Thank you very much! Best regards!

  • @MihailNikolayevich
    @MihailNikolayevich2 жыл бұрын

    Thank you for your hard work. Can you tell me if it is possible to control the playback of files in your "i2s_output" library? For example play 001.wav, then stop it close and play 002.wav.... Like a playlist.

  • @zoomingh
    @zoomingh3 жыл бұрын

    I use ( gr- sakura full )to catch analog voice & get digital then analog to loudspeaker. Can you give me like that by esp or any arduino board? Plz Thanks You are great

  • @MrAsteliks007
    @MrAsteliks0073 жыл бұрын

    This may sound like a strange question but is it possible for the ESP32 to collect and play audio over Wi-Fi like in an intercom? Would it be possible to add a camera to this intercom? And of course could you try making this project?

  • @atomic14

    @atomic14

    3 жыл бұрын

    Definitely possible - the only problem with a camera is that most camera boards don't leave many pins spare so it can be tricky to add anything extra. But it certainly feels possible to do the whole thing. Even better if you could add a screen as well! I'll need to look at my ESP-CAM board again and see how many pins are spare.

  • @MatteoDelChiaroWulpi

    @MatteoDelChiaroWulpi

    3 жыл бұрын

    @@atomic14 I'd love to make an intercom! And with me, tons of people trying to do an intercom or a smart doorbell

  • @ijustwanttogosailing8248

    @ijustwanttogosailing8248

    3 жыл бұрын

    @@MatteoDelChiaroWulpi Hey!! I'm also looking at making an intercom - with a record function.

  • @andrewjefferies8391
    @andrewjefferies83912 жыл бұрын

    Do you have an example of using the Arduino Nano RP2040 connect as a USB Microphone ? I'm looking for Arduino IDE code to test/ listen to the mic audio quality.

  • @EszHuzky
    @EszHuzky Жыл бұрын

    Hey, Thanks for the video. I am trying to stop the ESP32 from playing the sample file in a loop, but I cannot find this point it in the code. Is the a while condition that I have to remove?

  • @amir.hsekandarpour3363
    @amir.hsekandarpour33632 жыл бұрын

    hi it's very good. I have a question.. is it possible to send data of music by wifi connection? like bluetooth audio module but i want do it by wifi. thanks for answering. I use wemos r1 d1.

  • @G-Code_official
    @G-Code_official Жыл бұрын

    can we not play a wav file coded as hex file through I2S max98357A. I tried using Xtronicals example and it worked without I2S but was very noisy and would like to do the same using I2S . The problem is I am not an embedded systems developer I am able to manage but do not have in depth knowledge in this regard can you please guide me?

  • @zachtos2
    @zachtos2 Жыл бұрын

    Is there a difference in audio quality if you used an audio codec like SGTL5000? or is the quality all depend on the ESP32 ability to keep up?

  • @stephanhans4804
    @stephanhans4804 Жыл бұрын

    Hello atomic14, I like your videos about the ESP32 and it's audio capabilities. I'm trying to build an internet radio with two ESP32. Why two?: because with an ESP32 (due to Phil Schatzmann) you can only use either wifi or bluetooth (not both at the same time). But I'm planning to use a bluetooth speaker with the internet radio, just because the sound of my BT-speaker is much better than the squeeky 3W at the max98357. So I need both: wifi and bluetooth. Now I'm looking for an example that uses the I2S of an ESP32 as input and parses the audio data to a bluetooth speaker. Have you ever tried such a thing (ESP32 Audio Input with I2S DMA and A2DP output)?

  • @kramkhirinroddara5324
    @kramkhirinroddara532410 ай бұрын

    Hi, Do you have the solution for playing sound from internal flash ( .hex file) by using esp32 + I2S MAX98357?

  • @CamoPeng
    @CamoPeng5 ай бұрын

    Sorry for the noob question - but why use DMA?

  • @sebydocky5080
    @sebydocky50803 жыл бұрын

    Hi, I am just a new subscriber of your channel.... Your work is just amazing... Just a basic question : Is the method presented here is the best to play sound files on ESP32 in term of quality (rather than using the builtin DAC ?). Kind regards

  • @atomic14

    @atomic14

    3 жыл бұрын

    The built-in DAC is a bit noisy but works ok. Here's my video on outputting using the DAC: kzread.info/dash/bejne/npt415pxiZeXYdI.html and another one on outputting with I2S directly: kzread.info/dash/bejne/c6hssqaKY8qddrQ.html - personally I think using I2S gives better quality - the built-in DAC is pretty noisy and doesn't have good linearity. But it's great for directly driving things like headphones.

  • @sebydocky5080

    @sebydocky5080

    3 жыл бұрын

    @@atomic14 Thanks for your fast answer. I ordered the max98357A w/ 3W 4ohm speaker. I am planning to use your I2S integration coupled with a K210+ESP32 board to do a 'cat detector" for garden. In the sens to avoid them to damage fresh ground.... by playing a dedicaced repulsive sound (changing randomely according to a special portfolio)

  • @atomic14

    @atomic14

    3 жыл бұрын

    @@sebydocky5080 oooh nice. One of my friends built a cat squirter and trained it to recognise his cats and squirt any other cat: robdobson.com/2017/08/machine-learning-the-good-the-bad-and-the-ugly/

  • @sebydocky5080

    @sebydocky5080

    3 жыл бұрын

    @@atomic14 Haha nice project as well ... Well ML is my party, so I am not afraid about that ....:) Thanks for your answers in anycase. I am planning to plug everything into Home Assistant I like to use ESPhome in general... but actually no support of I2S (yet)...

  • @JLNweb
    @JLNweb Жыл бұрын

    Hello, Great and big thank you for your work. I just tried, it works, but I couldn't find how to stop a piece of music in progress... It plays in a loop, but I would like to put several pieces of music in a row, but how to stop the one in progress, thank you.

  • @EszHuzky

    @EszHuzky

    Жыл бұрын

    @JLNweb I have the same issue. Let me know, when you found a solution for it, please!

  • @JLNweb

    @JLNweb

    Жыл бұрын

    @@EszHuzky Hello, I use the library "Audio.h" instantiation "Audio audio;" and there are commands such as: - "audio.connecttoFS(SPIFFS, MyFile.c_str());" - "audio.connecttohost(URL.c_str());" - "audio.stopSong();" - "audio.isRunning()" etc. Easy to use with that!

  • @TechInventorAman
    @TechInventorAman3 жыл бұрын

    Do you think that the sound quality of this is just amazing or do you think there could have been a better solution ?

  • @rhalfik

    @rhalfik

    3 жыл бұрын

    SSm3582 is better. MAx is clean unless you overdeive it off course, which is easy to do with so little power.

  • @HX2003
    @HX20033 жыл бұрын

    What do you think of the audio quality? On another note, I can't drive more powerful speakers with this so I'm currently considering the TAS5825m which is also an I2S amp, hopefully that will work.

  • @atomic14

    @atomic14

    3 жыл бұрын

    To be honest - hard to tell on the audio quality front, I was driving it at full power without a proper speaker enclosure and from the same USB power supply as the ESP32, so probably not ideal conditions. Looking at the datasheet for the TAS5825m it should work. Sounds like you are working on an interesting project!

  • @hfe1833
    @hfe18333 жыл бұрын

    Awesome, can you make video similar to this but producing engine sound for rc car

  • @atomic14

    @atomic14

    3 жыл бұрын

    There's an interesting project called Faust - faust.grame.fr/ I will do a video on it soon.

  • @hfe1833

    @hfe1833

    3 жыл бұрын

    @@atomic14 thanks for info

  • @mauricecraft890
    @mauricecraft8902 жыл бұрын

    Is it possible to have a SPH0645 mic input with the MAX98357 amplifier output to a headphone using the ESP32?

  • @atomic14

    @atomic14

    2 жыл бұрын

    Yes, you can have one I2S peripheral running input and another one running output.

  • @AminShahsavar
    @AminShahsavar3 жыл бұрын

    Good videos - thank you! I'm wondering if it's possible to stream incoming bluetooth audio (e.g. sent from Phone) and have the ESP32 output it to a stereo system (having it's own amplifier, I presume) using your method?

  • @atomic14

    @atomic14

    3 жыл бұрын

    Looks like Espressif have you covered: github.com/espressif/esp-idf/tree/master/examples/bluetooth/bluedroid/classic_bt/a2dp_sink You'll need to use the idf to build their example (or pull it apart) - I might try and do a video on the subject.

  • @AminShahsavar

    @AminShahsavar

    3 жыл бұрын

    @@atomic14 would be great to have a video on it! :) Just to clarify: I am not talking about web radio streaming - since I've seen some examples on that before. What I haven't found as of a month or two ago is actual audio streaming from one BT player (e.g. phone playing Spotify) to the ESP, which then outputs to a board with a 3.5mm jack or similar, that would connect to a speaker system.

  • @gunnarthielebein5982

    @gunnarthielebein5982

    3 жыл бұрын

    @@AminShahsavar please see the examples provided by the ThingPulse team for their Icon64 product. docs.thingpulse.com/guides/icon64-esp32-rgb-led-audio/

  • @AminShahsavar

    @AminShahsavar

    3 жыл бұрын

    @@gunnarthielebein5982 Thank you Gunnar, looks very good!

  • @akshayviruss
    @akshayviruss3 жыл бұрын

    Hi there, am new to electronics and am actually trying to build a portable speaker with a class D amplifier. I found a lot of bluetooth connectivity options but streaming music over wifi is extremely limited. I am on a tight budget and was wondering if this module can somehow be used to receive music from a phone or pc and supply it to the amplifier like a much costlier WA31 Up2Stream wifi audio receiver

  • @atomic14

    @atomic14

    3 жыл бұрын

    Hi Akshay - it's definitely possible - I don't have any code to show it, but you can write code on the ESP32 that listens for data on a TCP socket and you should be able to just send raw samples from your machine to it and then play it on the ESP32. Let me know if you find any good examples on your search.

  • @akshayviruss

    @akshayviruss

    3 жыл бұрын

    @@atomic14 like I said, am new to all of this and other than knowing it's somehow possible, everything else just few right over my head 😅

  • @user-st8bb2gs9e
    @user-st8bb2gs9e2 жыл бұрын

    Good video but where's the code and how to use the code ?

  • @TronDiscSeller
    @TronDiscSeller3 жыл бұрын

    Thanks for the code and stuff, really useful. But I am facing this distortion while playing wav files, tried from SPIFF and WavData.h, but the same distortion exists, Please help me. I am using the same circuit

  • @atomic14

    @atomic14

    3 жыл бұрын

    What kind of distortion are you seeing? If you can upload a recording of it we can have a listen and see if it's something that can be fixed.

  • @TronDiscSeller

    @TronDiscSeller

    3 жыл бұрын

    @@atomic14 Thanks for the reply, I really need to finish this project. If we can talk over a video call or something, that would be really helpful. I am more than happy to pay for your time

  • @atomic14

    @atomic14

    3 жыл бұрын

    @@TronDiscSeller You can email me from the Channel -> About screen.

  • @TronDiscSeller

    @TronDiscSeller

    3 жыл бұрын

    @@atomic14 Thank you sir, I have emailed you

  • @AkashJadhavIT
    @AkashJadhavIT3 жыл бұрын

    great tutorial, but before starting I have one question, in My project I need to connect 1. 10 Small LED RGB White 5V (Planning to use PCA9685) 2. 2 DC motors 6v or 12v (Planning to use L298N) 3. 4 Stepper motor SG90 9gm ((Planning to use 2nd PCA9685) 4. Control over WIFI/Bluetooth, by Android app(which I can develop) 5. 1 Speaker with MicoSD mp3 audio in it (MAX98357A/SD car reader) Can I use ESP32 for these all or do I have to buy other chips as well ?

  • @atomic14

    @atomic14

    3 жыл бұрын

    I think you should be good - the ESP32 does I2C so can drive the PCA9685 no problem. Does the PCA9685 have a stepper motor driver?

  • @AkashJadhavIT

    @AkashJadhavIT

    3 жыл бұрын

    @@atomic14 yes PCA9685 is pwm servo controller has its own ic and power input, also they can be daisy chained with ewch other upto 96 boards . With only 3 input pins from esp32. I am worried about other devicesi will ve connecting and whether esp32 has enough pins for other output I will be connecting

  • @atomic14

    @atomic14

    3 жыл бұрын

    @@AkashJadhavIT There's a really good video here that discusses which pins can be used - along with a handy spreadsheet - kzread.info/dash/bejne/fo1hk6aBhNu4cc4.html

  • @aarriikknn33ll
    @aarriikknn33ll3 жыл бұрын

    Can this code be used in Arduino ide? Thanks! (Never used anything else than Arduino ide)

  • @atomic14

    @atomic14

    3 жыл бұрын

    Yes you can, it's just a bit of a pain to manage multiple files in the Arduino IDE.

  • @aarriikknn33ll

    @aarriikknn33ll

    3 жыл бұрын

    @@atomic14 okay thanks, tried it out and it compiled. Thanks for your help in the diy community ❤️

  • @PTyakiniku

    @PTyakiniku

    2 жыл бұрын

    @@aarriikknn33ll how you manage multiple files? i am new in Arduino IDE. I will be really appreciate as it is my project in college

  • @aarriikknn33ll

    @aarriikknn33ll

    2 жыл бұрын

    @@PTyakiniku Just open it'll work

  • @bamblaster2564
    @bamblaster25642 ай бұрын

    But....why?

  • @edgull_tlt
    @edgull_tlt2 жыл бұрын

    Спасибо