Skip to main content

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.

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

info

For the ESP32-S3-Touch-AMOLED-1.43C development board, Arduino IDE requires arduino-esp32 version v3.3.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-S3-Touch-AMOLED-1.43C development board can be downloaded from here. The Arduino\libraries directory within the package already contains all the library files required for this tutorial.
Library/File NameDescriptionVersionInstallation Method
LVGLGraphics Libraryv8.3.11/v9.5.0"Install Offline"
Version Compatibility Notes

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.

DemoBasic Program DescriptionDependency Library
01_ADC_TestGet the voltage value of the lithium battery-
02_WIFI_APSet to AP mode to obtain the IP address of the access device-
03_WIFI_STASet to STA mode to connect to Wi-Fi and obtain an IP address-
04_Audio_TestPlay the sound recorded by the microphone through the speakerLVGL V9.5.0
05_LVGL_V8_TestLVGLV8 demoLVGL V8.3.11
06_LVGL_V9_TestLVGLV9 demoLVGL V9.5.0

01_ADC_Test

Demo 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

printf("adc-example run\n"); // Terminal output information
bsp_batt_init(); // Initialize ADC channel
bsp_batt_get_voltage(); // Get battery voltage
bsp_batt_get_status(); // Get battery charging status

Operation Result

  • After the program is compiled and uploaded, open the serial monitor to see the printed output of the lithium battery voltage and charging information, as shown in the following figure:

02_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 02_WIFI_AP.ino file, locate ssid and password. 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:

03_WIFI_STA

Demo 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 03_WIFI_STA.ino file, locate ssid and password, and modify them to match the SSID and Password of an available router in the 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:

04_Audio_Test

Demo Description

  • Demonstrate how to acquire microphone data, play music, and other functions.

Hardware Connection

  • Connect the board to the computer using a USB cable

Code Analysis

bsp_broolesia_display_init(); // Screen initialization
speaker = bsp_audio_codec_speaker_init(); // Obtain playback handle
microphone = bsp_audio_codec_microphone_init(); // Obtain recording handle
boot_button_ = new Button(BUTTON_0_GPIO_PIN);Instantiate button
InitializeButtons(); // Button callback initialization
ESP_ERROR_CHECK(esp_codec_dev_open(speaker, &fs)); // Open playback
ESP_ERROR_CHECK(esp_codec_dev_open(microphone, &fs)); // Open recording
ESP_ERROR_CHECK(esp_codec_dev_set_out_vol(speaker, 100)); // Set playback volume
ESP_ERROR_CHECK(esp_codec_dev_set_in_gain(microphone,35)); // Set recording gain

Operation Result

  • After the program is flashed, the screen displays as shown:

    tip
    1. Press the BOOT button once to record for 3 seconds; after recording ends, the recording is played back automatically.
    2. Double-click the BOOT button to play a piece of music; press and hold the BOOT button to interrupt playback.

05_LVGL_V8_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

#define BACKLIGHT_EN 1 // Macro definition, enable backlight test, enabled by default
bsp_broolesia_display_init(); // Initialize screen and LVGL
if(bsp_display_lock(-1) == ESP_OK) { // Wait for lock
lv_demo_widgets(); // LVGL default UI
bsp_display_unlock(); // Release lock
}

Operation Result

  • After the program is flashed, the device operation result is as follows:

06_LVGL_V9_Test

Demo Description

  • Implements various multifunctional GUI interfaces on the screen by porting LVGL V9.

Hardware Connection

  • Connect the board to the computer using a USB cable

Code Analysis

#define BACKLIGHT_EN 1 // Macro definition, enable backlight test, enabled by default
bsp_broolesia_display_init(); // Initialize screen and LVGL
if(bsp_display_lock(-1) == ESP_OK) { // Wait for lock
lv_demo_widgets(); // LVGL default UI
bsp_display_unlock(); // Release lock
}

Operation Result

  • After the program is flashed, the device operation result is as follows: