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
For the ESP32-C6-Touch-AMOLED-1.64 development board, Arduino IDE requires arduino-esp32 version v3.2.0 or later.
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: Install Online and Install Offline. If the library installation requires Install Offline, you must use the provided library file.
- 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 sample program package for the ESP32-C6-Touch-AMOLED-1.64 development board can be downloaded from here. The
Arduino\librariesdirectory within the package already contains all the library files required for this tutorial.
| Library/File Name | Description | Version | Installation Method |
|---|---|---|---|
| LVGL | Graphics Library | v8.4.0 | "Install Offline” |
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

Demo
The Arduino demos are located in the Arduino/examples directory of the demo package.
| Demo | Basic Program Description | Dependency Library |
|---|---|---|
| 01_ADC_Test | Read the current system voltage value | - |
| 02_I2C_QMI8658 | Print the raw data from the IMU | - |
| 03_SD_Card | Load and display TF card information | - |
| 04_WIFI_AP | Set to AP mode, can obtain the MAC address of connected devices | - |
| 05_WIFI_STA | Set to STA mode to connect to WiFi and obtain an IP address | - |
| 06_LVGL_Test | LVGL demo | LVGL |
01_ADC_Test
Demo Description
- The analog voltage connected via GPIO is converted to a digital value by the ADC. The actual system voltage is then 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 0 of ADC1.adc_get_value(float *value,int *data): Reads the value from Channel 0 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:
-
When connected via USB, the measured voltage is the system voltage, around 4.65V. For detailed analysis, please refer to the schematic.

02_I2C_QMI8658
Demo Description
- Initialize the QMI8658 chip via the I2C protocol, then read the corresponding attitude information every 1 second and print it to the terminal.
Hardware Connection
- Connect the board to the computer using a USB cable
Code Analysis
qmi8658c_example(void* parameter): This function initializes the QMI8658 device. In an infinite loop, it reads and prints accelerometer, gyroscope, and temperature data every 1 second. As the board rotates faster, the gyroscope data increases accordingly. The accelerometer calculates the corresponding acceleration based on its current orientation.
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:
-
Data is output every 1 second. For modifications or reference, you can directly access the qmi source file.

03_SD_Card
Demo Description
- Drives the TF card via SPI, and after successfully mounting the TF card, prints the TF card information to the terminal.
Hardware Connection
- The board must have a TF card inserted (capacity less than 64GB)
- Connect the board to the computer using a USB cable
Operation Result
-
Click to open the Serial Monitor device. You can see the output TF card information; practical_size indicates the actual capacity of the TF card, as shown below:

04_WIFI_AP
Demo Description
- This demo 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
- Find
ssidandpasswordin the05_WIFI_AP.inofile. Then mobile phones or other devices in STA mode can use thisssidandpasswordto connect to the development board.
Operation Result
-
After flashing the program, open the serial terminal. If the device is successfully connected to the hotspot, the MAC address of the device will be output, as shown in the figure:

05_WIFI_STA
Demo Description
- This example sets the development board as a station, allowing it to connect to an available AP. After successful connection, it prints the obtained IP information to the terminal.
Hardware Connection
- Connect the board to the computer using a USB cable
Code Analysis
wifi_init(void): This function initializes the Wi-Fi connection of the ESP32. It sets the ESP32 to Wi-Fi station mode and attempts to connect to the specified Wi-Fi network (viassidandpassword). If successful, it prints the local IP address; if it fails to connect within a certain period (20 * 500 ms), it prints a connection failure message. The function can also enable auto-connect and auto-reconnect features.
Operation Result
-
The chip successfully connects to Wi-Fi in STA mode, and after clicking on the Serial Monitor, you can see the obtained IP address, as shown in the figure.

06_LVGL_Test
Demo Description
- Implements multifunctional GUI interfaces on the screen by porting LVGL.
Hardware Connection
- Connect the board to the computer using a USB cable
Code Analysis
- The display chip itself does not support hardware rotation. If rotation is required, it can be achieved through software. Find the macro definition
#define EXAMPLE_Rotate_90in thelcd_bsp.cfile and uncomment it. Software rotation performance is inferior to hardware rotation.
Operation Result
-
The LVGL example has relatively high requirements for RAM and ROM, so the program must be configured according to the environment setup requirements. After flashing, the device's operation effect is as follows:
