Working with Arduino
This chapter contains the following sections. Please read as needed:
Arduino Getting Started
New to Arduino ESP32 development and looking for a quick start? We have prepared a comprehensive Getting Started Tutorial for you.
- Section 0: Getting to Know ESP32
- Section 1: Installing and Configuring Arduino IDE
- Section 2: Arduino Basics
- Section 3: Digital Output/Input
- Section 4: Analog Input
- Section 5: Pulse Width Modulation (PWM)
- Section 6: Serial Communication (UART)
- Section 7: I2C Communication
- Section 8: SPI Communication
- Section 9: Wi-Fi Basics
- Section 10: Web Server
- Section 11: Bluetooth
- Section 12: LVGL GUI Development
- Section 13: Comprehensive Project
Note: This tutorial uses the ESP32-S3-Zero as a reference example, and all hardware code is based on its pinout. Before you start, we recommend checking the pinout of your development board to ensure the pin configuration is correct.
Setting Up Development Environment
1. Installing and Configuring Arduino IDE
Please refer to the tutorial Installing and Configuring Arduino IDE to download and install the Arduino IDE and add ESP32 support.
2. Installing Libraries
To run the demo, you need to install the corresponding library.
You can click here to download the demo package for the ESP32-S3-CAM-OVxxxx development board. The arduino\libraries directory within the package already includes all the library files required for this tutorial.
| Library/File Name | Description | Version | Installation Method |
|---|---|---|---|
| es7210 | Audio ADC driver | —— | Manual Installation |
| es8311 | Audio DAC driver | —— | Manual Installation |
| lvgl | LVGL graphics library | v8.4.0 | Via Library Manager or Manual Installation |
| ESP32-audioI2S-master | Audio playback component | v3.4.4 | Via Library Manager or Manual Installation |
There are strong dependencies between versions of LVGL and its driver libraries. For example, a driver written for LVGL v8 may not be compatible with LVGL v9. To ensure that the examples can be reproduced reliably, it is recommended to use the specific versions listed in the table above. Mixing different versions of libraries may lead to compilation failures or runtime errors.
Installation Steps:
-
Navigate to the downloaded demo package.
-
Copy all the folders (e.g., ESP32-audioI2S-master, lvgl) from its
Arduino\librariesdirectory to your Arduino libraries folder.infoThe path to the Arduino libraries folder is typically:
c:\Users\<username>\Documents\Arduino\libraries.You can also locate it in the Arduino IDE by going to File > Preferences and checking the "Sketchbook location". The libraries folder is the
librariessubfolder within this path. -
For other installation methods, please refer to: Arduino Library Management Tutorial.
Demo
The Arduino demos are located in the Arduino/examples directory of the demo package.
| Demo | Basic Program Description | Dependency Library |
|---|---|---|
| 01_lvgl_example | Demonstrates basic graphics library functions; also can be used to test basic display performance | lvgl |
| 02_CameraWebServer | Web camera test. Connects to Wi-Fi, creates an HTTP server, and captures camera images | —— |
| 03_audio_out_no_tf | Audio playback test | es8311 |
| 04_SDMMC_Test | TF card mounting and file read/write test | LVGL,SensorLib |
| 05_audio_out_tf | LVGL demonstration | LVGL, Arduino_DriveBus, Adafruit_XCA9554 |
| 06_esp_sr | ES7210 driver example, capturing human voice for detection | —— |
Arduino Project Parameter Settings
- If the example being flashed contains a speech recognition model, select "ESP SR 16M (3MB APP/7MB SPIFFS/2.9MB MODEL)" for the Partition Scheme.
- If the example being flashed does not contain a speech recognition model, select "16M Flash (3MB APP/9.9MB FATFS)" or another appropriate scheme.

01_lvgl_example
Demo Description
- This example demonstrates how to drive the display using Arduino and run an LVGL example program
Hardware Connection
- Connect the development board to the computer
Code Analysis
-
Initialize I2C and backlight:
DEV_I2C_Init();
IO_EXTENSION_Init();
IO_EXTENSION_Output(IO_EXTENSION_IO_6, 1);
IO_EXTENSION_Pwm_Output(100); -
Initialize the display, touch, and LVGL:
lcd_driver_init();
touch_driver_init();
lvgl_driver_init(); -
Load the LVGL demo:
lvgl_port_lock(0);
lv_demo_widgets();
// lv_demo_benchmark();
// lv_demo_keypad_encoder();
// lv_demo_music();
// lv_demo_stress();
lvgl_port_unlock();
Operation Result

02_CameraWebServer
Demo Description
- This example is a comprehensive program combining camera and HTTP server functionality. You can access the camera video stream through a browser
Hardware Connection
- Connect the camera (supports GC0308, GC2145, OV5640, OV3660)
- Connect the development board to the computer
Code Analysis
-
Initialize the camera:
esp_err_t err = esp_camera_init(&config);
if (err != ESP_OK) {
esp_camera_deinit();
Serial.printf("Camera init failed with error 0x%x", err);
config.frame_size = FRAMESIZE_QVGA;
config.pixel_format = PIXFORMAT_RGB565;
esp_camera_init(&config);
} -
Enter the SSID and password to connect to Wi-Fi:
WiFi.begin(ssid, password); -
Start the HTTP server:
startCameraServer();
Operation Result
-
After powering on, wait for the Wi-Fi connection. Open the serial monitor to see the IP address, then open it in a browser

03_audio_out_no_tf
Demo Description
- This example demonstrates playing music using the ES8311 audio DAC
Hardware Connection
- Connect a speaker
- Connect the development board to the computer
Code Analysis
-
Initialize the I2C controller and external I/O expander:
DEV_I2C_Init();
IO_EXTENSION_Init();
IO_EXTENSION_Output(IO_EXTENSION_IO_6, 1); -
Initialize ES8311:
es8311_codec_init(); -
Initialize I2S and enable the power amplifier (PA) pin:
setupI2S();
IO_EXTENSION_Output(IO_EXTENSION_IO_4, 1); -
In the loop, continuously write data to the ES8311 via I2S:
void loop() {
i2s.write((uint8_t *)audio_data, AUDIO_SAMPLES * 2);
}
Operation Result
- After flashing the program, music will start playing automatically
04_SDMMC_Test
Demo Description
- This example demonstrates how to mount a TF card and test file reading and writing
Hardware Connection
- Insert a TF card
- Connect the development board to the computer
Code Analysis
-
Set the SDIO interface pins and mount the file system:
if(!SD_MMC.setPins(clk, cmd, d0)){
Serial.println("Pin change failed!");
return;
}
if (!SD_MMC.begin( "/sdcard", true)) {
Serial.println("Card Mount Failed");
return;
} -
File read/write test:
listDir(SD_MMC, "/", 0);
createDir(SD_MMC, "/mydir");
listDir(SD_MMC, "/", 0);
removeDir(SD_MMC, "/mydir");
listDir(SD_MMC, "/", 2);
writeFile(SD_MMC, "/hello.txt", "Hello ");
appendFile(SD_MMC, "/hello.txt", "World!\n");
readFile(SD_MMC, "/hello.txt");
deleteFile(SD_MMC, "/foo.txt");
renameFile(SD_MMC, "/hello.txt", "/foo.txt");
readFile(SD_MMC, "/foo.txt");
testFileIO(SD_MMC, "/test.txt");
Serial.printf("Total space: %lluMB\n", SD_MMC.totalBytes() / (1024 * 1024));
Serial.printf("Used space: %lluMB\n", SD_MMC.usedBytes() / (1024 * 1024));
Operation Result

05_audio_out_tf
Demo Description
- This example demonstrates playing MP3 audio from a TF card
Hardware Connection
- Insert a TF card with an audio file named ff-16b-1c-44100hz.mp3 in the root directory
- Connect a speaker
- Connect the development board to the computer
Code Analysis
-
Initialize I2S and the audio decoder library, and set the playback path:
audio.setPinout(I2S_BCK_PIN, I2S_LRCK_PIN, I2S_DOUT_PIN,I2S_MCLK_PIN);
audio.connecttoFS(SD_MMC, "ff-16b-1c-44100hz.mp3");
Operation Result
- After flashing the program, MP3 music will play automatically
06_esp_sr
Demo Description
- This example demonstrates using the ES7210 audio ADC chip for voice wake-up and speech recognition
Hardware Connection
- Connect the development board to the computer
Code Analysis
-
Initialize I2S and the ES7210 audio ADC:
Wire.begin(I2C_PIN_SDA, I2C_PIN_SCL);
es7210_init();
i2s.setPins(I2S_PIN_BCK, I2S_PIN_WS, I2S_PIN_DOUT, I2S_PIN_DIN, I2S_PIN_MCK);
i2s.setTimeout(1000);
i2s.begin(I2S_MODE_STD, 16000, I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO); -
Register callbacks for voice wake-up and speech recognition events, then start ESP-SR:
ESP_SR.onEvent(onSrEvent);
ESP_SR.begin(i2s, sr_commands, sizeof(sr_commands) / sizeof(sr_cmd_t), SR_CHANNELS_STEREO, SR_MODE_WAKEWORD);
Operation Result
