Tags:
create new tag
view all tags

I2S and sound

Introduction

In order to play audio files we need:

  • the audio file itself, which we expect to be in uncompressed wav format
  • a file system from which to read the file. This is available in MicroPython either in its internal flash or on an SD card
  • a fast 16 bit DAC to convert the audio data into an analogue form that can be consumed by a loadspeaker
  • an amplifier to get enough signal power needed for the loadspeaker
  • a software driver implementing the I2S protocol
The digital data must be transferred to the DAC, which is done through the I2S protocol invented by Philips in the end 1980 ies.

There are two cheap I2S boards converting digital audio data to an analogue audio signal and communicating through the I2S protocol:

  • the ! MAX98357A, a mono converter board with integrated amplifier to which we can directly connect a loadspeaker
  • the PCM5102a, a stereo converter board with a connector for head phones. If we want to connect a loudspeaker to this board we have to pass through an audio amplifier.

Connecting the MAX98357A

max98357a.png

Here is a table showing how I connected the MAX98357A to the ESP32 board:

MAX98357A pin pin on ESP32 CPU card signification
Gnd Gnd  
Vcc 3.3V  
SD n.c.  
Gain Gnd important: don't leave this pin floating!
Din D2: GPIO 21 audio data
BCLK D0: GPIO 26 bit clock
LRC (LRCLK) D1: GPIO 22 left/right clock

Connecting the PCM5102:

pcm5102.png pcm5102back.png

PCM5102 pin pin on ESP32 CPU card signification
Vcc 5V  
Gnd Gnd  
BCK D0: GPIO 26 bit clock
Din D2: GPIO 21 audio data
LRCLK D1: GPIO 22 left/right clock
FMT Gnd  
XSMT short-circuit with A3V3   3.3 V output from regulator LDO
The SD card module, which may be used to store the music files, uses D5,D6,D7,D8 for its interface pins. These pins should therefore be avoided when choosing the pins for the PCM5102 module. D3 and D4 are used for PSRAM in case of the WROVER-B module.

I2S microphones

Two different I2S microphone breakout boards are available:

Both microphones are supported by the MicroPython I2S driver.
INMP441 front view INMP441 back view
inmp441_front.png inmp441_back.png
SPH0645 front view SPH0645 back view
sph0645_front.png sph0645_back.png

I2S examples

Mike Teachman, the author of the I2S MicroPython driver has supplied a series of test programs for his driver. These examples need some slight modifications due to different connections of the I2S pins with respect to his hardware:

  • SCK_PIN: corresponds to the hardware pin BCK and must be set to GPIO 26
  • WS_PIN: corresponds to hardware pin LRCK and must be set to GPIO 22
  • SD_PIN: corresponds to hardware pin Din and must be set to GPIO 21
With these modifications, play-tone.py should work. In order to make play-wav-from-flash-blocking.py work modified the WAV_FILE to wav/side-to-side-8k-16bits-stereo.wav. Then I created the folder /wav on the ESP32 with ampy and copied side-to-side-8k-16bits-stereo.wav to the folder.

-- Uli Raich - 2021-01-24

Comments

Topic attachments
I Attachment History Action Size Date Who Comment
PNGpng inmp441_back.png r1 manage 156.5 K 2022-09-24 - 08:52 UliRaich  
PNGpng inmp441_front.png r1 manage 143.0 K 2022-09-24 - 08:52 UliRaich  
PNGpng max98357a.png r1 manage 203.5 K 2021-01-24 - 16:23 UliRaich  
PNGpng pcm5102.png r1 manage 127.0 K 2021-01-24 - 16:23 UliRaich  
PNGpng pcm5102back.png r1 manage 88.2 K 2021-01-24 - 17:48 UliRaich  
PNGpng sph0645_back.png r1 manage 121.0 K 2022-09-24 - 08:52 UliRaich  
PNGpng sph0645_front.png r1 manage 110.0 K 2022-09-24 - 08:52 UliRaich  
Edit | Attach | Watch | Print version | History: r5 < r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r5 - 2022-09-24 - UliRaich
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2022 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback