Sound with ESP32 - ...
 
Notifications
Clear all

Sound with ESP32 - I2S Protocol

57 Posts
5 Users
4 Likes
4,130 Views
(@dronebot-workshop)
Workshop Guru Admin
Joined: 5 years ago
Posts: 1043
Topic starter  

Build an Internet Radio, an MP3 Player, and display microphone waveforms with an ESP32 and some I2S peripherals. Learn to use the I2S sound protocol with the ESP32.

Article with code: https://dronebotworkshop.com\esp32-i2s

You might have seen the term “I2S” on the spec sheet for the ESP32 and may have just assumed that it was a form of I2C.  Well, you would be mistaken - I2S is a protocol for manipulation of digital audio, and today we will be using it with the ESP32.

After a short primer on I2S and digital audio fundamentals, we will use an I2S microphone module with an ESP32. We’ll display the microphone output as a waveform on the Arduino IDE Serial Plotter.

After that, we will grab a library from GitHub, and we’ll use it to build an MP3 player with an I2S amplifier module. We’ll then use the same library and the ESP32 WiFi to create an Internet Radio.

Finally, we will convert our simple Internet Radio into a stereo device, with a volume control.

Here is what is in today's video:

00:00 - Introduction

01:27 - I2S & Digital Audio Intro

08:25 - I2S Peripherals

10:18 - Using an I2S Microphone

18:37 - I2S MP3 Player

28:31 - Simple I2S Internet Radio

33:41 - Stereo Internet Radio

43:56 - Conclusion

Remember, if you need any of the code used here, you'll find it on the DroneBot Workshop website at https://dronebotworkshop.com\esp32-i2s .

Hope you enjoy the video!

Bill

"Never trust a computer you can’t throw out a window." — Steve Wozniak


   
robotBuilder reacted
Quote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6549
 

Is it possible to change the sketch to send a Bluetooth stream to something like an Alexa? I know the ESP32 has a Bluetooth transmitter, but so far can't find info to make use of it.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@jailton)
Member
Joined: 2 years ago
Posts: 3
 

Hello good afternoon.

I know my question is unrelated to the topic.
I'm trying to do this web radio project and I'm having the following problem after programming my ESP32.

info Request http://s1.knixx.fm/dein_webradio_64.aac failed!

Does anyone have a way to solve this problem?

 

Thank you


   
ReplyQuote
(@mo1977)
Member
Joined: 2 years ago
Posts: 16
 

I am trying to compile the MP3 player code in the I@S tutorial.  I am getting this error message:

I am using the suggested library.

libraries\SD\src/utility/Sd2PinMap.h:524:2: error: #error Architecture or board not supported.
#error Architecture or board not supported.

The board is a NodeECU-32s


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6549
 

@mo1977 So your board is an ESP32, and that is selected in board manager, correct. Then what sketch are you trying to use?

If you are trying to run the sketches Bill posted in the above YT vid, you also need to install the library he pointed out. Go to the github location that Bill gave you the link for, click on the GREEN code button then click on Download ZIP. Now in the IDE, click Sketch, Include Library then Add .ZIP library and find the zip. click ok, done. Now comple, occasionally the IDE needs to be restarted so if you get an unexplained error, close all sketches, quit the app and restart.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@mo1977)
Member
Joined: 2 years ago
Posts: 16
 

@zander The Board I am using is using is a Nodemcu  ESP-32S. The board selected is NodeMCU-32S.

The sketch is the ESP32 SD I2S Music Player sketch.

Here's the sketch:

/*
ESP32 SD I2S Music Player
esp32-i2s-sd-player.ino
Plays MP3 file from microSD card
Uses MAX98357 I2S Amplifier Module
Uses ESP32-audioI2S Library - https://github.com/schreibfaul1/ESP32-audioI2S
*
DroneBot Workshop 2022
https://dronebotworkshop.com
*/

// Include required libraries
#include "Arduino.h"
#include "Audio.h"
#include "SD.h"
#include "FS.h"

// microSD Card Reader connections
#define SD_CS 5
#define SPI_MOSI 23
#define SPI_MISO 19
#define SPI_SCK 18

// I2S Connections
#define I2S_DOUT 22
#define I2S_BCLK 26
#define I2S_LRC 25

// Create Audio object
Audio audio;

void setup() {

// Set microSD Card CS as OUTPUT and set HIGH
pinMode(SD_CS, OUTPUT);
digitalWrite(SD_CS, HIGH);

// Initialize SPI bus for microSD Card
SPI.begin(SPI_SCK, SPI_MISO, SPI_MOSI);

// Start Serial Port
Serial.begin(115200);

// Start microSD Card
if(!SD.begin(SD_CS))
{
Serial.println("Error accessing microSD card!");
while(true);
}

// Setup I2S
audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);

// Set Volume
audio.setVolume(5);

// Open music file
audio.connecttoFS(SD,"/MYMUSIC.mp3");

}

void loop()
{
audio.loop();
}


   
ReplyQuote
(@mo1977)
Member
Joined: 2 years ago
Posts: 16
 

@zander I have done this and I still get this error.  Puzzling:

In file included from C:\Users\Maurice Craft\Documents\Arduino\libraries\SD\src/utility/Sd2Card.h:26:0,
from C:\Users\Maurice Craft\Documents\Arduino\libraries\SD\src/utility/SdFat.h:29,
from C:\Users\Maurice Craft\Documents\Arduino\libraries\SD\src/SD.h:20,
from C:\Users\Maurice Craft\Documents\Arduino\libraries\ESP32-audioI2S-master\src/Audio.h:28,
from C:\Users\Maurice Craft\AppData\Local\Temp\.arduinoIDE-unsaved202279-1940-kq27li.e27ec\BareMinimum\BareMinimum.ino:14:
C:\Users\Maurice Craft\Documents\Arduino\libraries\SD\src/utility/Sd2PinMap.h:524:2: error: #error Architecture or board not supported.
#error Architecture or board not supported.

 

HOWEVER: For the hell of it I started Arduino IDE 1.8.19 and it compiled and uploaded. Using Arduino IDE 2.0.0-rc9.1 and I get the aforementioned error! Bug?  Thanks for your help.  Maurice


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6549
 

@mo1977 You should report that to the IDE2 team. However I do see a board not supported error, did you choose the right board in IDE2?

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@mo1977)
Member
Joined: 2 years ago
Posts: 16
 

Yes.  After reading your message I started both versions, cut and pasted the code in both with the same results.  I have a message that says there is an update to the 2.0.0 version.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6549
 

@mo1977 Earlier you said it worked with IDE1. Do not use IDE2, it is still beta.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6549
 

@jailton Not enough information.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6549
 

@mo1977 Try with ESP32 Dev Module, it should be near the top of the selector list.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6549
 

@mo1977 Please read the Help section on the right side to learn how to post code. Also use the Practice forum to try that out.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6549
 

@mo1977 Yes, if you use the same sketch and similar board as Bill it will work in IDE1, IDE2 is still beta.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@mo1977)
Member
Joined: 2 years ago
Posts: 16
 

@zander Thanks.  Will do.


   
ReplyQuote
Page 1 / 4