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 the Development Environment
1. Installing and Configuring the 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
- When installing Arduino libraries, there are typically two methods: online installation and offline installation. If the library installation requires offline installation, you must use the provided library files.
- For most libraries, users can easily search for and install them via the Arduino IDE's online Library Manager. However, some open-source or custom libraries are not synchronized to the Arduino Library Manager and therefore cannot be found through online search. In this case, users can only install these libraries manually via offline methods.
- The example package for the ESP32-S3-Touch-LCD-3.49 development board can be downloaded from here. The
Arduino\librariesdirectory within the package already contains all the library files required for this tutorial.
| Library or File Name | Description | Version | Installation Method |
|---|---|---|---|
| LVGL | Graphics Library | v8.3.11/v9.3.0 | "Offline Installation" |
| SensorLib | Sensor library | v0.3.1 | "Online Installation" or "Offline 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.
3. Arduino Project Parameter Settings

Example
ESP32-S3-Touch-LCD-3.49 Board Installation Instructions
| Board Name | Installation Requirement | Version Requirement |
|---|---|---|
| ESP32 by Espressif Systems | "Offline Installation" / "Online Installation" | =3.3.0 |
Please note: there are V1 and V2 variants. The libraries and ESP32 versions are common, but the programs (pins have been modified) are not. It is recommended to download the corresponding example program according to your actual product version.
The Arduino examples are located in the Arduino/examples directory of the example package.
| Example | Basic Description | Dependency Library |
|---|---|---|
| 01_ADC_Test | Get the voltage value of the lithium battery | - |
| 02_I2C_PCF85063 | Print real-time time of RTC chip | SensorLib |
| 03_I2C_QMI8658 | Print the raw data from IMU | SensorLib |
| 04_SD_Card | Load and display TF card information | - |
| 05_WIFI_AP | Set to AP mode to obtain the IP address of the access device | - |
| 06_WIFI_STA | Set to STA mode to connect to Wi-Fi and obtain an IP address | - |
| 07_BATT_PWR_Test | Control power via the PWR button when powered solely by the lithium battery | - |
| 08_Audio_Test | Play the sound recorded by the microphone through the speaker | - |
| 09_LVGL_V8_Test | LVGLV8 example | LVGL V8.4.0 |
| 10_LVGL_V9_Test | LVGLV9 example | LVGL V9.3.0 |
01_ADC_Test
Example Description
- The analog voltage connected through the GPIO is converted to digital by the ADC, and then the actual lithium battery voltage is calculated and printed to the terminal.
Hardware Connection
- Connect the board to the computer using a USB cable.
Code Analysis
adc_bsp_init(void): Initializes ADC1, including creating an ADC one-shot trigger unit and configuring Channel 3 of ADC1.adc_get_value(float *value,int *data): Reads the value from Channel 3 of ADC1, calculates the corresponding voltage based on the reference voltage and resolution, and stores it at the location pointed to by the passed pointer. Stores 0 if the read fails.adc_example(void* parameter): After initializing ADC1, creates an ADC task. This task reads the ADC value every second and calculates the system voltage from the raw ADC reading.
Operation Result
-
After the program is compiled and downloaded, you can view the printed ADC values and voltage output by opening the Serial Monitor, as shown in the following image:

02_I2C_PCF85063
Example Description
- Through the I2C protocol, initialize the PCF85063 chip, set the time, and then periodically read the time and print it to the terminal
Hardware Connection
- Connect the board to the computer using a USB cable.
Code Analysis
void i2c_rtc_loop_task(void *arg): Creates an RTC task to implement the RTC function, reading the clock of the RTC chip every second and outputting it to the terminal.
Operation Result
-
After the program is compiled and downloaded, open the serial port monitoring to see the RTC time of the printout, as shown in the following figure:

03_I2C_QMI8658
Example Description
- Initialize the QMI8658 chip via the I2C protocol, then read the corresponding attitude information every 200ms and print it to the terminal.
Hardware Connection
- Connect the board to the computer using a USB cable.
Code Analysis
void i2c_qmi_loop_task(void *arg): Creates a QMI task to acquire attitude information. The task reads and prints accelerometer and gyroscope data at 200ms intervals, and outputs the results to the serial console.
Operation Result
-
Open the Serial Monitor to see the printed raw data from the IMU (Euler angles need to be converted by yourself), as shown in the figure below:

04_SD_Card
Example Description
- Drive the TF card through SDMMC, and print the TF card information to the terminal after successfully mounting.
Hardware Connection
- Install a FatFs-formatted TF card into the board before powering on
Code Analysis
-
sdcard_init(void): Initializes the TF card using 1-line SDMMC mode. -
loop(): Task for testing TF card read/write function. To enable, uncomment the macro definition#define sdcard_write_Test.//#define sdcard_write_Test
Operation Result
-
Click on the serial port monitoring device, you can see the output information of the TF card, as shown in the figure below:

05_WIFI_AP
Example Description
- This example can set the development board as a hotspot, allowing phones or other devices in STA mode to connect to the development board.
Hardware Connection
- Connect the board to the computer using a USB cable.
Code Analysis
-
In the
05_WIFI_AP.inofile, locatessidandpassword. Phones or other STA mode devices can then connect to the board using this SSID and password.const char *ssid = "ESP32_AP";const char *password = "12345678";
Operation Result
-
After flashing the program, open the Serial Terminal. If a device successfully connects to the hotspot, the MAC address of that device will be output, as shown:

06_WIFI_STA
Example Description
- This example configures the development board as a STA device to connect to a router, thereby accessing the system network.
Hardware Connection
- Connect the board to the computer using a USB cable.
Code Analysis
-
In the
06_WIFI_STA.inofile, locatessidandpassword, and modify them to match the SSID and Password of an available router in your current environment.const char *ssid = "you_ssid";const char *password = "you_password";
Operation Result
-
After flashing the program, open the Serial Terminal. If the device successfully connects to the hotspot, the obtained IP address will be output, as shown in the figure:

07_BATT_PWR_Test
Example Description
- Demonstrates how to control the system power via the PWR button when powered by the lithium battery.
Hardware Connection
- Connect the board to the computer using a USB cable.
Code Analysis
setup_ui(lv_ui *ui): Initializes the UI interface for visual control.tca9554_init(): Initialize the lithium battery control IO port.button_Init(): Initialize buttons and various trigger events.example_button_pwr_task(void* parmeter): Task that waits for button event triggers.
Operation Result
-
After the program is flashed, disconnect the USB power supply and connect the lithium battery. Power on by pressing and holding the PWR button, as shown in the figure:
tip- Press and hold the PWR button, wait for the screen to display "On", which means that the startup is successful, and release the button
- Press and hold the PWR button again, wait for the screen to display "Off", which means that the power is turned off successfully, and release the button
08_Audio_Test
Example Description
- Demonstrates how to get data from the microphone and then play it through the speaker
Hardware Connection
- Connect the board to the computer using a USB cable.
Code Analysis
i2c_master_Init(): Initializes the I2C bus.tca9554_init(): Initializes the I/O ports for audio amplifier CTRL control.lvgl_port_init(): Initializes the LVGL interface.user_audio_bsp_init(): Initializes the audio interface.
Operation Result
-
After the program is flashed, as shown in the figure:
tip- Click Recording to enter recording mode, speak into the MIC, and it will automatically end after 3 seconds
- Click Play to play the sound you just recorded
09_LVGL_V8_Test
Example Description
- Helps users quickly implement UI design by porting LVGL V8.
Hardware Connection
- Connect the board to the computer using a USB cable.
Code Analysis
-
If a 90-degree display rotation is needed, locate the
#define Rotatedmacro in theuser_config.hfile and assign the value"USER_DISP_ROT_90". -
If backlight testing is required, locate the
#define Backlight_Testingmacro in theuser_config.hfile and assign the value"true".#define Backlight_Testing 0#define USER_DISP_ROT_90 1#define USER_DISP_ROT_NONO 0#define Rotated USER_DISP_ROT_NONO //Rotation via software
Operation Result
-
After the program is flashed, the device operation result is as follows:

10_LVGL_V9_Test
Example Description
- Helps users quickly implement UI design by porting LVGL V9.
Hardware Connection
- Connect the board to the computer using a USB cable.
Code Analysis
-
If a 90-degree display rotation is needed, locate the
#define Rotatedmacro in theuser_config.hfile and assign the value"USER_DISP_ROT_90". -
If backlight testing is required, locate the
#define Backlight_Testingmacro in theuser_config.hfile and assign the value"true".#define Backlight_Testing 0#define USER_DISP_ROT_90 1#define USER_DISP_ROT_NONO 0#define Rotated USER_DISP_ROT_NONO //Rotation via software
Operation Result
-
After the program is flashed, the device operation result is as follows:
