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
Please refer to the tutorial Installing and Configuring Arduino IDE to download and install the Arduino IDE and add ESP32 support.
2. Installing Libraries
To run the example, you need to install the corresponding library.
The example program package for the ESP32-C6-LCD-0.85 development board can be downloaded from here. The Arduino\libraries directory within this package contains all the necessary library files required for this tutorial.
| Library or File Name | Description | Version | Installation Method |
|---|---|---|---|
| lvgl | LVGL graphics library | v8.4.0 or v9.3.0 | Via Library Manager or manual install |
| GFX_Library_for_Arduino | GFX graphics library | v1.6.0 | Via Library Manager or manual install |
| U8g2 | Graphics display library | v2.35.30 | Via Library Manager or manual install |
| FastLED | RGB LED driver library | v3.10.1 | Via Library Manager or manual install |
| ESP32-audioI2S-master | Audio processing library | v3.4.0 | Via Library Manager or manual install |
| OneButton | Button library | v2.6.1 | Via Library Manager or manual install |
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.
Installation Steps:
-
Extract the downloaded example package.
-
Copy all folders (ESP32-audioI2S-master, GFX_Library_for_Arduino, etc.) from its
Arduino\librariesdirectory to the Arduino libraries folder.infoThe path to the Arduino libraries folder is typically:
c:\Users\<username>\Documents\Arduino\libraries.You can also locate it in the Arduino IDE by going to File > Preferences and checking the "Sketchbook location". The libraries folder is the
librariessubfolder within this path. -
For other installation methods, please refer to: Arduino Library Management Tutorial.
Required Board Installation Instructions for ESP32-C6-LCD-0.85
| Board Name | Installation Requirement | Version Requirement |
|---|---|---|
| ESP32 by Espressif Systems | "Install Offline" / "Install Online" | 3.2.0 |
3. Other Tips
For the ESP32-C6-LCD-0.85, you need to select and configure the board.

- Select the ESP32C6 Dev Module for ESP32-C6-LCD-0.85.
- Select the USB port.
- The ESP32-C6-LCD-0.85 uses the ESP32-C6 native USB interface, not a UART-to-USB bridge. For serial communication:
-
The
printf()function can be used directly; -
To use the
Serial.println()function, additional configuration is required: Enable the "USB CDC On Boot" option in the IDE's Tools menu, or declare anHWCDCobject in your code to handle USB serial communication.
-
- Select 8MB Flash
- Select a Partition Table of the appropriate size
Example
The Arduino examples are located in the Arduino/examples directory of the example package.
| Example | Basic Description | Dependency Library |
|---|---|---|
| 01_audio_out | Read audio files from TF card and play them | ESP32-audioI2S-master |
| 02_button_example | Button test | OneButton |
| 03_ws2812b_example | Test RGB LED | FastLED |
| 04_gfx_helloworld | Display HelloWorld on the screen | GFX_Library_for_Arduino |
| 05_esp_wifi_analyzer | Display WiFi signal strength on the screen | GFX_Library_for_Arduino |
| 06_gfx_u8g2_font | Display text in multiple languages by loading fonts | GFX_Library_for_Arduino, U8g2 |
| 07_sd_card_test | Test TF card read/write | --- |
| 08_lvgl_example_v8 | lvgl v8.4.0 example | GFX_Library_for_Arduino, lvgl |
| 09_lvgl_example_v9 | lvgl v9.3.0 example | GFX_Library_for_Arduino, lvgl |
01_audio_out
This example demonstrates the ESP32-C6-LCD-0.85 playing audio through a speaker; the screen shows no output.
Code Analysis
- Set I2S pins:
void setupI2S() {i2s.setPins(I2S_BCK_PIN, I2S_LRCK_PIN, I2S_DOUT_PIN, I2S_DIN_PIN, I2S_MCK_PIN);// Initialize the I2S bus in standard modeif (!i2s.begin(I2S_MODE_STD, EXAMPLE_SAMPLE_RATE, I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_MONO, I2S_STD_SLOT_LEFT)) {Serial.println("Failed to initialize I2S bus!");return;}}
- Set the audio data to be played:
i2s.write((uint8_t *)audio_data, AUDIO_SAMPLES * 2);
Operation Result
- The device will play auido directly without showing content on the screen
02_button_example
This example demonstrates how to use the OneButton library to read button states such as single click, double click, and long press, and print them via the serial monitor.
Code Analysis
-
Bind callback functions:
button1.attachClick(click1);button1.attachDoubleClick(doubleclick1);button1.attachLongPressStart(longPressStart1);button1.attachLongPressStop(longPressStop1);button1.attachDuringLongPress(longPress1);
Operation Result
- The screen shows no output
- Button information is printed to the serial monitor

03_ws2812b_example
This example uses the FastLED library to drive the ws2812b RGB LED on the ESP32-C6-LCD-0.85, changing to a random color every 500ms.
Code Analysis
-
Initialize ws2812b and set brightness:
FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS); // GRB ordering is typicalFastLED.setBrightness(100); // 0-255
Operation Result
- The screen shows no output
- The RGB LED changes to a random color every 500ms

04_gfx_helloworld
This example demonstrates the ESP32-C6-LCD-0.85 using the GFX_Library_for_Arduino library to drive the screen and display "HelloWorld" on the screen.
Code Analysis
- Configure the screen interface and screen resolution, etc.
Arduino_DataBus *bus = new Arduino_HWSPI(3 /* DC */, 5 /* CS */, 1 /* SCK */, 2/* MOSI */, GFX_NOT_DEFINED /* MISO */);Arduino_GFX *gfx = new Arduino_ST7735(bus, 4 /* RST */, 0 /* rotation */, true /* IPS */,128 /* width */, 128 /* height */,2 /* col offset 1 */, 3 /* row offset 1 */);
Operation Result
- The screen displays as follows:

05_esp_wifi_analyzer
This example demonstrates the ESP32-C6-LCD-0.85 using a GFX_Library_for_Arduino library to display the signal strength of the WiFi band
Operation Result
- The screen displays as follows:

06_gfx_u8g2_font
This example demonstrates how ESP32-C6-LCD-0.85 uses GFX_Library_for_Arduino libraries to load font libraries to display them in various languages
Operation Result
- The screen displays as follows:

07_sd_card_test
This example tests the TF card read/write functionality on the ESP32-C6-LCD-0.85.
Code
07_sd_card_test.ino
#include "FS.h"
#include "SD_MMC.h"
int clk = 16;
int cmd = 15;
int d0 = 17;
int d1 = 18;
int d2 = 13;
int d3 = 14;
void listDir(fs::FS &fs, const char *dirname, uint8_t levels) {
Serial.printf("Listing directory: %s\n", dirname);
File root = fs.open(dirname);
if (!root) {
Serial.println("Failed to open directory");
return;
}
if (!root.isDirectory()) {
Serial.println("Not a directory");
return;
}
File file = root.openNextFile();
while (file) {
if (file.isDirectory()) {
Serial.print(" DIR : ");
Serial.println(file.name());
if (levels) {
listDir(fs, file.path(), levels - 1);
}
}else{
Serial.print(" FILE: ");
Serial.print(file.name());
Serial.print(" SIZE: ");
Serial.println(file.size());
}
file = root.openNextFile();
}
}
void createDir(fs::FS &fs, const char *path) {
Serial.printf("Creating Dir: %s\n", path);
if (fs.mkdir(path)) {
Serial.println("Dir created");
}else{
Serial.println("mkdir failed");
}
}
void removeDir(fs::FS &fs, const char *path) {
Serial.printf("Removing Dir: %s\n", path);
if (fs.rmdir(path)) {
Serial.println("Dir removed");
}else{
Serial.println("rmdir failed");
}
}
void readFile(fs::FS &fs, const char *path) {
Serial.printf("Reading file: %s\n", path);
File file = fs.open(path);
if (!file) {
Serial.println("Failed to open file for reading");
return;
}
Serial.print("Read from file: ");
while (file.available()) {
Serial.write(file.read());
}
}
void writeFile(fs::FS &fs, const char *path, const char *message) {
Serial.printf("Writing file: %s\n", path);
File file = fs.open(path, FILE_WRITE);
if (!file) {
Serial.println("Failed to open file for writing");
return;
}
if (file.print(message)) {
Serial.println("File written");
}else{
Serial.println("Write failed");
}
}
void appendFile(fs::FS &fs, const char *path, const char *message) {
Serial.printf("Appending to file: %s\n", path);
File file = fs.open(path, FILE_APPEND);
if (!file) {
Serial.println("Failed to open file for appending");
return;
}
if (file.print(message)) {
Serial.println("Message appended");
}else{
Serial.println("Append failed");
}
}
void renameFile(fs::FS &fs, const char *path1, const char *path2) {
Serial.printf("Renaming file %s to %s\n", path1, path2);
if (fs.rename(path1, path2)) {
Serial.println("File renamed");
}else{
Serial.println("Rename failed");
}
}
deleteFile(fs::FS &fs, const char *path) {
Serial.printf("Deleting file: %s\n", path);
if (fs.remove(path)) {
Serial.println("File deleted");
}else{
Serial.println("Delete failed");
}
}
void testFileIO(fs::FS &fs, const char *path) {
File file = fs.open(path);
static uint8_t buf[512];
size_t len = 0;
uint32_t start = millis();
uint32_t end = start;
if (file) {
len = file.size();
size_t flen = len;
start = millis();
while (len) {
size_t toRead = len;
if (toRead > 512) {
toRead = 512;
}
file.read(buf, toRead);
len -= toRead;
}
end = millis() - start;
Serial.printf("%u bytes read for %lu ms\n", flen, end);
file.close();
}else{
Serial.println("Failed to open file for reading");
}
file = fs.open(path, FILE_WRITE);
if (!file) {
Serial.println("Failed to open file for writing");
return;
}
size_t i;
start = millis();
for (i = 0; i < 2048; i++) {
file.write(buf, 512);
}
end = millis() - start;
Serial.printf("%u bytes written for %lu ms\n", 2048 * 512, end);
file.close();
}
void setup() {
Serial.begin(115200);
delay(3000);
if (!SD_MMC.setPins(clk, cmd, d0, d1, d2, d3)) {
Serial.println("Pin change failed!");
return;
}
if (!SD_MMC.begin()) {
Serial.println("Card Mount Failed");
return;
}
uint8_t cardType = SD_MMC.cardType();
if (cardType == CARD_NONE) {
Serial.println("No SD_MMC card attached");
return;
}
Serial.print("SD_MMC Card Type: ");
if (cardType == CARD_MMC) {
Serial.println("MMC");
} else if (cardType == CARD_SD) {
Serial.println("SDSC");
} else if (cardType == CARD_SDHC) {
Serial.println("SDHC");
}else{
Serial.println("UNKNOWN");
}
uint64_t cardSize = SD_MMC.cardSize() / (1024 * 1024);
Serial.printf("SD_MMC Card Size: %lluMB\n", cardSize);
listDir(SD_MMC, "/", 0);
createDir(SD_MMC, "/mydir");
listDir(SD_MMC, "/", 0);
removeDir(SD_MMC, "/mydir");
listDir(SD_MMC, "/", 2);
writeFile(SD_MMC, "/hello.txt", "Hello ");
appendFile(SD_MMC, "/hello.txt", "World!\n");
readFile(SD_MMC, "/hello.txt");
deleteFile(SD_MMC, "/foo.txt");
renameFile(SD_MMC, "/hello.txt", "/foo.txt");
readFile(SD_MMC, "/foo.txt");
testFileIO(SD_MMC, "/test.txt");
Serial.printf("Total space: %lluMB\n", SD_MMC.totalBytes() / (1024 * 1024));
Serial.printf("Used space: %lluMB\n", SD_MMC.usedBytes() / (1024 * 1024));
}
void loop() {
delay(10);
}
Code Analysis
-
TF card initialization:
if (!SD_MMC.setPins(clk, cmd, d0, d1, d2, d3)) {Serial.println("Pin change failed!");return;}if (!SD_MMC.begin()) {Serial.println("Card Mount Failed");return;}
Operation Result
- The screen shows no output
- Open the serial monitor

08_lvgl_example_v8
This example demonstrates how to run the lvgl examples (v8.4.0) on the ESP32-C6-LCD-0.85.
-
It is required to install lvgl v8.4.0 version. If you have installed other version, please reinstall.

Operation Result
- The screen displays as follows:

09_lvgl_example_v9
This example demonstrates how to run the lvgl (v9.3.0) examples on the ESP32-C6-LCD-0.85.
-
It is required to install lvgl v9.3.0 version. If you have installed other version, please reinstall.

Operation Result
- The screen displays as follows: