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
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 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 |
--
Uli Raich - 2021-01-24
Comments