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

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 มิ.ย. 2024
  • 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/atomic14/esp32_audio
    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/atomic14
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 80

  • @atomic14
    @atomic14  2 ปีที่แล้ว +2

    Interested in ESP32 Audio: th-cam.com/play/PL5vDt5AALlRfGVUv2x7riDMIOX34udtKD.html
    Looking for all my ESP32 projects: th-cam.com/play/PL5vDt5AALlRdN2KyL30l8j7kLCxhDUrNw.html

    • @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 ปีที่แล้ว +1

      @@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
    @balintarszenovits2430 2 ปีที่แล้ว

    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
    @LongWayToCome 3 ปีที่แล้ว +2

    Just amazing. Thanks you a lot

  • @chrisgallagher85
    @chrisgallagher85 ปีที่แล้ว

    Great video - and thanks you good sir

  • @GilgaFrank
    @GilgaFrank 3 ปีที่แล้ว

    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 ปีที่แล้ว +1

      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.

  • @machinelearning3917
    @machinelearning3917 2 ปีที่แล้ว

    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!

  • @Clebrw
    @Clebrw ปีที่แล้ว +2

    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?

  • @MihailNikolayevich
    @MihailNikolayevich 2 ปีที่แล้ว

    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.

  • @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?

  • @sebydocky5080
    @sebydocky5080 3 ปีที่แล้ว

    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: th-cam.com/video/lgDu88Y411o/w-d-xo.html and another one on outputting with I2S directly: th-cam.com/video/At8PDQ3g7FQ/w-d-xo.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 ปีที่แล้ว +1

      @@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)...

  • @imignap
    @imignap 7 หลายเดือนก่อน

    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.

  • @mrcalomx
    @mrcalomx 2 ปีที่แล้ว +1

    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

  • @tryssss
    @tryssss 3 ปีที่แล้ว +1

    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.

  • @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)?

  • @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?

  • @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?

  • @zoomingh
    @zoomingh 3 ปีที่แล้ว

    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

  • @andrewjefferies8391
    @andrewjefferies8391 2 ปีที่แล้ว

    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.

  • @HX2003
    @HX2003 3 ปีที่แล้ว

    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 ปีที่แล้ว +1

      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!

  • @amir.hsekandarpour3363
    @amir.hsekandarpour3363 2 ปีที่แล้ว

    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.

  • @AminShahsavar
    @AminShahsavar 3 ปีที่แล้ว

    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!

  • @MrAsteliks007
    @MrAsteliks007 3 ปีที่แล้ว +2

    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 ปีที่แล้ว +1

      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.

  • @hfe1833
    @hfe1833 3 ปีที่แล้ว

    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

  • @TechInventorAman
    @TechInventorAman 3 ปีที่แล้ว

    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.

  • @kramkhirinroddara5324
    @kramkhirinroddara5324 8 หลายเดือนก่อน

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

  • @axramar7743
    @axramar7743 5 หลายเดือนก่อน

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

  • @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?

  • @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!

  • @akshayviruss
    @akshayviruss 3 ปีที่แล้ว

    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 ปีที่แล้ว +1

      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 😅

  • @itdecoder2018
    @itdecoder2018 หลายเดือนก่อน

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

  • @mauricecraft890
    @mauricecraft890 ปีที่แล้ว

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

    • @atomic14
      @atomic14  ปีที่แล้ว

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

  • @CamoPeng
    @CamoPeng 3 หลายเดือนก่อน

    Sorry for the noob question - but why use DMA?

  • @AkashJadhavIT
    @AkashJadhavIT 3 ปีที่แล้ว

    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 - th-cam.com/video/LY-1DHTxRAk/w-d-xo.html

  • @TronDiscSeller
    @TronDiscSeller 2 ปีที่แล้ว

    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  2 ปีที่แล้ว

      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 2 ปีที่แล้ว

      @@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  2 ปีที่แล้ว

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

    • @TronDiscSeller
      @TronDiscSeller 2 ปีที่แล้ว

      @@atomic14 Thank you sir, I have emailed you

  • @user-st8bb2gs9e
    @user-st8bb2gs9e 2 ปีที่แล้ว

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

  • @aarriikknn33ll
    @aarriikknn33ll 3 ปีที่แล้ว

    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

  • @edgull_tlt
    @edgull_tlt 2 ปีที่แล้ว

    Спасибо

  • @bamblaster2564
    @bamblaster2564 15 วันที่ผ่านมา

    But....why?