nene1234

audio + 8mb_psram

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