Skip to main content

Working with Arduino

This section describes the environment setup, upload steps, and expected results of the Arduino examples. Prepare the board and a USB Type-C cable that supports data transfer, and download the ESP32-P4-Knob-Touch-AMOLED-1.75 Examples.

This chapter includes 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.

Set Up the Development Environment​

1. Install Arduino IDE and the Board Support Package​

Refer to Install and Configure Arduino IDE to install the IDE. In "File" > "Preferences", add the following URL to "Additional boards manager URLs":

https://espressif.github.io/arduino-esp32/package_esp32_index.json

Open the Boards Manager and install esp32 by Espressif Systems 3.3.12.

Development Environment Version

The Arduino examples are located in examples/arduino/examples and are built with Arduino-ESP32 3.3.12. The display examples use the bundled LVGL 9.5.0. The KnobWireless library contains a precompiled ESP32-P4 runtime for this core version, so the Wi-Fi and Bluetooth sketches do not require an ESP-IDF installation.

2. Configure the Example Libraries​

The libraries and configuration file required by the examples are provided in examples/arduino/libraries:

Library or FileDescriptionVersion
board_configPin definitions of the board1.0.0
board_displayCO5300 MIPI-DSI display and CST9217 touch support1.0.0
board_audioES8389 playback and ES7210 microphone capture support1.0.0
board_bt_playerBluetooth A2DP PCM playback support1.0.0
KnobWirelessWi-Fi and Bluetooth support through the ESP32 wireless coprocessor, including a precompiled ESP32-P4 archive1.0.0
lvglGraphics library9.5.0
lv_conf.hLVGL configuration fileProvided with the examples

Use either of the following methods so that Arduino IDE can find these libraries:

  • Set "Sketchbook location" in "File" > "Preferences" to the examples/arduino folder of the downloaded repository, then restart Arduino IDE. The IDE loads the libraries from examples/arduino/libraries.
  • Copy all contents of examples/arduino/libraries, including lv_conf.h and KnobWireless, to the libraries folder of your current sketchbook location.
examples/arduino/
├── examples/
│ ├── 01_system_info/
│ ├── ...
│ └── 16_a2dp_sink/
└── libraries/
├── board_audio/
├── board_bt_player/
├── board_config/
├── board_display/
├── KnobWireless/
├── lvgl/
└── lv_conf.h
Library Version Compatibility

Keep lv_conf.h alongside the lvgl folder, and do not install other LVGL versions at the same time, so that the compiler does not select a different library. Keep the complete KnobWireless folder; its precompiled archive matches Arduino-ESP32 3.3.12.

3. Select Project Parameters​

Configure the following options in the "Tools" menu:

OptionSetting
BoardESP32P4 Dev Module
Chip Variantv3.00 or newer
Flash Size32MB (256Mb)
PSRAMEnabled
Partition Scheme32M Flash (13MB APP/6.75MB SPIFFS)
USB CDC On BootDisabled (default)
PortThe serial port of the USB-to-UART connection
Serial Monitor Baud Rate115200

Keep USB CDC On Boot disabled. Serial then uses UART0 (GPIO37 TXD, GPIO38 RXD), which is connected to the onboard CH343P USB-to-UART chip. If it is enabled, Serial output is sent to the USB peripheral instead of this serial port.

If no serial port appears, flip the USB Type-C plug at the board end; flipping the plug powers the board up again.

4. Compile and Upload​

  1. From examples/arduino/examples, open the .ino file with the same name inside the desired example folder.
  2. Click "Verify" to compile. After compilation succeeds, click "Upload".
  3. After uploading, open the serial monitor and set the baud rate to 115200.
  4. Check the screen or the serial output as described in Example Programs.

If the upload cannot connect, close other programs that use the serial port and try again. If the problem persists, hold BOOT, power on the board again, and then release BOOT to enter download mode.

To use Arduino CLI, run the following commands in the repository root directory. Replace COM5 with the actual serial port:

arduino-cli core update-index --additional-urls https://espressif.github.io/arduino-esp32/package_esp32_index.json
arduino-cli core install esp32:esp32@3.3.12 --additional-urls https://espressif.github.io/arduino-esp32/package_esp32_index.json
arduino-cli compile --fqbn esp32:esp32:esp32p4:ChipVariant=postv3,FlashSize=32M,PartitionScheme=app13M_data7M_32MB,PSRAM=enabled --libraries examples/arduino/libraries examples/arduino/examples/11_display_touch
arduino-cli upload -p COM5 --fqbn esp32:esp32:esp32p4:ChipVariant=postv3,FlashSize=32M,PartitionScheme=app13M_data7M_32MB,PSRAM=enabled examples/arduino/examples/11_display_touch

After a basic example is flashed, the board runs that example. To restore the factory APPs, flash the factory firmware.

Example Programs​

Each example folder contains an .ino entry file with the same name as the folder.

ExampleBasic DescriptionView Results
01_system_infoChip, Flash, PSRAM, and heap informationSerial port
02_buttonsBOOT and PWR button press and release eventsSerial port
03_wifiWi-Fi access point scanSerial port
04_bluetoothBLE advertisement scanSerial port
05_axp2101Read-only AXP2101 power statusSerial port
06_sd_cardTF card mount and temporary-file verificationSerial port
07_limit_switchesKnob direction switch countingSerial port
08_motor_driveTimed vibration motor pulseVibration motor, serial port
09_rtcPCF85063 RTC time readingSerial port
10_qmi8658QMI8658 acceleration readingSerial port
11_display_touchDisplay color test and touch drawingScreen
12_mic_spectrumDual-microphone spectrumScreen
13_speaker_outputSpeaker test toneSpeaker, serial port
14_usb_displayUSB display and HID touch for WindowsScreen, computer
15_lvgl_demo_v9LVGL v9 benchmarkScreen, serial port
16_a2dp_sinkBluetooth A2DP audio receiver with knob volume controlScreen, speaker

01_system_info​

Prints the ESP32-P4 chip model and revision, CPU frequency, Flash size, PSRAM size, and available heap through the serial port.

Expected result: the serial monitor prints a system information report after boot and then every 5 seconds. The Flash and PSRAM sizes are not zero when PSRAM is enabled in the board options.

02_buttons​

Reads the BOOT (GPIO35) and PWR (GPIO2) buttons with a 30 ms debounce interval and keeps a separate press count for each button. BOOT reads LOW when pressed. PWR reads HIGH when pressed, because GPIO2 is driven through an onboard BSS138 inverter.

Expected result: the serial monitor prints the initial state of each button. Pressing and releasing a button prints the transition and the updated press count.

03_wifi​

Scans nearby Wi-Fi access points through the ESP32 wireless coprocessor. The sketch does not connect to a network.

Expected result: the serial monitor reports a successful scan and prints up to ten access points with SSID, RSSI, channel, and authentication mode. Hidden networks are shown as <hidden>.

04_bluetooth​

Scans Bluetooth LE advertisements once for ten seconds through the ESP32 wireless coprocessor. The sketch does not connect to devices and does not provide Classic Bluetooth serial or GATT functions.

Expected result: when the scan ends, the serial monitor prints the advertisement count, the number of unique devices, and up to ten devices with the strongest signal. Devices without an advertising name are shown as <unnamed>.

05_axp2101​

Reads the power, battery, charging, and temperature status of the AXP2101. The sketch does not change PMU, charging, or regulator settings.

Expected result: the serial monitor prints the PMU ID and the enabled ADC measurements once per second. A disabled ADC channel is shown as N/A(disabled); the sketch does not enable it.

06_sd_card​

Mounts the TF card in 1-bit SDMMC mode at 10 MHz, reports the card and file system capacity, creates a temporary file, reads it back, deletes it, and unmounts the card.

Expected result: the serial monitor reports the 1-bit 10 MHz configuration, the capacity, a successful write, read, and delete verification, and the unmount.

This example does not format the card or modify existing files. If writing fails, the example stops without deleting the temporary file; check the card before running it again.

07_limit_switches​

Reads the clockwise (GPIO20) and counterclockwise (GPIO21) direction switches of the knob with a 2 ms debounce interval, and keeps a separate count for each direction.

Expected result: turning the knob prints a CW or CCW trigger message and increases the count of that direction.

The two inputs are independent active-low switches. Do not configure them as a quadrature encoder.

08_motor_drive​

Drives the vibration motor through the DRV8837 with serial commands.

Expected result: send v in the serial monitor to start one vibration pulse; the motor stops after 400 ms. Send s to stop it immediately. Sending v again during a pulse does not extend its timeout.

09_rtc​

Reads the PCF85063 time and status once per second, validates the BCD date, and reports the RTC interrupt level. The sketch never writes the RTC time.

Expected result: the serial monitor prints the RTC date and time, the oscillator-stop state, and the interrupt level. Invalid BCD data and I2C read failures are reported before the next read.

10_qmi8658​

Initializes the QMI8658 accelerometer at ±8 g and 250 Hz, then prints the X, Y, and Z acceleration and both interrupt levels. The sketch tries the I2C addresses 0x6B and 0x6A and expects the device ID 0x05.

Expected result: the serial monitor reports the detected IMU address, and the acceleration values change when the board is moved.

11_display_touch​

Initializes the CO5300 MIPI-DSI display and the CST9217 touch controller.

Expected result: the screen shows red, green, and blue for about 2 seconds each, then opens a white drawing page. Press and drag to draw continuous lines across the touch area, including the edges. Tap Clear to erase the canvas.

12_mic_spectrum​

Captures ES7210 MIC1 and MIC2 input at 16 kHz and shows a 512-point FFT spectrum, RMS level, and peak level on the screen.

Expected result: the 32 spectrum bars change with nearby sound. The bars use an additional 24 dB of display gain to show quiet sounds; the RMS and peak values describe the original input level. The speaker amplifier remains off.

13_speaker_output​

Configures the ES8389 DAC and the NS4150B amplifier, then alternates a three-second 1 kHz stereo tone with three seconds of digital silence.

Expected result: the serial monitor prints key ES8389 register values, and the speaker alternates between the tone and silence. The amplifier is enabled only during tone playback.

14_usb_display​

Receives 466 × 466 JPEG frames from the Espressif USB display driver for Windows through the ESP32-P4 high-speed USB port, and returns touch events to the computer as a HID touch screen.

Operation: install the Espressif USB Display Driver for Windows on a Windows 10 or Windows 11 computer. After uploading, connect the board in the USB 2.0 plug orientation instead of the USB-to-UART orientation.

Expected result: Windows recognizes a 466 × 466 display device. The board shows the content sent by the computer and sends touch reports back to it.

15_lvgl_demo_v9​

Runs the LVGL v9 benchmark on the full 466 × 466 round display, with CST9217 touch input registered in LVGL.

Expected result: the screen shows the benchmark scenes and then the summary screen. When the benchmark completes, the serial monitor reports the number of valid scenes and the average FPS.

16_a2dp_sink​

Starts a Bluetooth A2DP sink named Knob_BT_INO. Received 16-bit mono or stereo PCM audio is played through the ES8389 DAC and the speaker amplifier.

Operation: pair a phone or another Bluetooth audio source with Knob_BT_INO and start playback.

Expected result: the round screen shows the device name, Bluetooth and audio status, received sample format, and current volume. The DAC and amplifier are enabled when PCM playback begins. Turn the knob to adjust the volume.

Troubleshooting​

  • Library files not found: check that the sketchbook location points to examples/arduino, or that all contents of examples/arduino/libraries have been copied to the current sketchbook libraries folder. Restart Arduino IDE after changing the sketchbook location.
  • LVGL compilation errors: use the bundled LVGL 9.5.0 and lv_conf.h, and remove other LVGL versions from the sketchbook libraries folder.
  • Wi-Fi or Bluetooth sketches fail to compile or link: use Arduino-ESP32 3.3.12 and keep the complete KnobWireless library, including its precompiled archive.
  • Black screen or initialization failure: confirm that PSRAM is enabled and that the Flash size and partition scheme match Select Project Parameters. The sensor and control examples report through the serial port only and do not light up the screen.
  • No serial output: connect the USB-to-UART plug orientation, select the corresponding port, and set the baud rate to 115200.

For more questions, see the ESP32-P4-Knob-Touch-AMOLED-1.75 FAQ.