Chapter 29 Bluetooth Media by Audio Module
In the previous section, ESP32’s own DAC was used to output the audio signal, and obviously there was some distortion in the sound quality. In this section, with the help of PCM5102A chip, you will enjoy higher-quality music.
Project 29.1 Playing Bluetooth Music through Audio Converter & Amplifier
In this project, we will use Audio Converter & Amplifier to transcode audio data into stereo and output it.
Component List
ESP32-WROVER x1
|
GPIO Extension Board x1
|
Micro USB Wire x1
|
Speaker
|
Audio Converter & Amplifier
|
Jumper F/M x4 Jumper F/F x2
|
Component knowledge
The front and reverse view of Audio Converter & Amplifier module.
front view |
reverse view |
schematic diagram |
|---|---|---|
|
|
|
Interface description for Audio Converter & Amplifier module
Pin |
Name |
Introductions |
|---|---|---|
1 |
SCK |
System clock input |
2 |
BCK |
Audio data bit clock input |
3 |
DIN |
Audio data input |
4 |
LCK |
Audio data word clock input |
5 |
VCC |
Power input, 3.3V~5.0V |
6 |
GND |
Power Ground |
7 |
L |
External audio left channel input |
8 |
G |
Power Ground |
9 |
R |
External audio right channel input |
10 |
G |
Power Ground |
11 |
R+ |
Positive pole of right channel horn |
12 |
R- |
Negative pole of right channel horn |
13 |
L+ |
Positive pole of left channel horn |
14 |
L- |
Negative pole of left channel horn |
|
|
Speaker interface: Connect left channel speaker and right channel speaker. Group L: L+ & L-; Group R: R+& R-. The two interfaces of the speaker can be connected to the interfaces of group L or group R. But when one interface is connected to group L, the other cannot be connected to group R. Doing so may cause the module to malfunction.
Headphone interface: the interface to connect the headphones.
I2S input interface: connect to the device with I2S. Used to transcode audio data into DAC audio signals.
External audio input interface: connect to external audio equipment. Used to amplify externally input audio signals.
Power interface: connect to external power supply. External power supply selection range: 3.3V-5.0V.
Circuit
Schematic diagram |
|
Hardware connection |
If you need any support, please feel free to contact us via: support@freenove.com
|
Sketch
If you are using ESP32 Core 2.x.x, please see Sketch_29.1_Bluetooth_Music_by_Audio_Converter(2.x.x)
If you are using ESP32 Core 3.x.x, please see Sketch_29.1_Bluetooth_Music_by_Audio_Converter(3.x.x)
Sketch_29.1_Bluetooth_Music_by_Audio_Converter(2.x.x)
Compile and upload the code to the ESP32-WROVER and open the serial monitor. ESP32 takes a few seconds to initialize the program.
When you see the prompt as shown in the figure below, it means that the Bluetooth function of ESP32 is ready and waiting for the connection of other Bluetooth devices.
Please use your mobile phone to search and connect a Bluetooth device named “ESP32”. After the connection is successful, you can use ESP32 to play the audio files in your mobile phone.
Code
The following is the program code:
Code Explanation
Define an I2S configuration class and initialize it; define an I2S pin configuration class and associate I2S signals with these pins.
In this chapter, the procedure is very similar to the previous section. The difference only lies in the I2S configuration. The audio quality of the DAC output from the PCM5102 chip after decoding is significantly higher than that of the ESP32’s own 8-bit precision DAC.
Sketch_29.1_Bluetooth_Music_by_Audio_Converter(3.x.x)
Code
The following is the program code:
Code Explanation
Introduce the necessary libraries.
Define the required pins
Create instances of I2S and Bluetooth A2DP Sink
Configure the specific pins used for I2S
Initialize the I2S interface
Start the Bluetooth sink with the name “ESP32 A2DP”












