Guest User

ESP32-P4-WIFI6-Touch-LCD-4C

a guest
Oct 5th, 2025
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 9.41 KB | None | 0 0
  1. esphome:
  2.   name: waveshare-p4-touch-lcd-4c
  3.   friendly_name: WaveShare P4 Touch LCD 4
  4.   name_add_mac_suffix: false
  5.  
  6. esp32:
  7.   board: esp32-p4-evboard
  8.   flash_size: 32Mb
  9.   cpu_frequency: 400MHz
  10.   framework:
  11.     type: esp-idf
  12.     # platform_version: https://github.com/pioarduino/platform-espressif32/releases/download/54.03.21/platform-espressif32.zip
  13.     version: 5.4.2
  14.     platform_version: 54.03.21
  15.     advanced:
  16.       enable_idf_experimental_features: yes
  17.  
  18. # Enable logging
  19. logger:
  20.   level: debug
  21.   logs:
  22.     lvgl: info
  23.   hardware_uart: UART0
  24.  
  25. # Enable Home Assistant API
  26. api:
  27.   encryption:
  28.     key: !secret waveshare_api
  29.  
  30. ota:
  31.   - platform: esphome
  32.     password: !secret ota_password
  33.  
  34. wifi:
  35.   ssid: !secret wifi_ssid
  36.   password: !secret wifi_password
  37.  
  38.   # Enable fallback hotspot (captive portal) in case wifi connection fails
  39.   ap:
  40.     ssid: "Esp32-P4-Touch-Lcd-4C"
  41.     password: !secret ap_pwd
  42.  
  43. psram:
  44.   speed: 200MHz
  45.  
  46. esp32_hosted:
  47.   active_high: true
  48.   variant: ESP32C6
  49.   reset_pin: GPIO54
  50.   cmd_pin: GPIO19
  51.   clk_pin: GPIO18
  52.   d0_pin: GPIO14
  53.   d1_pin: GPIO15
  54.   d2_pin: GPIO16
  55.   d3_pin: GPIO17
  56.  
  57. i2c:
  58.   sda: GPIO7
  59.   scl: GPIO8
  60.   scan: true
  61.   frequency: 400kHz
  62.   id: i2c_bus
  63.  
  64. i2s_audio:
  65.   - id: audio_bus
  66.     i2s_mclk_pin: GPIO13
  67.     i2s_lrclk_pin: GPIO10
  68.     i2s_bclk_pin: GPIO12
  69.  
  70. audio_dac:
  71.   - platform: es8311
  72.     id: es8311_dac
  73.     i2c_id: i2c_bus
  74.     address: 0x18
  75.  
  76. microphone:
  77.   - platform: i2s_audio
  78.     id: esp32_microphone
  79.     i2s_audio_id: audio_bus
  80.     i2s_din_pin: GPIO11
  81.     sample_rate: 16000
  82.     bits_per_sample: 16bit
  83.     adc_type: external
  84.  
  85. speaker:
  86.   - platform: i2s_audio
  87.     id: esp32_speaker
  88.     i2s_audio_id: audio_bus
  89.     i2s_dout_pin: GPIO9
  90.     audio_dac: es8311_dac
  91.     dac_type: external
  92.     channel: mono
  93.     buffer_duration: 100ms
  94.     bits_per_sample: 16bit
  95.     sample_rate: 48000
  96.  
  97.   - platform: mixer
  98.     id: mixing_speaker
  99.     output_speaker: esp32_speaker
  100.     source_speakers:
  101.       - id: announcement_mixing_input
  102.         timeout: never
  103.       - id: media_mixing_input
  104.         timeout: never
  105.  
  106.   - platform: resampler
  107.     id: announcement_resampling_speaker
  108.     output_speaker: announcement_mixing_input
  109.     sample_rate: 48000
  110.     bits_per_sample: 16
  111.  
  112.   - platform: resampler
  113.     id: media_resampling_speaker
  114.     output_speaker: media_mixing_input
  115.     sample_rate: 48000
  116.     bits_per_sample: 16
  117.  
  118. switch:
  119.   - platform: gpio
  120.     pin: GPIO53  # BSP_POWER_AMP_IO
  121.     name: "Audio Amplifier"
  122.     id: audio_amplifier
  123.     restore_mode: ALWAYS_OFF
  124.  
  125. media_player:
  126.   - platform: speaker
  127.     name: "ESP32 P4 Media Player"
  128.     id: speaker_media_player
  129.     codec_support_enabled: true
  130.     volume_min: 0.5
  131.     volume_max: 0.75
  132.     volume_increment: 0.05
  133.     announcement_pipeline:
  134.       speaker: announcement_resampling_speaker
  135.       format: FLAC
  136.       sample_rate: 48000
  137.       num_channels: 1
  138.     media_pipeline:
  139.       speaker: media_resampling_speaker
  140.       format: FLAC
  141.       num_channels: 1
  142.       sample_rate: 48000
  143.     on_announcement:
  144.       - if:
  145.           condition:
  146.             - microphone.is_capturing:
  147.           then:
  148.            - micro_wake_word.stop
  149.             - voice_assistant.stop
  150.       - mixer_speaker.apply_ducking:
  151.           id: media_mixing_input
  152.           decibel_reduction: 20
  153.           duration: 0.0s
  154.       - switch.turn_on: audio_amplifier
  155.       - delay: 100ms
  156.     on_state:
  157.       if:
  158.         condition:
  159.           and:
  160.             - not:
  161.                 voice_assistant.is_running:
  162.             - not:
  163.                 media_player.is_announcing:
  164.         then:
  165.           - mixer_speaker.apply_ducking:
  166.               id: media_mixing_input
  167.               decibel_reduction: 0
  168.               duration: 1.0s
  169.     on_play:
  170.       - logger.log: "Media player started playing, disabling microphone"
  171.       - switch.turn_on: audio_amplifier
  172.       - delay: 100ms
  173.       - micro_wake_word.stop
  174.       - voice_assistant.stop
  175.     on_idle:
  176.       - delay: 100ms
  177.       - switch.turn_off: audio_amplifier
  178.       - if:
  179.           condition:
  180.             not:
  181.               voice_assistant.is_running:
  182.           then:
  183.            - micro_wake_word.start
  184.  
  185.  
  186. sensor:
  187.   - platform: template
  188.     name: "Voice Assistant State"
  189.     lambda: |-
  190.       if (id(esp32_microphone).is_running()) {
  191.         return 1;
  192.       } else {
  193.         return 0;
  194.       }
  195.     update_interval: 2s
  196.  
  197. text_sensor:
  198.   - platform: template
  199.     name: "Voice Assistant Status"
  200.     id: voice_status
  201.     update_interval: 5s
  202.     lambda: |-
  203.       if (id(esp32_microphone).is_running()) {
  204.         return {"Listening"};
  205.       } else {
  206.         return {"Idle"};
  207.       }
  208.  
  209. micro_wake_word:
  210.   id: my_wake_word
  211.   models:
  212.     - model: hey_jarvis
  213.   on_wake_word_detected:
  214.     then:
  215.       - logger.log: "Wake word detected"
  216.       - voice_assistant.start:
  217.           wake_word: !lambda return wake_word;
  218.  
  219. ## Voice Assistant
  220. voice_assistant:
  221.   microphone: esp32_microphone
  222.   media_player: speaker_media_player
  223.   micro_wake_word: my_wake_word
  224.   noise_suppression_level: 2
  225.   auto_gain: 31dBFS
  226.   volume_multiplier: 2.0
  227.   conversation_timeout: 300s
  228.   on_end:
  229.    # Wait a short amount of time to see if an announcement starts
  230.     - wait_until:
  231.         condition:
  232.           - media_player.is_announcing:
  233.         timeout: 0.5s
  234.     # Announcement is finished and the I2S bus is free
  235.     - wait_until:
  236.         - and:
  237.             - not:
  238.                 media_player.is_announcing:
  239.             - not:
  240.                 media_player.is_playing:
  241.     - micro_wake_word.start:
  242.   on_client_connected:
  243.     - micro_wake_word.start:
  244.   on_client_disconnected:
  245.     - micro_wake_word.stop:
  246. ## TOUCHSCREEN CONFIG
  247. touchscreen:
  248.   - platform: gt911
  249.     id: touchscreen_
  250.     # address: 0x14
  251.     on_touch:
  252.       - logger.log:
  253.           format: "Touch at %d/%d"
  254.           args: [touch.x, touch.y]
  255.  
  256. ## PANEL BACKLIGHT CONFIG
  257. output:
  258.   - platform: ledc
  259.     id: backlight_
  260.     pin: GPIO26
  261.     frequency: 100Hz
  262.     inverted: true
  263.     min_power: 0.1 # To prevent the backlight from being too dim
  264.     max_power: 1.0 # 0.8 To prevent overheating due to excessive lighting
  265.    
  266. light:
  267.   - platform: monochromatic
  268.     name: "backlight"
  269.     output: backlight_
  270.     id: backlight_light
  271.     restore_mode: ALWAYS_ON
  272.  
  273. ## MIPI DSI CONFIG
  274. esp_ldo:
  275.   - channel: 3
  276.     voltage: 2.5V
  277.  
  278. display:
  279.   - platform: mipi_dsi
  280.     model: WAVESHARE-P4-NANO-10.1
  281.  
  282.     # DPI config
  283.     lanes: 2
  284.     lane_bit_rate: 1500000000
  285.     hsync_pulse_width: 20
  286.     hsync_front_porch: 40
  287.     hsync_back_porch: 20
  288.     vsync_pulse_width: 4
  289.     vsync_front_porch: 24
  290.     vsync_back_porch: 12
  291.     pclk_frequency: 80MHz
  292.     dimensions:
  293.       height: 720
  294.       width: 720
  295.  
  296.     # Vendor config
  297.     init_sequence:
  298.    - [0xE0, 0x00]
  299.     - [0xE1, 0x93, 0xE2, 0x65, 0xE3, 0xF8, 0x80, 0x01]
  300.     - [0xE0, 0x01]
  301.     - [0x00, 0x00, 0x01, 0x41, 0x03, 0x10, 0x04, 0x44]
  302.     - [0x17, 0x00, 0x18, 0xD0, 0x19, 0x00, 0x1A, 0x00, 0x1B, 0xD0, 0x1C, 0x00]
  303.     - [0x24, 0xFE, 0x35, 0x26]
  304.     - [0x37, 0x09]
  305.     - [0x38, 0x04, 0x39, 0x08, 0x3A, 0x0A, 0x3C, 0x78, 0x3D, 0xFF, 0x3E, 0xFF, 0x3F, 0xFF]
  306.     - [0x40, 0x04, 0x41, 0x64, 0x42, 0xC7, 0x43, 0x18, 0x44, 0x0B, 0x45, 0x14]
  307.     - [0x55, 0x02, 0x57, 0x49, 0x59, 0x0A, 0x5A, 0x1B, 0x5B, 0x19]
  308.     - [0x5D, 0x7F, 0x5E, 0x56, 0x5F, 0x43, 0x60, 0x37, 0x61, 0x33, 0x62, 0x25, 0x63, 0x2A, 0x64, 0x16, 0x65, 0x30, 0x66, 0x2F, 0x67, 0x32, 0x68, 0x53, 0x69, 0x43, 0x6A, 0x4C, 0x6B, 0x40, 0x6C, 0x3D, 0x6D, 0x31, 0x6E, 0x20, 0x6F, 0x0F]
  309.     - [0x70, 0x7F, 0x71, 0x56, 0x72, 0x43, 0x73, 0x37, 0x74, 0x33, 0x75, 0x25, 0x76, 0x2A, 0x77, 0x16, 0x78, 0x30, 0x79, 0x2F, 0x7A, 0x32, 0x7B, 0x53, 0x7C, 0x43, 0x7D, 0x4C, 0x7E, 0x40, 0x7F, 0x3D, 0x80, 0x31, 0x81, 0x20, 0x82, 0x0F]
  310.     - [0xE0, 0x02, 0x00, 0x5F, 0x01, 0x5F, 0x02, 0x5E, 0x03, 0x5E, 0x04, 0x50, 0x05, 0x48, 0x06, 0x48, 0x07, 0x4A, 0x08, 0x4A, 0x09, 0x44, 0x0A, 0x44, 0x0B, 0x46, 0x0C, 0x46, 0x0D, 0x5F, 0x0E, 0x5F, 0x0F, 0x57, 0x10, 0x57, 0x11, 0x77, 0x12, 0x77, 0x13, 0x40, 0x14, 0x42, 0x15, 0x5F]
  311.     - [0x16, 0x5F, 0x17, 0x5F, 0x18, 0x5E, 0x19, 0x5E, 0x1A, 0x50, 0x1B, 0x49, 0x1C, 0x49, 0x1D, 0x4B, 0x1E, 0x4B, 0x1F, 0x45, 0x20, 0x45, 0x21, 0x47, 0x22, 0x47, 0x23, 0x5F, 0x24, 0x5F, 0x25, 0x57, 0x26, 0x57, 0x27, 0x77, 0x28, 0x77, 0x29, 0x41, 0x2A, 0x43, 0x2B, 0x5F]
  312.     - [0x2C, 0x1E, 0x2D, 0x1E, 0x2E, 0x1F, 0x2F, 0x1F, 0x30, 0x10, 0x31, 0x07, 0x32, 0x07, 0x33, 0x05, 0x34, 0x05, 0x35, 0x0B, 0x36, 0x0B, 0x37, 0x09, 0x38, 0x09, 0x39, 0x1F, 0x3A, 0x1F, 0x3B, 0x17, 0x3C, 0x17, 0x3D, 0x17, 0x3E, 0x17, 0x3F, 0x03, 0x40, 0x01, 0x41, 0x1F]
  313.     - [0x42, 0x1E, 0x43, 0x1E, 0x44, 0x1F, 0x45, 0x1F, 0x46, 0x10, 0x47, 0x06, 0x48, 0x06, 0x49, 0x04, 0x4A, 0x04, 0x4B, 0x0A, 0x4C, 0x0A, 0x4D, 0x08, 0x4E, 0x08, 0x4F, 0x1F, 0x50, 0x1F, 0x51, 0x17, 0x52, 0x17, 0x53, 0x17, 0x54, 0x17, 0x55, 0x02, 0x56, 0x00, 0x57, 0x1F]
  314.     - [0xE0, 0x02, 0x58, 0x40, 0x59, 0x00, 0x5A, 0x00, 0x5B, 0x30, 0x5C, 0x01, 0x5D, 0x30, 0x5E, 0x01, 0x5F, 0x02, 0x60, 0x30, 0x61, 0x03, 0x62, 0x04, 0x63, 0x04, 0x64, 0xA6, 0x65, 0x43, 0x66, 0x30, 0x67, 0x73, 0x68, 0x05, 0x69, 0x04, 0x6A, 0x7F, 0x6B, 0x08, 0x6C, 0x00, 0x6D, 0x04, 0x6E, 0x04, 0x6F, 0x88]
  315.     - [0x75, 0xD9, 0x76, 0x00, 0x77, 0x33, 0x78, 0x43]
  316.     - [0xE0, 0x00, 0x11, 0x00]
  317.     - delay 120ms
  318.     - [0x29, 0x00]
  319.     - delay 120ms
  320.     - [0x35, 0x00]
  321.    
  322.     # Panel config
  323.     color_order: rgb
  324.     pixel_mode: 24bit
  325.     color_depth: 24
  326.     byte_order: little_endian
  327.     reset_pin: GPIO27
  328.  
  329.     show_test_card: true
  330.  
Advertisement
Add Comment
Please, Sign In to add comment