Skip to main content

Working with Arduino

This chapter includes the following sections, please read as needed:

Arduino Getting Started Tutorial

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

Please refer to the tutorial Installing and Configuring Arduino IDE Tutorial 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 file.
  • For most libraries, users can easily search and install them through the online Library Manager in the Arduino software. However, some open-source libraries or custom libraries are not synchronized to the Arduino Library Manager, so they cannot be acquired through online searches. In this case, users can only manually install these libraries offline. You can click this link to download the demo package for the ESP32-C6-LCD-1.3 board from the Arduino directory. The Arduino\libraries directory within the package already includes all the library files required for this tutorial.
Library/File NameDescriptionVersionInstallation Method
Adafruit_GFX_LibraryLow-level graphics rendering libraryv1.11.9Install via library manager or manually
Arduino_GFXDisplay driver graphics library supporting ST7789 chipv1.4.9Install via library manager or manually
ArduinoJsonLightweight JSON parsing/generation libraryv6.21.2Install via library manager or manually
lvglLVGL display frameworkv8.3.10Install via library manager or manually
FastLEDAddressable LED control libraryv3.10.3Install via library manager or manually
JPEGDECJPEG image decoding libraryv1.6.1Install via library manager or manually
PNGdecPNG image decoding libraryv1.0.2Install via library manager or manually
TimeBasic time handling library1.6.1Install via library manager or manually
TJpg_DecoderUltra-lightweight JPEG decoding library1.0.8Install via library manager or manually
Version Compatibility Description

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 stable reproduction of the examples, it is recommended to use the specific versions listed in the table above. Mixing different library versions may cause compilation failures or runtime exceptions.

Installation Steps:

  1. Download the demo package.

  2. Copy all folders (Arduino_DriveBus, GFX_Library_for_Arduino, etc.) in the Arduino\libraries directory to the Arduino library folder.

    info

    The path to the Arduino libraries folder is typically: c:\Users\<Username>\Documents\Arduino\libraries.

    You can also locate it within the Arduino IDE via File > Preferences, by checking the "Sketchbook location". The library folder is the libraries folder under this path.

  3. For other installation methods, please refer to: Arduino Library Management Tutorial.

3. Installing ESP32 Development Board

  • To use ESP32-related boards in the Arduino IDE, you must first install the board package "esp32 by Espressif Systems".
  • According to board installation requirement''', it is generally recommended to use '''Install Online'''. If online installation fails, use '''Install Offline'''.
  • For the installation tutorial, please refer to Arduino Board Management Tutorial

Required Board Installation Instructions for ESP32-C6-LCD-1.3

Board NameInstallation RequirementVersion Requirement
ESP32 by Espressif Systems"Install Offline" / "Install Online”3.0.1

Demo

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

DemoBasic Program DescriptionDependency Library
01_LVGL_ArduinoDemonstrates basic graphics library functions, hardware parameter detection, and displayFastLED, lvgl
02_LVGL_WeatherClockDemonstrates basic graphics library functions, can also be used to test basic display performance and random text display effectsGFX_Library_for_Arduino, Arduino_DriveBus, Adafruit_XCA9554
03_Video_demoPrints ASCII characters in rows and columns on the display according to the screen sizeGFX_Library_for_Arduino

ESP32-C6-LCD-1.3 Model Selection

01_LVGL_Arduino

Demo Description

  • This example demonstrates displaying hardware information (Flash/TF card capacity, number of scanned wireless devices) through an LVGL graphical interface.

Hardware Connection

  • Connect the development board to the computer

Code Analysis

  • setup() function:
    • Flash_test(): Detects the ESP32 Flash chip capacity and assigns it to the global variable Flash_Size.
    • LCD_Init(): Initializes the ST7789 display (configures SPI, screen commands, backlight, etc.).
    • Lvgl_Init(): Initializes the LVGL graphics library, binds the ST7789 display refresh function, creates a basic LVGL display buffer, and registers touch (placeholder) and display drivers.
    • SD_Init(): Initializes the TF card, detects the card type, calculates the total capacity, and assigns it to SDCard_Size.
    • Lvgl_Example1(): Creates the LVGL interface (Onboard parameter panel), initializes WS2812B and the waterfull light / button.
    • Wireless_Test2(): Creates the FreeRTOS task WirelessScanTask, which runs in the background on core 0 to scan for WiFi/BLE devices, and stores the results in WIFI_NUM / BLE_NUM.
  • loop() function:
    • Timer_Loop(): Calls the LVGL core timer handler lv_timer_handler() to maintain interface refresh and normal execution of timers (such as button detection, waterfull light, parameter refresh).
    • delay(5): A simple delay to ensure LVGL refresh rate.

Operation Result

02_LVGL_WeatherClock

Demo Description

  • This example demonstrates a weather clock system, presenting weather clock functionality on the ST7789 display while optimizing for smooth operation and CPU resource usage.

Hardware Connection

  • Connect the development board to the computer

Code Analysis

  • setup function:
    • Serial Initialization: Enables serial communication at 115200 baud for system log printing, facilitating debugging.
    • Hardware/Driver Initialization: Executes Flash test, ST7789 display initialization, LVGL graphics library initialization, and TF card initialization in sequence.
    • Peripheral Configuration: Sets the display backlight to 100% and initializes the weather clock business logic.
    • Log Output: Provides initialization progress feedback via serial, facilitating troubleshooting of startup anomalies.
  • loop function:
    • LVGL Core Processing: Calls Timer_Loop to ensure LVGL timers and animations update normally.
    • Business Logic Loop: Executes WeatherClock_Loop to handle real-time data updates and display logic for the weather clock.
    • Resource Optimization: Retains only a 1ms delay, avoiding excessive CPU usage while ensuring high-frequency LVGL scheduling, balancing smoothness and resource consumption.

Operation Result

03_Video_demo

Demo Description

  • This example demonstrates TF card detection and video multimedia playback.

Hardware Connection

  • Connect the development board to the computer

Code Analysis

  • setup() function:
    • Hardware Initialization: Completes Flash test, ST7789 display initialization, backlight setting, and WS2812B LED strip initialization in sequence.
    • RGB Self-Test: Sequentially displays red/green/blue colors simultaneously on the screen and LED strip, holding each for 1 second before turning off the LED strip.
    • TF Card Detection: Identifies the TF card type. If no card is found, an error message is displayed on the screen and subsequent processes are terminated. If a card is present, it checks for video files. If a video file exists, the video playback module is initialized.
  • loop() function:
    • Fallback Logic: If no TF card is detected, only delays in the loop without executing any playback operations.
    • Playback Branch: If the video module is initialized, calls Video_Play_Loop() to play the video in a loop.

Operation Result