Skip to content

Instantly share code, notes, and snippets.

@kroimon

kroimon/box.yaml Secret

Last active June 27, 2023 00:24
Show Gist options
  • Save kroimon/f6692879f9c00702990801ae9dfa433b to your computer and use it in GitHub Desktop.
Save kroimon/f6692879f9c00702990801ae9dfa433b to your computer and use it in GitHub Desktop.
ESPHome configuration to test PR #4793 on ESP32-S3-BOX
esphome:
name: box
friendly_name: Box
on_boot:
priority: 799
then:
# Mirror display (X and Y) - TODO: fix in ili9xxx driver
- lambda: |-
uint8_t madctl = ili9xxx::MADCTL_BGR | ili9xxx::MADCTL_MX | ili9xxx::MADCTL_MY;
id(lcd).send_command(ili9xxx::ILI9XXX_MADCTL, &madctl, 1);
- output.turn_on: ns4150_ctrl
esp32:
board: esp32s3box
framework:
type: arduino
# Compilation with esp-idf currently results in boot-loops. Also, i2s is currently only supported on Arduino.
#type: esp-idf
#version: latest
external_components:
- source: github://pr#4793
components: [ tt21100 ]
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
reboot_timeout: 15min
ap:
password: !secret ap_password
ap_timeout: 10min
ota:
password: !secret ota_password
api:
encryption:
key: !secret api_encryption_key
reboot_timeout: 0s
logger:
# CDC logging is currently not working on the S3
# See https://github.com/espressif/esp-idf/commit/9924d9f27192a5fab5f66230c72249ecc6cad34c
#hardware_uart: USB_CDC
level: VERBOSE
logs:
ledc.output: DEBUG
component: DEBUG
ili9xxx: DEBUG
tt21100: VERBOSE
time:
- platform: sntp
id: time_sntp
output:
- platform: ledc
pin: GPIO45
id: lcd_backlight
- platform: gpio
pin: GPIO46
id: ns4150_ctrl
light:
- platform: monochromatic
output: lcd_backlight
name: "LCD Backlight"
restore_mode: ALWAYS_ON
spi:
clk_pin: GPIO7
mosi_pin: GPIO6
display:
- platform: ili9xxx
model: ili9342
cs_pin: GPIO5
dc_pin: GPIO4
reset_pin: GPIO48
id: lcd
# Width = 320, Height = 240
lambda: |-
it.fill(Color::WHITE);
auto red = Color(255, 0, 0);
auto green = Color(0, 255, 0);
auto blue = Color(0, 0, 255);
it.filled_rectangle(10, 170, 60, 60, red);
it.filled_rectangle(130, 170, 60, 60, green);
it.filled_rectangle(250, 170, 60, 60, blue);
it.strftime(160, 85, id(font_time), Color::BLACK, TextAlign::CENTER, "%H:%M", id(time_sntp).now());
if (id(muted).state) {
it.print(310, 10, id(font_small), red, TextAlign::TOP_RIGHT, "Muted");
}
font:
- file: "gfonts://Roboto@900"
id: font_time
size: 80
glyphs: "0123456789:"
- file: "gfonts://Roboto"
id: font_small
size: 20
i2c:
scl: GPIO18
sda: GPIO8
scan: true
touchscreen:
- platform: tt21100
address: 0x24
interrupt_pin: GPIO3
# Don't use as the reset pin is shared with the display, so the ili9xxx will perform the reset
#reset_pin: GPIO48
binary_sensor:
- platform: gpio
pin:
number: GPIO0
mode: INPUT_PULLUP
id: settings
name: "Settings"
- platform: gpio
pin:
number: GPIO1
inverted: true
id: muted
name: "Muted"
- platform: tt21100
name: "Home"
index: 0
- platform: touchscreen
name: "Red"
x_min: 10
x_max: 70
y_min: 170
y_max: 230
- platform: touchscreen
name: "Green"
x_min: 130
x_max: 190
y_min: 170
y_max: 230
- platform: touchscreen
name: "Blue"
x_min: 250
x_max: 310
y_min: 170
y_max: 230
i2s_audio:
i2s_lrclk_pin: GPIO47
i2s_bclk_pin: GPIO17
# Need support for MCLK pin, see https://github.com/esphome/feature-requests/issues/1786
#i2c_mclk_pin: GPIO2
#es8311:
# address: 0x18
#media_player:
# - platform: i2s_audio
# name: Media Player
# dac_type: external
# i2s_dout_pin: GPIO15
# mode: mono
#es7210:
# address: 0x40
#microphone:
# - platform: i2s_audio
# id: external_mic
# adc_type: external
# pdm: false
# i2s_din_pin: GPIO16
# i2c device at address 0x18 - ES8311 Audio Codec
# i2c device at address 0x24 - TT21100 Touchscreen
# i2c device at address 0x40 - ES7210 Mic ADC
# i2c device at address 0x68 - ICM-42607-P IMU
@gsgxnet
Copy link

gsgxnet commented Jun 22, 2023

A slightly modified config works here. ESPHome 2023.6.1
Changes:

  • drop mirror code at boot
  • change display model from ili9342 to S3BOX
  • use standard wifi, ota, api and logger setup

Finally, the log shows, when touching the red area:

[00:01:57][D][binary_sensor:036]: 'Red': Sending state ON
[00:01:57][D][binary_sensor:036]: 'Green': Sending state OFF
[00:01:57][D][binary_sensor:036]: 'Blue': Sending state OFF
[00:01:57][D][binary_sensor:036]: 'Red': Sending state OFF

later, touching the blue area for a while:

[00:09:54][D][binary_sensor:036]: 'Blue': Sending state ON
[00:09:57][D][binary_sensor:036]: 'Blue': Sending state OFF

These color states are reflected to the a HA dashboard where I place a card which contain them.
The display backlight can be turned off/on from that HA card as well.

So thanks for the good work. Hopefully your PR will be merged soon.

@ChristophCaina
Copy link

Yes, I just got my box working some minutes ago :)

At the moment, I've removed the speaker / mediaplayer, Microphone and RGB LED, since I don't use them YET...
For now, the device is only working as a clock and (most important for me atm: bluetooth proxy) ... ^^

esp32:
  board: esp32s3box
  framework:
    type: arduino

spi:
  clk_pin: GPIO7
  mosi_pin: GPIO6

light:
#  - platform: rgb
#    name: RGB LED
#    red: rgb_red
#    green: rgb_green
#    blue: rgb_blue
  - platform: monochromatic
    output: lcd_backlight
    name: "LCD Backlight"
    restore_mode: ALWAYS_ON
    
output:
#  - platform: ledc
#    id: rgb_red
#    pin: GPIO39
#  - platform: ledc
#    id: rgb_green
#    pin: GPIO40
#  - platform: ledc
#    id: rgb_blue
#    pin: GPIO41
  - platform: ledc
    pin: GPIO45
    id: lcd_backlight
    
display:
  - platform: ili9xxx
    model: S3BOX
    cs_pin: GPIO5
    dc_pin: GPIO4
    reset_pin: GPIO48
    id: lcd
    lambda: |-
      it.fill(Color(255, 255, 255));
      it.strftime(160, 85, id(font_time), Color::BLACK, TextAlign::CENTER, "%H:%M:%S", id(time_ha).now());
      it.strftime(160, 170, id(font_date), Color::BLACK, TextAlign::CENTER, "%d.%m.%Y", id(time_ha).now());
#      auto red = Color(255, 0, 0);
#      auto green = Color(0, 255, 0);
#      auto blue = Color(0, 0, 255);
#      it.filled_rectangle(10, 170, 60, 60, red);
#      it.filled_rectangle(130, 170, 60, 60, green);
#      it.filled_rectangle(250, 170, 60, 60, blue);
#      it.line(0, 0, 50, 50);
#      it.strftime(160, 85, id(font_time), Color::BLACK, TextAlign::CENTER, "%H:%M", id(time_ha).now());

font:
  - file: "gfonts://Roboto"
    id: font_time
    size: 60
    glyphs: "0123456789:"
  - file: "gfonts://Roboto"
    id: font_date
    size: 50
    glyphs: "0123456789."
  - file: "gfonts://Roboto"
    id: font_small
    size: 20

time:
  - platform: homeassistant
    id: time_ha
    timezone: Europe/Berlin

# api, ota, wifi, bluetooth_proxy, button (restart), and so on as available in the esphome documentation

@degner
Copy link

degner commented Jun 23, 2023

using the above (and yaml from a few other posts) i can get my box to work (show the correct time, show button presses in HA and respond to touch etc) - BUT after a restart is just boot loops and never seems to connect to HA (or wifi?) again - any thoughts or ideas?

Interestingly i can get it to connect (and get latest time and stop boot looping) by starting serial port logging

@gsgxnet
Copy link

gsgxnet commented Jun 24, 2023

yeah, I see similar effects. Power off and the on again - display goes on and off and on and ... again.
Time in the display starts from 01:00 and counts up from there, after a while I am at 01:03. But no behavior as it should be.
Touchscreen does not react as configured any more.
I have the RGB led defined and connected. Pushing the red square should light the led in red as long as the push continues.
Okay when the device is fine. Defunct after power off/on when it is stuck in the loop.

And I can confirm, opening the serial (JTAG) log from HA gives a very long log list and the box works from then again as it should.

Strange!

@gsgxnet
Copy link

gsgxnet commented Jun 24, 2023

So I removed all extra modules from the .yaml. No sound, no touchscreen, no ... , just plain ESP32S3 and the display.
Still the same loop. Not good.

@ChristophCaina - your nearly bare config, does it run stable after a reboot, when HA-ESPHome is not actively logging?

@gsgxnet
Copy link

gsgxnet commented Jun 25, 2023

Found a solution. Use the latest Arduino framework.

esp32:
  board: esp32s3box
  framework:
    type: arduino
    #version: recommended  # default
    version: latest

That will give you when compiling the following warning:

INFO Reading configuration /config/esphome/box32s3xc.yaml...
WARNING The selected Arduino framework version is not the recommended one. If there are connectivity or build issues please remove the manual version.

Which has some truth in it, I have to exclude i2saudio. Because the compiler fails on that:

src/esphome/components/i2s_audio/microphone/i2s_audio_microphone.cpp: In member function 'void esphome::i2s_audio::I2SAudioMicrophone::read_()':
src/esphome/components/i2s_audio/microphone/i2s_audio_microphone.cpp:119:43: error: no matching function for call to 'esphome::CallbackManager<void(const std::vector<short int, std::allocator<short int> >&)>::call(std::vector<unsigned char>&)'
   this->data_callbacks_.call(this->buffer_);
                                           ^
In file included from src/esphome/components/i2s_audio/microphone/../i2s_audio.h:7,
                 from src/esphome/components/i2s_audio/microphone/i2s_audio_microphone.h:5,
                 from src/esphome/components/i2s_audio/microphone/i2s_audio_microphone.cpp:1:
src/esphome/core/helpers.h:474:8: note: candidate: 'void esphome::CallbackManager<void(Ts ...)>::call(Ts ...) [with Ts = {const std::vector<short int, std::allocator<short int> >&}]'
   void call(Ts... args) {
        ^~~~
src/esphome/core/helpers.h:474:8: note:   no known conversion for argument 1 from 'std::vector<unsigned char>' to 'const std::vector<short int>&'
*** [/data/box32s3xc/.pioenvs/box32s3xc/src/esphome/components/i2s_audio/microphone/i2s_audio_microphone.cpp.o] Error 1

Now it works as expected after a reset. No loop.

@degner
Copy link

degner commented Jun 26, 2023

Great work @gsgxnet , I will try this and report back

@degner
Copy link

degner commented Jun 26, 2023

hi @gsgxnet i can confirm that worked for me as well. would be great to get these findings reported with hope of fix being made (including i2saudio) - any chance you have done that?

@gsgxnet
Copy link

gsgxnet commented Jun 26, 2023

hi @gsgxnet i can confirm that worked for me as well. would be great to get these findings reported with hope of fix being made (including i2saudio) - any chance you have done that?

Would do so if I had a clue where to do it.

@rpatel3001
Copy link

We are tracking the status of the S3-BOX at esphome/feature-requests#2239

There is an updated config at https://gist.github.com/rpatel3001/ffd160577b96585fda144b786d789f46

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment