• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

main/11-Mar-2024-5,2785,186

tools/11-Mar-2024-5040

CMakeLists.txtD11-Mar-2024235 75

MakefileD11-Mar-2024182 92

README.mdD11-Mar-20243.1 KiB9568

partitions_adc_dac_example.csvD11-Mar-2024299 76

README.md

1| Supported Targets | ESP32 |
2| ----------------- | ----- |
3
4# I2S Built-in ADC/DAC Example
5
6(See the README.md file in the upper level 'examples' directory for more information about examples.)
7
8In this example, we configure I2S to work in I2S_ADC and I2S_DAC modes and then:
9* recording sound from ADC,
10* playing the recorded sound,
11* playing an audio file in flash via DAC.
12
13#### Note:
14The `tools` directory contains `generate_audio_file.py` script for generating audio files:
15
16    * The script provides an example of generating audio tables from `.wav` files.
17    * In this example, the `wav` file must be in 16k/16bit mono format.
18    * The script will bundle the `wav` files into a single table named `audio_example_file.h`.
19    * Since the ADC can only play 8-bit data, the script will scale each 16-bit value to a 8-bit value.
20    * The script will covert all signed values into unsigned values because only positive values will be output by the ADC.
21
22## How to Use Example
23
24### Hardware Required
25
26* A development board with ESP32 SoC (e.g., ESP32-DevKitC, ESP-WROVER-KIT, etc.)
27* A USB cable for power supply and programming
28* A microphone (with amplifier) and one or two speaker(s) for testing.
29
30The following is the hardware connection:
31
32|hardware|module|GPIO|
33|:---:|:---:|:---:|
34|Microphone|ADC1_CH0|GPIO36|
35|speaker(R)|DAC1|GPIO25|
36|speaker(L)|DAC2|GPIO26|
37
38### Configure the Project
39
40```
41idf.py menuconfig
42```
43
44* Set the flash size to 4 MB under Serial Flasher Options.
45* Select "Custom partition table CSV" and rename "Custom partition CSV file" to "partitions_adc_dac_example.csv".
46
47(Note that you can use `sdkconfig.defaults`)
48
49### Build and Flash
50
51Build the project and flash it to the board, then run monitor tool to view serial output:
52
53```
54idf.py -p PORT flash monitor
55```
56
57(To exit the serial monitor, type ``Ctrl-]``.)
58
59See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
60
61## Example Output
62
63Reset your development board. The application it will first record the sound through the microphone. Then it will play the recorded sound, and finally a piece of audio stored in the flash. The following is the output log:
64
65```
66partiton addr: 0x00110000; size: 2097152; label: storage
67Erasing flash
68partiton addr: 0x00110000; size: 2097152; label: storage
69Erase size: 323584 Bytes
70I2S: PLL_D2: Req RATE: 16000, real rate: 1004.000, BITS: 16, CLKM: 83, BCK: 60, MCLK: 83.333, SCLK: 32128.000000, diva: 64, divb: 21
71Sound recording 5%
72Sound recording 10%
73...
74Sound recording 97%
75Sound recording 102%
76playing: 0 %
77playing: 1 %
78playing: 2 %
79...
80playing: 96 %
81playing: 97 %
82playing: 98 %
83Playing file example:
84I2S: PLL_D2: Req RATE: 16000, real rate: 1004.000, BITS: 16, CLKM: 83, BCK: 60, MCLK: 83.333, SCLK: 32128.000000, diva: 64, divb: 21
85```
86
87## Troubleshooting
88
89* Program upload failure
90
91    * Hardware connection is not correct: run `idf.py -p PORT monitor`, and reboot your board to see if there are any output logs.
92    * The baud rate for downloading is too high: lower your baud rate in the `menuconfig` menu, and try again.
93
94For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon.
95