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:
- A display to show the user interface
- A microphone to capture voice input
- 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¶
- Understand how an AI voice chat robot works
- Learn how to configure the display on the Elecrow P4 HMI
- Learn how to configure the microphone on the Elecrow P4 HMI
- Learn how to configure the speaker on the Elecrow P4 HMI
- Learn how to configure Wi-Fi on the Elecrow P4 HMI
Preview of the Result¶
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 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¶
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¶
- 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¶
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¶
- Power-on initialization delay: 3000 ms
- Number of data lanes: 2
MIPI DSI Power Configuration¶
- 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¶
- Backlight control pin: GPIO31
- Backlight output is not inverted
Touch Screen Configuration (Not Used in This Example)¶
- 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.
P4 HMI Basic Course Links¶
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:
- 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.
Then search for:
hosted
Important Pin Configuration¶
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.






