nene1234

lilka audio work!

Nov 17th, 2025
500
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 8.22 KB | None | 0 0
  1. esphome:
  2.   name: lilka
  3.   friendly_name: lilka
  4.   on_boot:
  5.     priority: 600
  6.     then:
  7.       - output.turn_on: display_power
  8.       - delay: 100ms
  9.  
  10. esp32:
  11.   board: esp32-s3-devkitc-1
  12.   framework:
  13.     type: esp-idf
  14.     version: recommended
  15.     # Оптимізація пам'яті
  16.     sdkconfig_options:
  17.       CONFIG_ESP32S3_DATA_CACHE_64KB: y
  18.       CONFIG_ESP32S3_DATA_CACHE_LINE_64B: y
  19.       CONFIG_SPIRAM_MODE_OCT: y
  20.       CONFIG_SPIRAM: y
  21.  
  22. # Додати якщо є PSRAM
  23. psram:
  24.   mode: octal
  25.   speed: 80MHz
  26.  
  27. wifi:
  28.   ssid: !secret wifi_ssid
  29.   password: !secret wifi_password
  30.   power_save_mode: none
  31.   ap:
  32.     ssid: "Lilka Fallback Hotspot"
  33.     password: "hnYImYM4O6I0"
  34.  
  35. captive_portal:
  36. web_server:
  37.   port: 80
  38.  
  39. api:
  40.   encryption:
  41.     key: "Yw3yq8lxsaze+jdggjAwxKpV4GD6gNZptvw4d6OPfOc="
  42.  
  43. logger:
  44.   level: INFO
  45.   logs:
  46.     lvgl: WARN
  47.     speaker_media_player: INFO
  48.     i2s_audio.speaker: INFO
  49.  
  50. ota:
  51.   - platform: esphome
  52.     password: "bb198feb99159fdaefc8092f10039acd"
  53.  
  54. output:
  55.   - platform: gpio
  56.     pin: 46
  57.     id: display_power
  58.     inverted: false
  59.  
  60. i2s_audio:
  61.   - id: i2s_out
  62.     i2s_lrclk_pin: GPIO1
  63.     i2s_bclk_pin: GPIO42
  64.  
  65. speaker:
  66.   - platform: i2s_audio
  67.     id: lilka_speaker
  68.     dac_type: external
  69.     i2s_audio_id: i2s_out
  70.     i2s_dout_pin: GPIO2
  71.     channel: mono
  72.     sample_rate: 16000
  73.     bits_per_sample: 16bit
  74.     buffer_duration: 100ms
  75.  
  76. media_player:
  77.   - platform: speaker
  78.     name: "Lilka Media Player"
  79.     id: lilka_media_player
  80.     buffer_size: 4000
  81.     codec_support_enabled: false
  82.     announcement_pipeline:
  83.         speaker: lilka_speaker
  84.         format: WAV
  85.         num_channels: 1
  86.  
  87. # ---------------------------------------------------
  88. # СЕНСОРИ
  89. # ---------------------------------------------------
  90.  
  91. sensor:
  92.   - platform: adc
  93.     pin: GPIO3
  94.     id: battery_voltage
  95.     name: "Battery Voltage"
  96.     icon: "mdi:lightning-bolt"
  97.     update_interval: 10s
  98.     attenuation: 12db
  99.     filters:
  100.       - multiply: 1.33
  101.    
  102.   - platform: template
  103.     id: battery_level
  104.     name: "Battery Level"
  105.     icon: "mdi:battery"
  106.     unit_of_measurement: "%"
  107.     accuracy_decimals: 0
  108.     update_interval: 10s
  109.     lambda: |-
  110.       float voltage = id(battery_voltage).state;
  111.       float percent = (voltage - 3.0) / (4.2 - 3.0) * 100.0;
  112.       if (percent > 100) percent = 100;
  113.       if (percent < 0) percent = 0;
  114.       return percent;
  115.  
  116. # ---------------------------------------------------
  117. # ДИСПЛЕЙ ST7789V + LVGL
  118. # ---------------------------------------------------
  119.  
  120. spi:
  121.   clk_pin: 18
  122.   mosi_pin: 17
  123.  
  124. display:
  125.   - platform: mipi_spi
  126.     model: ST7789V
  127.     id: my_display
  128.     dc_pin: 15
  129.     cs_pin: 7
  130.     update_interval: 2s
  131.     rotation: 270
  132.     invert_colors: true
  133.     color_order: BGR
  134.     pixel_mode: 16bit
  135.     dimensions:
  136.       width: 280
  137.       height: 240
  138.       offset_width: 20
  139.       offset_height: 0
  140.     auto_clear_enabled: false
  141.  
  142. lvgl:
  143.   log_level: WARN
  144.   buffer_size: 25%
  145.  
  146.   style_definitions:
  147.     - id: default_style
  148.       bg_color: 0x000000
  149.       text_color: 0xFFFFFF
  150.     - id: focused_style
  151.       border_color: 0xFFFFFF
  152.       border_width: 3
  153.  
  154.   pages:
  155.     - id: main_page
  156.       bg_color: 0x000000
  157.       widgets:
  158.         - button:
  159.             id: red_button
  160.             align: CENTER
  161.             y: -40
  162.             width: 180
  163.             height: 50
  164.             bg_color: 0xFF0000
  165.             widgets:
  166.               - label:
  167.                   id: battery_label
  168.                   text: "Battery: --"
  169.                   align: CENTER
  170.  
  171.         - button:
  172.             id: green_button
  173.             align: CENTER
  174.             y: 20
  175.             width: 180
  176.             height: 50
  177.             bg_color: 0x00FF00
  178.             widgets:
  179.               - label:
  180.                   id: voltage_label
  181.                   text: "Voltage: --"
  182.                   align: CENTER
  183.                   text_color: 0x000000
  184.  
  185.         - button:
  186.             id: blue_button
  187.             align: CENTER
  188.             y: 80
  189.             width: 180
  190.             height: 50
  191.             bg_color: 0x0000FF
  192.             widgets:
  193.               - label:
  194.                   text: "Lilka LVGL"
  195.                   align: CENTER
  196.                   text_color: 0xFFFFFF
  197.  
  198. # ---------------------------------------------------
  199. # ГЛОБАЛЬНІ ЗМІННІ ТА СКРИПТ ФОКУСУ
  200. # ---------------------------------------------------
  201.  
  202. globals:
  203.   - id: current_button_index
  204.     type: int
  205.     restore_value: no
  206.     initial_value: '0'
  207.  
  208. script:
  209.   - id: update_focus
  210.     then:
  211.       - lvgl.widget.update:
  212.           id: red_button
  213.           border_width: !lambda 'return id(current_button_index) == 0 ? 3 : 0;'
  214.       - lvgl.widget.update:
  215.           id: green_button
  216.           border_width: !lambda 'return id(current_button_index) == 1 ? 3 : 0;'
  217.       - lvgl.widget.update:
  218.           id: blue_button
  219.           border_width: !lambda 'return id(current_button_index) == 2 ? 3 : 0;'
  220.  
  221. # ---------------------------------------------------
  222. # КНОПКИ
  223. # ---------------------------------------------------
  224.  
  225. binary_sensor:
  226.   - platform: gpio
  227.     pin:
  228.       number: 38
  229.       mode: INPUT_PULLUP
  230.       inverted: true
  231.     id: button_up
  232.     name: "Button Up"
  233.     icon: "mdi:arrow-up-circle"
  234.     filters:
  235.       - delayed_on_off: 50ms
  236.     on_press:
  237.       - lambda: |-
  238.           id(current_button_index)--;
  239.           if (id(current_button_index) < 0) id(current_button_index) = 2;
  240.       - script.execute: update_focus
  241.  
  242.   - platform: gpio
  243.     pin:
  244.       number: 41
  245.       mode: INPUT_PULLUP
  246.       inverted: true
  247.     id: button_down
  248.     name: "Button Down"
  249.     icon: "mdi:arrow-down-circle"
  250.     filters:
  251.       - delayed_on_off: 50ms
  252.     on_press:
  253.       - lambda: |-
  254.           id(current_button_index)++;
  255.           if (id(current_button_index) > 2) id(current_button_index) = 0;
  256.       - script.execute: update_focus
  257.  
  258.   - platform: gpio
  259.     pin:
  260.       number: 39
  261.       mode: INPUT_PULLUP
  262.       inverted: true
  263.     id: button_left
  264.     name: "Button Left"
  265.     icon: "mdi:arrow-left-circle"
  266.     filters:
  267.       - delayed_on_off: 50ms
  268.  
  269.   - platform: gpio
  270.     pin:
  271.       number: 40
  272.       mode: INPUT_PULLUP
  273.       inverted: true
  274.     id: button_right
  275.     name: "Button Right"
  276.     icon: "mdi:arrow-right-circle"
  277.     filters:
  278.       - delayed_on_off: 50ms
  279.  
  280.   - platform: gpio
  281.     pin:
  282.       number: 5
  283.       mode: INPUT_PULLUP
  284.       inverted: true
  285.     id: button_a
  286.     name: "Button A"
  287.     icon: "mdi:alpha-a-circle"
  288.     filters:
  289.       - delayed_on_off: 50ms
  290.  
  291.   - platform: gpio
  292.     pin:
  293.       number: 6
  294.       mode: INPUT_PULLUP
  295.       inverted: true
  296.     id: button_b
  297.     name: "Button B"
  298.     icon: "mdi:alpha-b-circle"
  299.     filters:
  300.       - delayed_on_off: 50ms
  301.  
  302.   - platform: gpio
  303.     pin:
  304.       number: 10
  305.       mode: INPUT_PULLUP
  306.       inverted: true
  307.     id: button_c
  308.     name: "Button C"
  309.     icon: "mdi:alpha-c-circle"
  310.     filters:
  311.       - delayed_on_off: 50ms
  312.  
  313.   - platform: gpio
  314.     pin:
  315.       number: 9
  316.       mode: INPUT_PULLUP
  317.       inverted: true
  318.     id: button_d
  319.     name: "Button D"
  320.     icon: "mdi:alpha-d-circle"
  321.     filters:
  322.       - delayed_on_off: 50ms
  323.  
  324.   - platform: gpio
  325.     pin:
  326.       number: 4
  327.       mode: INPUT_PULLUP
  328.       inverted: true
  329.     id: button_start
  330.     name: "Button Start"
  331.     icon: "mdi:play-circle"
  332.     filters:
  333.       - delayed_on_off: 50ms
  334.  
  335.   - platform: gpio
  336.     pin:
  337.       number: 0
  338.       mode: INPUT_PULLUP
  339.       inverted: true
  340.     id: button_select
  341.     name: "Button Select"
  342.     icon: "mdi:checkbox-marked-circle"
  343.     filters:
  344.       - delayed_on_off: 50ms
  345.  
  346. # ---------------------------------------------------
  347. # ОНОВЛЕННЯ СТАТУСУ БАТАРЕЇ НА ЕКРАНІ
  348. # ---------------------------------------------------
  349.  
  350. interval:
  351.   - interval: 5s
  352.     then:
  353.       - lvgl.label.update:
  354.           id: battery_label
  355.           text: !lambda |-
  356.             return std::string("Battery: ") + to_string((int)id(battery_level).state) + "%";
  357.  
  358.       - lvgl.label.update:
  359.           id: voltage_label
  360.           text: !lambda |-
  361.             char buf[20];
  362.             snprintf(buf, sizeof(buf), "Voltage: %.2fV", id(battery_voltage).state);
  363.             return std::string(buf);
Advertisement
Add Comment
Please, Sign In to add comment