esphome / issues

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

SenseAir S8 - Reading from UART timed out | Reading data from SenseAir failed #795

Closed reinisb closed 4 years ago

reinisb commented 4 years ago

Operating environment/Installation (Hass.io/Docker/pip/etc.):

ESPHome 1.14.0, Hass.io, Virtualbox

ESP (ESP32/ESP8266, Board/Sonoff):

SparkFun ESP32 Thing (3.3v) + SparkFun Logic Level Converter - Single Supply (3.3v -> 5v)

Affected component:

https://esphome.io/components/sensor/senseair.html

Description of problem: Today I tried setting up the SenseAir S8 sensor for the very first time, but I have not succeeded as the reading from the sensor always fails. I suppose the issue lies somewhere with UART. I would appreciate if you could please help. Thanks!

Problem-relevant YAML-configuration entries:

esphome:
  name: sparkfun_node
  platform: ESP32
  board: esp32thing

wifi:
  ssid: "erased"
  password: "erased"

switch:
  - platform: gpio
    name: "The Blue LED"
    pin: 5

uart:
  tx_pin: 17
  rx_pin: 16
  baud_rate: 9600
  id: "mans_uart"

sensor:
  - platform: senseair
    co2:
      name: "SenseAir CO2 Value"
    update_interval: 10s
    uart_id: "mans_uart"

# Enable logging
logger:
  level: VERY_VERBOSE
  # Disable UART Logging
  # baud_rate: 0

# Enable Home Assistant API
api:

ota:

Logs (if applicable):

[00:00:11][I][app:100]: ESPHome version 1.14.0 compiled on Nov  1 2019, 23:56:36
[00:00:12][C][wifi:409]: WiFi:
[00:00:12][C][wifi:277]:   SSID: [redacted]
[00:00:12][C][wifi:278]:   IP Address: 10.99.99.106
[00:00:12][C][wifi:280]:   BSSID: [redacted]
[00:00:12][C][wifi:281]:   Hostname: 'sparkfun_node'
[00:00:12][C][wifi:285]:   Signal strength: -31 dB ▂▄▆█
[00:00:12][V][wifi:287]:   Priority: 0.0
[00:00:12][C][wifi:289]:   Channel: 9
[00:00:12][C][wifi:290]:   Subnet: 255.255.255.0
[00:00:12][C][wifi:291]:   Gateway: 10.99.99.100
[00:00:12][C][wifi:292]:   DNS1: 10.99.99.100
[00:00:12][C][wifi:293]:   DNS2: 0.0.0.0
[00:00:12][C][uart:040]: UART Bus:
[00:00:12][C][uart:042]:   TX Pin: GPIO17
[00:00:12][C][uart:045]:   RX Pin: GPIO16
[00:00:12][C][uart:047]:   Baud Rate: 9600 baud
[00:00:12][C][uart:048]:   Stop bits: 1
[00:00:12][C][switch.gpio:042]: GPIO Switch 'The Blue LED'
[00:00:12][C][switch.gpio:043]:   Pin: GPIO5 (Mode: OUTPUT)
[00:00:12][C][switch.gpio:059]:   Restore Mode: Restore (Defaults to OFF)
[00:00:12][C][logger:175]: Logger:
[00:00:12][C][logger:176]:   Level: VERY_VERBOSE
[00:00:12][C][logger:177]:   Log Baud Rate: 115200
[00:00:12][C][logger:178]:   Hardware UART: UART0
[00:00:12][C][senseair:074]: SenseAir:
[00:00:12][C][senseair:075]:   CO2 'SenseAir CO2 Value'
[00:00:12][C][senseair:075]:     Unit of Measurement: 'ppm'
[00:00:12][C][senseair:075]:     Accuracy Decimals: 0
[00:00:12][C][senseair:075]:     Icon: 'mdi:periodic-table-co2'
[00:00:12][C][ota:029]: Over-The-Air Updates:
[00:00:12][C][ota:030]:   Address: sparkfun_node.local:3232
[00:00:12][C][api:095]: API Server:
[00:00:12][C][api:096]:   Address: sparkfun_node.local:6053
[00:00:17][VV][api.service:250]: on_ping_request: PingRequest {}
[00:00:17][VV][api.service:035]: send_ping_response: PingResponse {}
[00:00:18][VV][api.service:250]: on_ping_request: PingRequest {}
[00:00:18][VV][api.service:035]: send_ping_response: PingResponse {}
[00:00:19][VV][scheduler:131]: Running interval 'update' with interval=10000 last_execution=139024 (now=149024)
[00:00:19][VV][uart:109]:     Flushing...
[00:00:19][VV][uart:064]:     Wrote 0b11111110 (0xFE)
[00:00:19][VV][uart:064]:     Wrote 0b00000100 (0x04)
[00:00:19][VV][uart:064]:     Wrote 0b00000000 (0x00)
[00:00:19][VV][uart:064]:     Wrote 0b00000000 (0x00)
[00:00:19][VV][uart:064]:     Wrote 0b00000000 (0x00)
[00:00:19][VV][uart:064]:     Wrote 0b00000100 (0x04)
[00:00:19][VV][uart:064]:     Wrote 0b11100101 (0xE5)
[00:00:19][VV][uart:064]:     Wrote 0b11000110 (0xC6)
[00:00:20][E][uart:101]: Reading from UART timed out at byte 5!
[00:00:21][VV][uart:109]:     Flushing...
[00:00:21][W][senseair:015]: Reading data from SenseAir failed!
[00:00:21][V][app:076]: A component took a long time in a loop() cycle (1.05 s).
[00:00:21][V][app:077]: Components should block for at most 20-30ms in loop().
[00:00:23][VV][api.service:250]: on_ping_request: PingRequest {}
[00:00:23][VV][api.service:035]: send_ping_response: PingResponse {}
[00:00:28][VV][api.service:250]: on_ping_request: PingRequest {}
[00:00:29][VV][api.service:035]: send_ping_response: PingResponse {}
[00:00:29][VV][scheduler:131]: Running interval 'update' with interval=10000 last_execution=149024 (now=159025)
[00:00:30][VV][uart:109]:     Flushing...
[00:00:30][VV][uart:064]:     Wrote 0b11111110 (0xFE)
[00:00:30][VV][uart:064]:     Wrote 0b00000100 (0x04)
[00:00:30][VV][uart:064]:     Wrote 0b00000000 (0x00)
[00:00:30][VV][uart:064]:     Wrote 0b00000000 (0x00)
[00:00:30][VV][uart:064]:     Wrote 0b00000000 (0x00)
[00:00:30][VV][uart:064]:     Wrote 0b00000100 (0x04)
[00:00:30][VV][uart:064]:     Wrote 0b11100101 (0xE5)
[00:00:30][VV][uart:064]:     Wrote 0b11000110 (0xC6)
[00:00:30][E][uart:101]: Reading from UART timed out at byte 7!
[00:00:30][VV][uart:109]:     Flushing...
[00:00:30][W][senseair:015]: Reading data from SenseAir failed!
[00:00:30][V][app:076]: A component took a long time in a loop() cycle (1.05 s).
[00:00:30][V][app:077]: Components should block for at most 20-30ms in loop().
[00:00:33][VV][api.service:250]: on_ping_request: PingRequest {}
[00:00:33][VV][api.service:035]: send_ping_response: PingResponse {}
[00:00:34][VV][api.service:250]: on_ping_request: PingRequest {}
[00:00:34][VV][api.service:035]: send_ping_response: PingResponse {}

Additional information and things you've tried: The sensor light blinks every 10 seconds or so, hence the sensor is powered. I tried swapping rx_pin/rx_pin values, nothing changes, the same error.

PS GPIO Switch 'The Blue LED' works, hence I at least know that communication with the board works, but I suppose something is wrong with UART.

IMG_3931

reinisb commented 4 years ago

It is clear that the Senseair S8 LP sensor requires 5V power supply. Now, what about the logic pins (UART_RxD and UART_TxD) - do they require 5V as well? Or are they 3.3V? If they require only 3.3V then there is no need for the 5V-to-3.3V logic converter (which does not work anyway).

OttoWinter commented 4 years ago

Those will be 5V level too. Technically you should shift that to 3.3V for the ESP, but I've successfully used 5V on those pins already. You just have to be careful you don't mix up TX/RX.

reinisb commented 4 years ago

@OttoWinter so you are saying that Senseair S8 LP has 5V both on power (G+) and logic pins (UART_RxD and UART_TxD). In that case, something is wrong with my logic converter. I have an ESP32 board with 5V power-out pin and 3.3v TX/RX logic pins. When I connect the 5V power pin along ground to the sensor, then the sensor powers on properly. If I then connect the 3.3V TX/RX pins to sensor's 5V(?) UART_RxD/UART_TxD pins then I can read sensor readings. So everything works.

Now, when I connect the 3.3V TX/TX pins via a 3.3V-to-5V logic level shifter to the UART_RxD/UART_TxD then I cannot read sensor readings. Can you please confirm that connecting ESP32 3.3V logic level TX/RX to the sensor via a 3.3V-to-5V logic level shifter work for you and you can read sensor readings?

OttoWinter commented 4 years ago

It should work if the logic level conversion is bi-directional (or uni-directional but different for each pin).

I don't have that device here, so I can't test it. I can only tell you I successfully used an MH-Z19 with the same 5V setup.

reinisb commented 4 years ago

I have the SparkFun Logic Level Converter - Single Supply, which seems to be bi-directional. I am pretty sure that the Senseair S8 LP has TX/RX pins that operate at 3.3v (not 5v) - I would appreciate it if anyone could please confirm. Thanks!

OttoWinter commented 4 years ago

@reinisb You can check that with a multimeter.

But as you noted, it works fine when connecting it directly, which means it's an issue with how you connected the device, not a software bug. I will therefore close this report - if a solution is found please update the docs.