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-S3-LCD-1.9 development board, the Arduino IDE requires the installation of arduino-esp32 v3.3.0 or higher.
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-S3-LCD-1.9 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" |
| Arduino_GFX_Library | Sensor Library | v1.5.6 | "Install Online" or "Install Offline" |
| Freenove_WS2812_Lib_for_ESP32 | WS2812 Driver Library | v2.0.0 | "Install Online" or "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_WS2812_Test | Drive WS2812RGB LEDs | Freenove_WS2812_Lib_for_ESP32 |
| 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 WiFi and obtain an IP address | - |
| 07_Hello_World_GFX | GFX basic demo | Arduino_GFX_Library |
| 08_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 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_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 view the raw data output from the IMU (Euler angles require conversion), as shown in the figure below:

03_SD_Card
Demo Description
- Drive the TF card using SDMMC. After successfully mounting the TF card, print the TF card information to the terminal and read/write data to the
writeTest.txtfile every 1 second.
Hardware Connection
- Connect the board to the computer using a USB cable
Code Analysis
-
In the
03_SD_Card.inofile, find the#define sdcard_write_Testline and uncomment it to test the TF card read/write function.//#define sdcard_write_Test
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_WS2812_Test
Demo Description
- Drive the WS2812 RGB LEDs to create a flowing rainbow effect. This example is only applicable to the ESP32-S3-LCD-1.9.
Hardware Connection
- Connect the board to the computer using a USB cable
Code Analysis
-
First, analyze the macro definitions in the file:
#define LEDS_COUNT 2 // Number of WS2812-RGB LED beads
#define LEDS_PIN 15 //WS2812-GPIO control pin
#define CHANNEL 0 //WS2812 control channel -
Analyze the main functions:
strip.setLedColorData(id, color); //id: The ID of the RGB beads, color: The actual color 0XFF0000 which means red
strip.setLedColorData(id, r, g, b); //r, g, b: The actual values of the three primary colors
strip.show();//Push the color data to WS2812
Operation Result
-
The actual effect is as follows:
05_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
-
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
Demo Description
- This example can configure the development board as a STA device to connect to a router, thereby enabling access to the system network.
Hardware Connection
- Connect the board to the computer using a USB cable
Code Analysis
-
In the file
espwifi.cpp, findssidandpassword, then modify them to 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 is successfully connected to the hotspot, the IP address obtained will be output, as shown in the figure:

07_Hello_World_GFX
Demo Description
- Implement some basic GUI interface on the screen by porting the Arduino_GFX_Library.
Hardware Connection
- Connect the board to the computer using a USB cable
Code Analysis
-
Configure the Arduino_DataBus and Arduino_GFX classes to drive the LCD.
Arduino_DataBus *bus = new Arduino_HWSPI(6 /* DC */, 7 /* CS */, 5 /* SCK */, 4 /* MOSI */);
Arduino_GFX *gfx = new Arduino_ST7789(bus, 14 /* RST */,0 /*rotation*/,0/*IPS*/,170/*w*/,320/*h*/,35/*offsetx1*/,0/*offsety1*/,35/*offsetx2*/,0/*offsety2*/);
Operation Result
-
After flashing the program, you can see various "Hello World" formats displayed on the screen, as shown in the figure:

08_LVGL_Test
Demo Description
- Implements various multifunctional GUI interfaces on the screen by porting LVGL V8.
Hardware Connection
- Connect the board to the computer using a USB cable
Code Analysis
-
To rotate the display by 90 degrees, find the Direction macro definition in the lcd_config.h file and choose one of the two options.
#define Rotate 1 //Rotation 90
#define Normal 0 //Normal
#define Direction Normal -
This example disables Touch by default for compatibility with the ESP32-S3-LCD-1.9. To enable it, find the EXAMPLE_USE_TOUCH macro definition in the lcd_config.h file and set it to 1.
#define EXAMPLE_USE_TOUCH 0
Operation Result
-
After the program is flashed, the device operation result is as follows:
