Skip to content

CrowPanel Advanced 7/9/10.1inch ESP32-P4 HMI AI Voice Chat Robot

Introduction

In this example, we’ll walk through the process step by step to show how to configure an AI voice chat robot on the Elecrow P4 HMI.

To enable voice conversations, the system needs three essential hardware components:

  1. A display to show the user interface
  2. A microphone to capture voice input
  3. A speaker to play back the AI’s responses

In this lesson, we’ll configure each of these components, including the display output, audio input, and audio output settings. These configurations will provide the foundation needed to build a complete AI voice interaction system.


Learning Goals

  1. Understand how an AI voice chat robot works
  2. Learn how to configure the display on the Elecrow P4 HMI
  3. Learn how to configure the microphone on the Elecrow P4 HMI
  4. Learn how to configure the speaker on the Elecrow P4 HMI
  5. Learn how to configure Wi-Fi on the Elecrow P4 HMI

Preview of the Result

ai-11

After uploading the code, you can wake up the AI robot using a predefined wake word and start having a conversation with it.

For detailed instructions, please refer to the P4 HMI AI Case User Guide.


Hardware Used in This Lesson

ai-22

ai-222

ai-2222

AI Voice Chat Robot


Download the Code

Before diving into the code explanation, you can download the complete project first.

Full project download link: https://drive.google.com/file/d/1mGSaZ-9NiI8-cwcbhZgRR8-os7AhnqYb/view?usp=sharing


Key Code Explanation

Now let’s go through the AI Voice Chat Robot example.

In the project directory, navigate to:

main → boards → elecrow-p4-board

Open the file:

config.h

This file is the main configuration file for the Elecrow P4 development board. Below is an explanation of the key configuration settings.


Audio Configuration

#define AUDIO_INPUT_SAMPLE_RATE  16000
#define AUDIO_OUTPUT_SAMPLE_RATE 16000

Both the audio input sampling rate and audio output sampling rate are set to 16,000 Hz.


I2S Audio Pin Configuration

#define AUDIO_I2S_GPIO_MCLK GPIO_NUM_NC
#define AUDIO_I2S_GPIO_WS   GPIO_NUM_21
#define AUDIO_I2S_GPIO_BCLK GPIO_NUM_22
#define AUDIO_I2S_GPIO_DOUT GPIO_NUM_23
  • MCLK (Master Clock) is not used and is set to NC.
  • WS / LRCLK (Word Select) controls the left and right audio channels and is connected to GPIO21.
  • BCLK (Bit Clock) controls the timing of each audio data bit and is connected to GPIO22.
  • DOUT outputs audio data to the speaker and is connected to GPIO23.

Microphone Pin Configuration

#define AUDIO_PDM_MIC_CLK  GPIO_NUM_24
#define AUDIO_PDM_MIC_DIN  GPIO_NUM_26
  • PDM microphone clock output: GPIO24
  • PDM microphone data input: GPIO26

Audio Codec Configuration

#define AUDIO_CODEC_PA_PIN       GPIO_NUM_30
#define AUDIO_CODEC_I2C_SDA_PIN  GPIO_NUM_NC
#define AUDIO_CODEC_I2C_SCL_PIN  GPIO_NUM_NC
#define AUDIO_CODEC_ES8311_ADDR  ES8311_CODEC_DEFAULT_ADDR
  • The power amplifier enable pin is GPIO30.
  • Setting it HIGH turns the speaker on.
  • Setting it LOW turns the speaker off.
  • Since there is no audio codec chip used, the I2C SDA and SCL pins are set to NC.
  • The codec I2C address is simply a placeholder and is not actually accessed.

Button Configuration

#define BOOT_BUTTON_GPIO GPIO_NUM_35

This is the BOOT button on the P4 board, which can be used to interrupt the AI conversation.


Display Configuration

#define DISPLAY_WIDTH 1024
#define DISPLAY_HEIGHT 600
#define LCD_BIT_PER_PIXEL (16)
#define PIN_NUM_LCD_RST GPIO_NUM_NC
  • Display resolution: 1024 × 600
  • Pixel format: 16-bit (RGB565)
  • The LCD reset pin is not used, so it is set to NC.

MIPI DSI Configuration

#define DELAY_TIME_MS (3000)
#define LCD_MIPI_DSI_LANE_NUM (2)
  • Power-on initialization delay: 3000 ms
  • Number of data lanes: 2

MIPI DSI Power Configuration

#define MIPI_DSI_PHY_PWR_LDO_CHAN (3)
#define MIPI_DSI_PHY_PWR_LDO_VOLTAGE_MV (2500)
  • LDO channel: 3
  • Power supply voltage: 2.5 V

Display Orientation Configuration

#define DISPLAY_SWAP_XY false
#define DISPLAY_MIRROR_X false
#define DISPLAY_MIRROR_Y false
#define DISPLAY_OFFSET_X 0
#define DISPLAY_OFFSET_Y 0
  • No XY axis swapping
  • No horizontal mirroring
  • No vertical mirroring
  • X offset: 0
  • Y offset: 0

Backlight Configuration

#define DISPLAY_BACKLIGHT_PIN GPIO_NUM_31
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
  • Backlight control pin: GPIO31
  • Backlight output is not inverted

Touch Screen Configuration (Not Used in This Example)

#define TOUCH_GPIO_RST GPIO_NUM_40
#define TOUCH_GPIO_INT GPIO_NUM_42
  • Touch reset pin: GPIO40
  • Touch interrupt pin: GPIO42

Touch I2C Configuration

#define TOUCH_I2C_SDA_PIN GPIO_NUM_45
#define TOUCH_I2C_SCL_PIN GPIO_NUM_46
#define TOUCH_I2C_PORT I2C_NUM_0
  • I2C SDA: GPIO45
  • I2C SCL: GPIO46
  • Uses I2C controller 0

Hardware Implementation File

Under the same path:

main → boards → elecrow-p4-board

you will also find the file:

elecrow_board.cc

This file implements the core hardware functions of the Elecrow P4 HMI system.

It defines a complete device configuration with Wi-Fi support, including:

  • Display
  • Backlight
  • Camera
  • Buttons
  • Touch communication

All of these components are explained in the P4 HMI basic course, so they will not be covered in detail here.

7-inch P4 HMI course: https://www.elecrow.com/download/product/DHE04107D/Advance_HMI_P4_7inch_Course.pdf

9-inch P4 HMI course: https://www.elecrow.com/download/product/DHE04209D/Advance_HMI_P4_9inch_Course.pdf

10.1-inch P4 HMI course: https://www.elecrow.com/download/product/DHE04310D/Advance_HMI_P4_10.1inch_Course.pdf


Camera Configuration

The camera configuration file is located at:

main → boards → elecrow-p4-board → bsp_camera.h

Key configuration parameters:

#define SCCB_MASTER_PORT 1
#define SCCB_GPIO_SCL 13
#define SCCB_GPIO_SDA 12
  • SCCB port: 1
  • SCL pin: GPIO13
  • SDA pin: GPIO12

Camera Driver Files

bsp_camera.c

This file initializes the camera sensor, configures the CSI interface, and sets parameters such as:

  • Resolution
  • Pixel format
  • Bits per pixel

p4_bsp_camera.cc

This file implements the photo capture function and sends the captured image to a server for recognition, then returns the recognition result.


Camera Configuration Summary

Parameter Value File
Resolution 1024 × 600 bsp_camera.c
Pixel Format RGB565 (16-bit) bsp_camera.c
Frame Rate 30 fps bsp_camera.c
Interface MIPI CSI 2-lane bsp_camera.c
SCCB I2C Port Port 1 bsp_camera.c
SCCB SCL Pin GPIO13 bsp_camera.c
SCCB SDA Pin GPIO12 bsp_camera.c
Camera Power LDO4 (3.3 V) elecrow_board.cc
Buffer Size 1025 × 600 × 2 = 1,228,800 bytes bsp_camera.c

Wi-Fi Configuration

Click the menuconfig button at the bottom of VS Code to open the configuration menu.

ai-33

Then search for:

hosted

ai-44


Important Pin Configuration

ai-55

The corresponding settings will also appear in the sdkconfig file:

CONFIG_SLAVE_IDF_TARGET_ESP32C6=y
CONFIG_ESP_HOSTED_ENABLED=y
CONFIG_ESP_HOSTED_P4_DEV_BOARD_NONE
CONFIG_ESP_HOSTED_PRIV_SDIO_OPTION=y
CONFIG_ESP_HOSTED_IDF_SLAVE_TARGET="esp32c6"
CONFIG_ESP_HOSTED_SDIO_RESET_ACTIVE_HIGH=y
CONFIG_ESP_HOSTED_SDIO_SLOT_1=y
CONFIG_ESP_HOSTED_SDIO_1_BIT_BUS=y
CONFIG_ESP_HOSTED_SDIO_CLOCK_FREQ_KHZ=40000
CONFIG_ESP_HOSTED_PRIV_SDIO_PIN_CMD_SLOT_1=19
CONFIG_ESP_HOSTED_PRIV_SDIO_PIN_CLK_SLOT_1=18
CONFIG_ESP_HOSTED_PRIV_SDIO_PIN_D0_SLOT_1=14
CONFIG_ESP_HOSTED_PRIV_SDIO_PIN_D1_1BIT_BUS_SLOT_1=15
CONFIG_ESP_HOSTED_SDIO_GPIO_RESET_SLAVE=32
CONFIG_ESP_HOSTED_ENABLE_BT_BLUEDROID=y

For reliability, it is recommended to copy these configuration settings directly into menuconfig.

Once configured, the sdkconfig file will automatically generate the corresponding settings.