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-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\libraries directory within the package already contains all the library files required for this tutorial.
Library/File NameDescriptionVersionInstallation Method
LVGLGraphics Libraryv8.4.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_TestRead the current system voltage value-
02_I2C_QMI8658Print the raw data from the IMU-
03_SD_CardLoad and display TF card information-
04_WIFI_APSet to AP mode, can obtain the MAC address of connected devices-
05_WIFI_STASet to STA mode to connect to WiFi and obtain an IP address-
06_LVGL_TestLVGL demoLVGL

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.

    ESP32-C6-Touch-AMOLED-1.64.webp

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.

    ESP32-C6-Touch-AMOLED-1.64.webp

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:

    ESP32-C6-Touch-AMOLED-1.64.webp

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 ssid and password in the 05_WIFI_AP.ino file. Then mobile phones or other devices in STA mode can use this ssid and password to 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:

    ESP32-C6-Touch-AMOLED-1.64.webp

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 (via ssid and password). 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.

    ESP32-C6-Touch-AMOLED-1.64.webp

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_90 in the lcd_bsp.c file 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:

    ESP32-C6-Touch-AMOLED-1.64.webp