esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
290 stars 34 forks source link

esp32s2 compile error: cannot convert 'USBCDC*' to 'HardwareSerial*' in assignment #3988

Open Mrten opened 1 year ago

Mrten commented 1 year ago

The problem

I'm trying to use an Wemos Lolin S2 Pico for a CO2 sensor, but it won't compile using the arduino framework. I'd like to add a neopixel so using esp-idf is out of the question as neopixelbus nor fastled are supported with esp-idf.

(the esp-idf framework does compile)

This is a minimal yaml to reproduce:

esphome:
  name: co2

esp32:
  board: lolin_s2_pico
  variant: esp32s2
  framework:
    type: arduino

uart:
  - rx_pin: GPIO16
    tx_pin: GPIO17
    baud_rate: 9600

This is the output when trying to compile:

INFO Reading configuration /config/esphome/co2-test.yaml...
INFO Generating C++ source...
INFO Core config or version changed, cleaning build files...
INFO Compiling app...
Processing co2 (board: lolin_s2_pico; framework: arduino; platform: platformio/espressif32 @ 5.2.0)
--------------------------------------------------------------------------------
HARDWARE: ESP32S2 240MHz, 320KB RAM, 4MB Flash
 - toolchain-riscv32-esp @ 8.4.0+2021r2-patch3 
 - toolchain-xtensa-esp32s2 @ 8.4.0+2021r2-patch3
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
No dependencies
Compiling /data/co2/.pioenvs/co2/src/esphome/components/esp32/core.cpp.o
Compiling /data/co2/.pioenvs/co2/src/esphome/components/esp32/gpio.cpp.o
Compiling /data/co2/.pioenvs/co2/src/esphome/components/esp32/preferences.cpp.o
Compiling /data/co2/.pioenvs/co2/src/esphome/components/uart/uart.cpp.o
Compiling /data/co2/.pioenvs/co2/src/esphome/components/uart/uart_component.cpp.o
Compiling /data/co2/.pioenvs/co2/src/esphome/components/uart/uart_component_esp32_arduino.cpp.o
Compiling /data/co2/.pioenvs/co2/src/esphome/components/uart/uart_component_esp8266.cpp.o
Compiling /data/co2/.pioenvs/co2/src/esphome/components/uart/uart_component_esp_idf.cpp.o
Compiling /data/co2/.pioenvs/co2/src/esphome/components/uart/uart_component_rp2040.cpp.o
Compiling /data/co2/.pioenvs/co2/src/esphome/components/uart/uart_debugger.cpp.o
Compiling /data/co2/.pioenvs/co2/src/esphome/core/application.cpp.o
Compiling /data/co2/.pioenvs/co2/src/esphome/core/color.cpp.o
Compiling /data/co2/.pioenvs/co2/src/esphome/core/component.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:90:25: error: cannot convert 'USBCDC*' to 'HardwareSerial*' in assignment
     this->hw_serial_ = &Serial;
                         ^~~~~~
*** [/data/co2/.pioenvs/co2/src/esphome/components/uart/uart_component_esp32_arduino.cpp.o] Error 1
========================== [FAILED] Took 4.78 seconds ==========================

Which version of ESPHome has the issue?

2022.12.3

What type of installation are you using?

Home Assistant Add-on

Which version of Home Assistant has the issue?

2022.12.8

What platform are you using?

ESP32

Board

wemos lolin s2 pico

Component causing the issue

UART

Changing 'board' to 'esp32dev' makes it compile and upload, but I think the esp32 isn't booting then.

LayerCakeMakes commented 1 year ago

This is definitively related to #3419

vidplace7 commented 1 year ago

@Mrten the platformio lolin_s2_pico board profile enables USB CDC by default -- this also applies to lolin_s2_mini See: https://github.com/platformio/platform-espressif32/blob/v5.2.0/boards/lolin_s2_pico.json

You can try overriding this using platformio_options > board_build.extra_flags.

Example:

esphome:
  name: co2
  platformio_options:
    board_build.extra_flags:
      - "-DARDUINO_USB_CDC_ON_BOOT=0"  # Override, defaults to '-DARDUINO_USB_CDC_ON_BOOT=1'

esp32:
  board: lolin_s2_pico
  framework:
    type: arduino

uart:
  - rx_pin: GPIO16
    tx_pin: GPIO17
    baud_rate: 9600

All I could find on USB CDC: https://docs.espressif.com/projects/esp-idf/en/v4.4.3/esp32s2/api-guides/usb-otg-console.html

Mrten commented 1 year ago

Thanks for the suggestions and the pointer to the json!

However, If I do that it compiles but does not seem to do anything after upload and reboot. There's no port anymore to connect the esphome dashboard_install to (but that would be expected I guess) so I can't see any logs.

I then added a status_led on the correct GPIO but it does not light up after boot; if I add a wifi it won't connect (and still no status light).

zuk commented 1 year ago

Adding

  platformio_options:
    board_build.extra_flags:
      - "-DARDUINO_USB_CDC_ON_BOOT=0"

to the esphome section did indeed make things work on my end. This is on a esp32-qt-py-s2. Thanks for the tip @vidplace7 !

Mrten commented 1 year ago

the stability issues were fixed by having a 470u low-esr and a 220n capacitor on the 3.3V and a 4700u capacitor on the 5V (yes, both were necessary)

Mrten commented 1 year ago

Oh, and setting the wifipower to less than the default (17?) is also still mandatory: otherwise it crashes still.

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