CrowPanel Advanced 5inch ESP32-P4 HMI AI Voice Chat Robot¶
Introduction¶
In this example, we will walk through the process step by step to demonstrate how to configure an AI voice chat robot on the Elecrow P4 HMI.
To enable real-time voice interaction, the system requires three essential hardware components:
- A display for the user interface
- A microphone for capturing voice input
- A speaker for playing back audio responses
In this lesson, we will guide you through configuring each of these components, including display output, audio input, and audio output settings. These configurations will serve as the foundation for building a complete AI voice interaction system.
Learning Goals¶
- Understand the working principle of an AI voice chat robot
- 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 the preset wake word and start a voice conversation with it.
For detailed instructions on how to use it, please refer to the P4 HMI AI Case User Guide.
Hardware Used in This Lesson¶
AI Voice Chat Robot¶
Download the Code¶
Before we go through the code, you can download the complete project first.
Full project download link: https://drive.google.com/file/d/1dguwlhGNss9FSLusx42QgQkiUmvDyaSf/view?usp=sharing
Key Code Explanation¶
Now let’s walk 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 each configuration section.
Audio Configuration¶
Both the audio input sampling rate and the 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, so it 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 is the audio data output line used to drive the speaker, connected to GPIO23.
Microphone Pin Configuration¶
- The PDM microphone clock output pin is GPIO24.
- The PDM microphone data input pin is GPIO25.
Audio Codec Configuration¶
#define AUDIO_CODEC_PA_PIN GPIO_NUM_NC
#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
Since this design does not use an audio codec chip, the I2C SDA and SCL pins are set to NC.
The codec I2C address is simply a placeholder and will not actually be accessed.
Button Configuration¶
This is the BOOT button on the P4 board, which is used to interrupt the AI conversation.
Display Configuration¶
#define DISPLAY_WIDTH 800
#define DISPLAY_HEIGHT 480
#define LCD_BIT_PER_PIXEL (16)
#define PIN_NUM_LCD_RST GPIO_NUM_NC
- Display resolution: 800 × 480
- Each pixel uses 16 bits (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
- Supply voltage: 2.5 V
RGB LCD Timing Configuration¶
#define RGB_LCD_PIXEL_CLOCK_HZ (18 * 1000 * 1000)
#define RGB_LCD_HSYNC 4
#define RGB_LCD_HBP 8
#define RGB_LCD_HFP 8
#define RGB_LCD_VSYNC 4
#define RGB_LCD_VBP 16
#define RGB_LCD_VFP 16
RGB Control Pins¶
#define RGB_PIN_NUM_DISP_EN GPIO_NUM_NC
#define RGB_PIN_NUM_HSYNC GPIO_NUM_40
#define RGB_PIN_NUM_VSYNC GPIO_NUM_41
#define RGB_PIN_NUM_DE GPIO_NUM_2
#define RGB_PIN_NUM_PCLK GPIO_NUM_3
RGB Data Pins (RGB565 – 16-bit)¶
#define RGB_PIN_NUM_DATA0 GPIO_NUM_8
#define RGB_PIN_NUM_DATA1 GPIO_NUM_7
#define RGB_PIN_NUM_DATA2 GPIO_NUM_6
#define RGB_PIN_NUM_DATA3 GPIO_NUM_5
#define RGB_PIN_NUM_DATA4 GPIO_NUM_4
#define RGB_PIN_NUM_DATA5 GPIO_NUM_14
#define RGB_PIN_NUM_DATA6 GPIO_NUM_13
#define RGB_PIN_NUM_DATA7 GPIO_NUM_12
#define RGB_PIN_NUM_DATA8 GPIO_NUM_11
#define RGB_PIN_NUM_DATA9 GPIO_NUM_10
#define RGB_PIN_NUM_DATA10 GPIO_NUM_9
#define RGB_PIN_NUM_DATA11 GPIO_NUM_19
#define RGB_PIN_NUM_DATA12 GPIO_NUM_18
#define RGB_PIN_NUM_DATA13 GPIO_NUM_17
#define RGB_PIN_NUM_DATA14 GPIO_NUM_16
#define RGB_PIN_NUM_DATA15 GPIO_NUM_15
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 swap
- No horizontal mirroring
- No vertical mirroring
- X offset: 0
- Y offset: 0
Backlight Configuration¶
The display backlight is not controlled by the ESP32. Instead, it is controlled by an external power circuit / STC8 / PWM chip, so no GPIO is assigned.
Touch Screen Configuration (Not Used in This Example)¶
- Touch reset pin: GPIO36
- 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
STC8 Extended IO / Power Management¶
#define STC8_I2C_PORT TOUCH_I2C_PORT
#define STC8_I2C_SDA_PIN TOUCH_I2C_SDA_PIN
#define STC8_I2C_SCL_PIN TOUCH_I2C_SCL_PIN
Hardware Implementation File¶
Under the same path:
main → boards → elecrow-p4-board
there is another file:
elecrow_board.cc
This file implements the main hardware functionality of the Elecrow P4 HMI display system.
It defines the complete device configuration with Wi-Fi support, including:
- Display
- Backlight
- Camera
- Buttons
- Touch communication
All of this code is already covered in the P4 HMI basic course, so it will not be explained in detail here.
5-inch P4 HMI basic course link:
Wi-Fi Configuration¶
Click the menuconfig button at the bottom of VS Code to configure the settings.
Search for:
hosted
Important Pin Configuration¶
Relevant configuration options 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=y
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_4_BIT_BUS=y
CONFIG_ESP_HOSTED_SDIO_CLOCK_FREQ_KHZ=40000
CONFIG_ESP_HOSTED_PRIV_SDIO_PIN_CMD_SLOT_1=54
CONFIG_ESP_HOSTED_PRIV_SDIO_PIN_CLK_SLOT_1=53
CONFIG_ESP_HOSTED_PRIV_SDIO_PIN_D0_SLOT_1=52
CONFIG_ESP_HOSTED_PRIV_SDIO_PIN_D1_4BIT_BUS_SLOT_1=51
CONFIG_ESP_HOSTED_PRIV_SDIO_PIN_D2_4BIT_BUS_SLOT_1=50
CONFIG_ESP_HOSTED_PRIV_SDIO_PIN_D3_4BIT_BUS_SLOT_1=49
CONFIG_ESP_HOSTED_SDIO_GPIO_RESET_SLAVE=20
CONFIG_ESP_HOSTED_ENABLE_BT_BLUEDROID=y
For better reliability, it is recommended to copy these configuration settings directly into menuconfig.
Once configured, the sdkconfig file will automatically generate the corresponding settings.




