SOLVED (sorta!) How can I create a UART on a WEMOS ESP32-S2 Mini?

This is the top of my yaml:

esphome:
  name: myesp32s2
  friendly_name: myESP32S2

esp32:
  board: lolin_s2_mini  #esp32-s2-saola-1
  framework:
    type: arduino

# Enable logging
logger:


# Enable Home Assistant API
api:
  encryption:
    key: "....."

ota:
  password: "....."

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Myesp32S2 Fallback Hotspot"
    password: "....."

captive_portal:

uart:
  - id: uart_2
    tx_pin: GPIO39 #marked as TXD on WEMOS ESP32S2 D1
    rx_pin: GPIO37 #marked as RXD
    baud_rate: 115200
    stop_bits: 1
    parity: none
    

… and this is the compilation errors:

INFO ESPHome 2023.6.5
INFO Reading configuration /config/esphome/myesp32s2.yaml...
INFO Generating C++ source...
INFO Compiling app...
Processing myesp32s2 (board: lolin_s2_mini; framework: arduino; platform: platformio/[email protected])
--------------------------------------------------------------------------------
HARDWARE: ESP32S2 240MHz, 320KB RAM, 4MB Flash
 - toolchain-riscv32-esp @ 8.4.0+2021r2-patch5 
 - toolchain-xtensa-esp32s2 @ 8.4.0+2021r2-patch5
Dependency Graph
|-- AsyncTCP-esphome @ 1.2.2
|-- WiFi @ 2.0.0
|-- FS @ 2.0.0
|-- Update @ 2.0.0
|-- ESPAsyncWebServer-esphome @ 2.1.0
|-- DNSServer @ 2.0.0
|-- ESPmDNS @ 2.0.0
|-- noise-c @ 0.1.4
|-- Wire @ 2.0.0
Compiling /data/myesp32s2/.pioenvs/myesp32s2/src/esphome/components/uart/uart_component_esp32_arduino.cpp.o
Compiling /data/myesp32s2/.pioenvs/myesp32s2/src/main.cpp.o
src/esphome/components/uart/uart_component_esp32_arduino.cpp: In member function 'virtual void esphome::uart::ESP32ArduinoUARTComponent::setup()':
src/esphome/components/uart/uart_component_esp32_arduino.cpp:91:25: error: cannot convert 'USBCDC*' to 'HardwareSerial*' in assignment
     this->hw_serial_ = &Serial;
                         ^~~~~~
*** [/data/myesp32s2/.pioenvs/myesp32s2/src/esphome/components/uart/uart_component_esp32_arduino.cpp.o] Error 1
========================= [FAILED] Took 12.53 seconds =========================

Thanks for any help you can offer.
Regards, Martin

To answer my own question…
It seems that one solution is to add a “platformio_options:”. My minimum yaml now becomes:

esphome:
  name: myesp32s2
  friendly_name: myESP32S2
  platformio_options:
    board_build.extra_flags:
      - "-DARDUINO_USB_CDC_ON_BOOT=0"

esp32:
  board: lolin_s2_mini  #esp32-s2-saola-1
  framework:
    type: arduino
  
# Enable logging
logger:
  #hardware_uart: my_uart
  level: DEBUG
  
# Enable Home Assistant API
api:
  encryption:
    key: ""

ota:
  password: ""

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Myesp32S2 Fallback Hotspot"
    password: ""

captive_portal:

uart:
  - id: my_uart
    tx_pin: GPIO37 #marked as RXD on WEMOS ESP32S2 D1
    rx_pin: GPIO39 #marked as TXD
    baud_rate: 115200
    stop_bits: 1
    parity: none

SO… This leads to two more questions!

  1. Where is the documentation for “platformio_options:”?
  2. How do I get my defined UART (my_uart) to be a sink for the LOGGER?

Regards, Martin

Finally got this working with the S2 mini. What are these acual sensors though? Is there an explanation for them?

Thanks :slight_smile:

sensor:

  • platform: ld2410

    moving_distance:

    name : Moving Distance

    still_distance:

    name: Still Distance

    moving_energy:

    name: Move Energy

    still_energy:

    name: Still Energy

    detection_distance:

    name: Detection Distance

Thanks for sharing this! Works great for me

This has worked for me today with a wemos S2 Mini v1.0.0 board today:

esphome:
  name: xyz
  friendly_name: xyz

esp32:
  board: lolin_s2_mini
  framework: 
    type: esp-idf

# Enable logging
logger:
  level: DEBUG

# Enable Home Assistant API
api:
  encryption:
    key: "abc"

ota:
  password: "cde"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "xyz Fallback Hotspot"
    password: "fgh"

captive_portal:
    
uart:
  - id: my_uart
    tx_pin: GPIO37 #marked as RXD on WEMOS ESP32S2 D1
    rx_pin: GPIO39 #marked as TXD
    baud_rate: 115200
    stop_bits: 1
    parity: none

Flash via:

esptool.py write_flash 0x0 your.bin