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 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.5 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.4.0"Online installation" (requires copying the demos folder to src)
GFX_Library_for_ArduinoLCD driver libraryv1.5.5"Online Installation"
JPEGDECJPG decoder libraryv1.8.2"Online Installation"
PNGdecPNG decoder libraryv1.8.2"Online Installation"
XPowersLibPower management driver libraryv0.2.9"Online Installation"
SensorLibSensor libraryv0.3.1"Online Installation"
ESP32-audioI2S-masterAudio processingv3.3.0"Online Installation"
TCA9554I/O expander libraryv0.1.2"Online Installation"
es8311es8311 driver library-"Offline Installation"

3. Arduino Project Parameter Settings

Example

The Arduino examples are located in the Arduino/examples directory of the example package.

ExampleBasic Program DescriptionDependency Library
01_audio_outRead audio file from TF card and play itESP32-audioI2S-master
02_axp2101_examplePrint data from the power management chipXPowersLib
03_camera_web_serverDisplay camera image on a web pageXPowersLib
04_es8311_exampleRecord audio for a period of time and play it backes8311
05_pcf85063_timePrint RTC dataSensorLib
06_qmi8658_getdataPrint IMU dataSensorLib
07_sd_card_testTest TF card read/write-
08_gfx_helloworldDisplay HelloWorld on the screenGFX_Library_for_Arduino, TCA9554
09_gfx_jpegDecode a JPG file and display it on the screenGFX_Library_for_Arduino, TCA9554, JPEGDEC
10_gfx_pngDecode a PNG file and display it on the screenGFX_Library_for_Arduino, TCA9554, PNGdec
11_lvgl_example_v8LVGL example programGFX_Library_for_Arduino, TCA9554, lvgl, SensorLib
12_lvgl_pcf85063Display time and date using LVGLGFX_Library_for_Arduino, TCA9554, lvgl, SensorLib
13_lvgl_qmi8658Display IMU data using LVGLGFX_Library_for_Arduino, TCA9554, lvgl, SensorLib
14_lvgl_imageDisplay images using LVGLGFX_Library_for_Arduino, TCA9554, lvgl, SensorLib

01_audio_out

Example Description

  • This example demonstrates the ESP32-S3-Touch-LCD-3.5 reading an audio file from a TF card and playing it through a speaker, supporting MP3, AAC, WAV, and other formats.

Hardware Connection

  • Insert the TF card into the computer.
  • Create a new folder named music in the root directory of the TF card.
  • Copy the 1.mp3 file from the data folder of this project to the music folder on the TF card.
  • Insert the TF card into the ESP32-S3-Touch-LCD-3.5.

Code Analysis

  • Initialize

    Wire.begin(I2C_SDA, I2C_SCL);
    es8311_codec_init();
    SD_MMC.setPins(SD_MMC_CLK, SD_MMC_CMD, SD_MMC_D0);
    if (!SD_MMC.begin("/sdmmc", true, false, 20000))
    {
    esp_rom_printf("Card Mount Failed\n");
    while (1)
    {
    };
    }
    audio.setPinout(I2S_BCLK, I2S_LRCK, I2S_SDOUT,I2S_MCLK);
    audio.setVolume(21); // 0...21
  • Set the audio file to play

    audio.connecttoFS(SD_MMC, "music/1.mp3");

Operation Result

  • The device will play auido directly without showing content on the screen

02_axp2101_example

Example Description

  • This example demonstrates using XPowers to drive the AXP2101 and printing data via the serial port.

Hardware Connection

  • Connect the board to your computer via USB.

Code Analysis

  • Initialize

    bool result = power.begin(Wire, AXP2101_SLAVE_ADDRESS, i2c_sda, i2c_scl);

    if (result == false) {
    Serial.println("power is not online...");
    while (1) delay(50);
    }

Operation Result

  • The screen shows no output
  • Open the serial monitor

03_camera_web_server

Example Description

  • This example demonstrates how to drive the camera. After connecting to Wi‑Fi, the program creates a web server. Users simply enter the device's IP address in a browser to access it. The web page can display the camera image and supports settings such as resolution and mirroring.

Hardware Connection

  • Connect the board to your computer via USB.
  • Insert the OV5640 camera into the 24PIN interface on the board (not required for the version with a case).
  • Set Partition to Custom

Code Analysis

  • Define camera‑related pins

    #define PWDN_GPIO_NUM -1
    #define RESET_GPIO_NUM -1
    #define XCLK_GPIO_NUM 38
    #define SIOD_GPIO_NUM 8
    #define SIOC_GPIO_NUM 7

    #define Y9_GPIO_NUM 21
    #define Y8_GPIO_NUM 39
    #define Y7_GPIO_NUM 40
    #define Y6_GPIO_NUM 42
    #define Y5_GPIO_NUM 46
    #define Y4_GPIO_NUM 48
    #define Y3_GPIO_NUM 47
    #define Y2_GPIO_NUM 45
    #define VSYNC_GPIO_NUM 17
    #define HREF_GPIO_NUM 18
    #define PCLK_GPIO_NUM 41
  • Wi‑Fi SSID and password to connect to

    const char *ssid = "waveshare";
    const char *password = "12345678";
  • Start the server to begin providing an HTTP video stream

    startCameraServer();
    Serial.print("Camera Ready! Use 'http://");
    Serial.print(WiFi.localIP());
    Serial.println("' to connect");

Operation Result

  • Open the serial terminal; after connecting to Wi‑Fi, the IP address is shown.
  • Enter the IP address printed on the serial port in a browser (on the device that provides the hotspot).
  • Click Start Stream to see the camera image.

04_es8311_example

Example Description

  • This example demonstrates using the ESP32-S3-Touch-LCD-3.5 to drive the ES8311 audio codec, implementing audio recording and playback.

Hardware Connection

  • Connect the board to your computer via USB.

Code Analysis

  • Initialize

    Wire.begin(I2C_SDA, I2C_SCL);
    es8311_codec_init();
    setupI2S();
  • Record audio for 5 seconds and play back the recorded content

    wav_buffer = i2s.recordWAV(5, &wav_size);
    delay(1000);
    Serial.println("I2S playWAV");
    i2s.playWAV(wav_buffer, wav_size);

Operation Result

  • The screen shows no output.
  • Press the RST button on the ESP32-S3-Touch-LCD-3.5 to start audio recording; after 5 seconds, the recorded content is played back.

05_pcf85063_time

Example Description

  • This example demonstrates driving the PCF85063 on the ESP32-S3-Touch-LCD-3.5, setting the time/date and reading the time.

Hardware Connection

  • Connect the board to your computer via USB.

Code Analysis

  • Initialize

    if (!rtc.begin(Wire, PCF85063_SLAVE_ADDRESS, SENSOR_SDA, SENSOR_SCL))
    {
    Serial.println("Failed to find PCF8563 - check your wiring!");
    while (1) {
    delay(1000);
    }
    }
  • Set the time and date

    rtc.setDateTime(year, month, day, hour, minute, second);
  • Get the time and date

    RTC_DateTime datetime = rtc.getDateTime();

Operation Result

  • The screen shows no output.
  • Open the serial monitor

06_qmi8658_getdata

Example Description

  • This example demonstrates driving the QMI8658 on the ESP32-S3-Touch-LCD-3.5, obtaining and printing Accel, Gyro, and IMU temperature data.

Hardware Connection

  • Connect the board to your computer via USB.

Code Analysis

  • Initialize

    if (!qmi.begin(Wire, QMI8658_L_SLAVE_ADDRESS, SENSOR_SDA, SENSOR_SCL)) {
    Serial.println("Failed to find QMI8658 - check your wiring!");
    while (1) {
    delay(1000);
    }
    }
  • Get data

    if (qmi.getDataReady()) {
    if (qmi.getAccelerometer(acc.x, acc.y, acc.z)) {
    }
    if (qmi.getGyroscope(gyr.x, gyr.y, gyr.z)) {
    }
    }

Operation Result

  • The screen shows no output
  • Open the serial monitor

07_sd_card_test

Example Description

  • This example demonstrates testing TF card read/write functionality on the ESP32-S3-Touch-LCD-3.5.

Hardware Connection

  • Connect the board to your computer via USB.
  • Insert a TF card into the card slot (the TF card must be formatted as FAT32).

Code Analysis

  • Initialize

    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;
    }

Operation Result

  • Insert the TF card into the computer, and and two files, test.txt and foo.test, will appear. The content of the foo.txt is Hello World!, and the test.txt is empty.

08_gfx_helloworld

Example Description

  • This example demonstrates the ESP32-S3-Touch-LCD-3.5 using the GFX_Library_for_Arduino library to drive the screen and display "HelloWorld".

Hardware Connection

  • Connect the board to your computer via USB.

Code Analysis

  • Configure the screen interface and resolution, etc.

    Arduino_DataBus* bus = new Arduino_ESP32SPI(LCD_DC /* DC */, LCD_CS /* CS */, SPI_SCLK /* SCK */, SPI_MOSI /* MOSI */, SPI_MISO /* MISO */);
    Arduino_GFX* gfx = new Arduino_ST7796(
    bus, LCD_RST /* RST */, 0 /* rotation */, true, LCD_HOR_RES, LCD_VER_RES);

Operation Result

09_gfx_jpeg

Example Description

  • This example demonstrates the ESP32-S3-Touch-LCD-3.5 using the JPEGDEC library to decode a JPG file from the TF card and displaying the image using the GFX_Library_for_Arduino driver.

Hardware Connection

  • Insert the TF card into the computer.
  • Create a new folder named images in the root directory of the TF card.
  • Copy the octocat.jpg file from the data folder of this project to the images folder on the TF card.
  • Insert the TF card into the ESP32-S3-Touch-LCD-3.5.
  • Connect the board to your computer via USB.

Code Analysis

  • Decode the JPG file and display it

    jpegDraw(JPEG_FILENAME, jpegDrawCallback, true /* useBigEndian */,
    0 /* x */, 0 /* y */, gfx->width() /* widthLimit */, gfx->height() /* heightLimit */);

Operation Result

10_gfx_png

Example Description

  • This example demonstrates the ESP32-S3-Touch-LCD-3.5 using the PNGdec library to decode a PNG file from the TF card and displaying the image using the GFX_Library_for_Arduino driver.

Hardware Connection

  • Insert the TF card into the computer.
  • Create a new folder named images in the root directory of the TF card.
  • Copy the octocat.png and octocat-4bpp.png files from the data folder of this project to the images folder on the TF card.
  • Insert the TF card into the ESP32-S3-Touch-LCD-3.5.
  • Connect the board to your computer via USB.

Code Analysis

  • Decode the PNG file and display it

    rc = png.open(PNG_FILENAME, myOpen, myClose, myRead, mySeek, PNGDraw);
    if (rc == PNG_SUCCESS)
    {
    int16_t pw = png.getWidth();
    int16_t ph = png.getHeight();

    xOffset = (w - pw) / 2;
    yOffset = (h - ph) / 2;

    rc = png.decode(NULL, 0);

    Serial.printf("Draw offset: (%d, %d), time used: %lu\n", xOffset, yOffset, millis() - start);
    Serial.printf("image specs: (%d x %d), %d bpp, pixel type: %d\n", png.getWidth(), png.getHeight(), png.getBpp(), png.getPixelType());
    png.close();
    }

Operation Result

11_lvgl_example_v8

Example Description

  • This example demonstrates running the LVGL (v8.4.0) example program on the ESP32-S3-Touch-LCD-3.5.

Hardware Connection

  • Connect the board to your computer via USB.

Preparation

  • The lvgl v8.4.0 library needs to be installed. If another version is already installed, please reinstall it.

Code Analysis

  • UI initialization

    lv_obj_t *label = lv_label_create(lv_scr_act());
    lv_label_set_text(label, "Hello Arduino! (V" GFX_STR(LVGL_VERSION_MAJOR) "." GFX_STR(LVGL_VERSION_MINOR) "." GFX_STR(LVGL_VERSION_PATCH) ")");
    lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);

    lv_obj_t *sw = lv_switch_create(lv_scr_act());
    lv_obj_align(sw, LV_ALIGN_TOP_MID, 0, 50);

    sw = lv_switch_create(lv_scr_act());
    lv_obj_align(sw, LV_ALIGN_BOTTOM_MID, 0, -50);

Operation Result

  • Touch operation is supported.

12_lvgl_pcf85063

Example Description

  • This example demonstrates obtaining time and date data from the PCF85063 on the ESP32-S3-Touch-LCD-3.5 and displaying it using the LVGL library.

Hardware Connection

  • Connect the board to your computer via USB.

Preparation

  • The lvgl v8.4.0 library needs to be installed. If another version is already installed, please reinstall it.

Code Analysis

  • UI initialization

    void lvgl_pcf85063_ui_init(lv_obj_t *parent) {
    lv_obj_t *list = lv_list_create(parent);
    lv_obj_set_size(list, lv_pct(100), lv_pct(100));

    lv_obj_t *list_item = lv_list_add_btn(list, NULL, "data");
    label_data = lv_label_create(list_item);
    lv_label_set_text(label_data, "2025-01-01");

    list_item = lv_list_add_btn(list, NULL, "time");
    label_time = lv_label_create(list_item);
    lv_label_set_text(label_time, "00:00:00");

    pcf85063_timer = lv_timer_create(pcf85063_callback, 100, NULL);
    }

Operation Result

13_lvgl_qmi8658

Example Description

  • This example demonstrates obtaining QMI8658 data on the ESP32-S3-Touch-LCD-3.5 and displaying it using the LVGL library.

Hardware Connection

  • Connect the board to your computer via USB.

Preparation

  • The lvgl v8.4.0 library needs to be installed. If another version is already installed, please reinstall it.

Code Analysis

  • UI initialization

    void lvgl_qmi8658_ui_init(lv_obj_t *parent) {
    lv_obj_t *list = lv_list_create(parent);
    lv_obj_set_size(list, lv_pct(100), lv_pct(100));

    lv_obj_t *list_item = lv_list_add_btn(list, NULL, "accel_x");
    label_accel_x = lv_label_create(list_item);
    lv_label_set_text(label_accel_x, "0.00");

    list_item = lv_list_add_btn(list, NULL, "accel_y");
    label_accel_y = lv_label_create(list_item);
    lv_label_set_text(label_accel_y, "0.00");

    list_item = lv_list_add_btn(list, NULL, "accel_z");
    label_accel_z = lv_label_create(list_item);
    lv_label_set_text(label_accel_z, "0.00");

    list_item = lv_list_add_btn(list, NULL, "gyro_x");
    label_gyro_x = lv_label_create(list_item);
    lv_label_set_text(label_gyro_x, "0.00");

    list_item = lv_list_add_btn(list, NULL, "gyro_y");
    label_gyro_y = lv_label_create(list_item);
    lv_label_set_text(label_gyro_y, "0.00");

    list_item = lv_list_add_btn(list, NULL, "gyro_z");
    label_gyro_z = lv_label_create(list_item);
    lv_label_set_text(label_gyro_z, "0.00");

    list_item = lv_list_add_btn(list, NULL, "temp");
    label_temp = lv_label_create(list_item);
    lv_label_set_text(label_temp, "0.00C");

    qmi8658_timer = lv_timer_create(qmi8658_callback, 100, NULL);
    }

Operation Result

14_lvgl_image

Example Description

  • This example demonstrates the ESP32-S3-Touch-LCD-3.5 using LVGL to display images from a TF card, supporting image formats such as jpg, bmp, png, and bin.

Hardware Connection

  • Insert the TF card into the computer.
  • Create a new folder named images in the root directory of the TF card.
  • Copy all the files from the data folder of this project to the images folder on the TF card
  • Insert the TF card into the ESP32-S3-Touch-LCD-3.5.
  • Connect the board to your computer via USB.

Preparation

  • The lvgl v8.4.0 library needs to be installed. If another version is already installed, please reinstall it.

Code Analysis

  • Set the image to be displayed

    lv_obj_t *img = lv_img_create(lv_scr_act());
    lv_obj_align(img, LV_ALIGN_CENTER, 0, 0);
    // lv_img_set_src(img, "S:images/octocat.jpg");
    lv_img_set_src(img, "S:images/octocat.png");

Operation Result