I am trying to adapt this ESP8266 Arduino code to work with ESP32 and ESPHome.
I already did the changes needed to make it work directly with ESP32 on a fork and did a PR for it.
Now I am trying to move that code to an ESPHome external component but I am not able to make the UART Component even work. I get no information whatsoever. This is the yaml file:
esphome:
name: ventilation-controller
friendly_name: Ventilation Controller
external_components:
- source:
type: local
path: ../../../esphome-components/components
esp32:
board: esp32dev
framework:
type: esp-idf
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "xxxxx"
ota:
- platform: esphome
password: "xxxxxxxx"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Ventilation-Controller"
password: "xxxxxxx"
captive_portal:
uart:
id: sec_touch_uart
tx_pin:
number: GPIO17
rx_pin:
number: GPIO16
baud_rate: 28800
# rx_buffer_size: 64
debug:
direction: BOTH
dummy_receiver: true
after:
delimiter: "\r\n"
sequence:
- lambda: |-
UARTDebug::log_string(direction, bytes);
UARTDebug::log_hex(direction, bytes, ',');
UARTDebug::log_int(direction, bytes, ',');
UARTDebug::log_binary(direction, bytes, ',');
# sec_touch:
# uart_id: sec_touch_uart
I am using the same ESP32 board with the exact same connection. Toggling between the pure Arduino firmware and an ESPHome build consistently the show Arduino version working while I get not logging of the UART component in ESPHome.
I have almost none experience with C++ or UART so I do not quite know what should I be searching now.
I already trying giving invert: true
to the pins, chaning the ESPHome framework to arduino an use an smaller buffer_size (like in the original code). I tried changing the TX-RX cable order (which i do not think makes sense since in the Arduino Firmware works).
The only thing I could image is that ESPHome is using “real” Serial UART, while the arduino version is using a Software version.
Any advice on how to continue or what to test would be appreciated.
Edit:
In case needed, the board:
Edit2:
I get this logs on start
[13:29:11][C][logger:185]: Logger:
[13:29:11][C][logger:186]: Level: DEBUG
[13:29:11][C][logger:188]: Log Baud Rate: 115200
[13:29:11][C][logger:189]: Hardware UART: UART0
[13:29:11][C][uart.idf:159]: UART Bus 1:
[13:29:11][C][uart.idf:160]: TX Pin: GPIO17
[13:29:11][C][uart.idf:161]: RX Pin: GPIO16
[13:29:11][C][uart.idf:163]: RX Buffer Size: 256
[13:29:11][C][uart.idf:165]: Baud Rate: 28800 baud
[13:29:11][C][uart.idf:166]: Data Bits: 8
[13:29:11][C][uart.idf:167]: Parity: NONE
[13:29:11][C][uart.idf:168]: Stop bits: 1
[13:29:11][C][captive_portal:089]: Captive Portal:
[13:29:11][C][mdns:116]: mDNS:
[13:29:11][C][mdns:117]: Hostname: ventilation-controller
[13:29:11][C][esphome.ota:073]: Over-The-Air updates:
[13:29:11][C][esphome.ota:074]: Address: ventilation-controller.local:3232
[13:29:11][C][esphome.ota:075]: Version: 2
[13:29:11][C][esphome.ota:078]: Password configured
[13:29:11][C][safe_mode:018]: Safe Mode:
[13:29:11][C][safe_mode:019]: Boot considered successful after 60 seconds
[13:29:11][C][safe_mode:021]: Invoke after 10 boot attempts
[13:29:11][C][safe_mode:022]: Remain in safe mode for 300 seconds
[13:29:11][C][api:140]: API Server:
[13:29:11][C][api:141]: Address: ventilation-controller.local:6053
[13:29:11][C][api:143]: Using noise encryption: YES
I also realized that after a while, the board crashes and do not even try to reconnect to wifi.