Problems getting SCD30 over i²c to work

Hi there!
I have an CO2 meter, which I wanted to connect to Homeassistant, so I soldered wires to everything Important, disabled the original chip and installed an D1 mini esp8266.
The device has an SCD30 sensor installed. My problem is, that the sensor is not recognized by the ESP, it says:

[20:01:00][C][i2c.arduino:053]: I2C Bus:
[20:01:00][C][i2c.arduino:054]:   SDA Pin: GPIO13
[20:01:00][C][i2c.arduino:055]:   SCL Pin: GPIO16
[20:01:00][C][i2c.arduino:056]:   Frequency: 50000 Hz
[20:01:00][C][i2c.arduino:062]:   Recovery: failed, SCL is held low on the bus
[20:01:00][I][i2c.arduino:069]: Results from i2c bus scan:
[20:01:00][I][i2c.arduino:071]: Found no i2c devices!

This is my esphome yaml:


switch:
  - platform: gpio
    pin: D8
    id: SCD30_pwr
    restore_mode: ALWAYS_ON

ota:
  password: "..."

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

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

captive_portal:

output:
  - platform: esp8266_pwm
    pin: D5
    id: rtttl_pwm
    frequency: 4000hz
  - platform: esp8266_pwm
    pin: D2
    id: red
  - platform: esp8266_pwm
    pin: GPIO3
    id: green
  - platform: esp8266_pwm
    pin: D1
    id: blue

rtttl:
  output: rtttl_pwm
  id: beeper
  on_finished_playback:
    - logger.log: 'Song ended!'

light:
  - platform: rgb
    name: "CO2_Led"
    red: red
    green: green
    blue: blue

i2c:
  sda: D7
  scl: D0
  scan: true

sensor:
  - platform: scd30
    co2:
      name: "..._co2"
      accuracy_decimals: 1
    temperature:
      name: "..._temperature"
      accuracy_decimals: 2
    humidity:
      name: "..._humidity"
      accuracy_decimals: 1
    update_interval: 5s
    automatic_self_calibration: True

The LEDs and the Buzzer are working.

I connected an Oscilloscope and captured the I²C signals from the original chip (which worked) and esphome:

This is the working scl signal.
This is the esphome signal (looks similar), but the bursts happen in bigger Intervals.

This is what the working sda bus looks like
Thats a whole lot of nothing on the sda bus with the esp

Can somebody help me with this?

You can’t use D0 (GPIO16) for I2C, or much else for that matter. Have a read:

Oh, okay, thanks
I knew some limitations but not this one, because I used this chart:

something changed:

[22:06:33][C][i2c.arduino:053]: I2C Bus:
[22:06:33][C][i2c.arduino:054]:   SDA Pin: GPIO13
[22:06:33][C][i2c.arduino:055]:   SCL Pin: GPIO2
[22:06:33][C][i2c.arduino:056]:   Frequency: 50000 Hz
[22:06:33][C][i2c.arduino:059]:   Recovery: bus successfully recovered
[22:06:33][I][i2c.arduino:069]: Results from i2c bus scan:
[22:06:33][I][i2c.arduino:071]: Found no i2c devices!

But it still doesn’t find any devices :frowning:

Hmm ok. As you can see the signals the power side is ok. Only suggestion I have is to fiddle with the I2C bus frequency settings.

hm, okay… I’ll do that

I have analysed the signal a bit:
In the very moment i power the ESP a burst of data gets send out on the SDA and SCL lines. After that nothing happenes.

this is what the SCL should look like:

I tested it with an Arduino Uno and the Adafruit liberary and the sensor + cables definitely work!
FAlritS1

That’s it scanning the bus looking for devices (which it then doesn’t find).

Maybe it’s a power issue (the UNO is 5V). Have you tried powering from VIN (5V) instead of 3.3V? That’s within the acceptable range for a SCD30.

I just tried it with a “clean configuration”.
the same ESP but with only the bare minimum connected and all unecesary code removed and the sensor on GPIO4 and GPIO5.
And it worked!
I guess I have some soldering to do in order to change the pins…

Lol! Bummer - although there is no reason it shouldn’t work on the final pins you chose.

This is why I breadboard most projects first. :slight_smile:

I rewired everything, changed the code and…
…got the same error again

Maybe something to do with the esp8266_pwm driving your lights. That’s a software PWM implementation and maybe it’s stuffing up the I2C timing enough to mess with detections.

Do you have a spare ESP32?

I sadly don’t but that also is what I am suspecting

nope, I removed the pwm code and its still broken…

okay, this time it was a software oopsie on my behalf

It works!!!
And I really don’t know why…

1 Like