SCD30 CO2 Sensor using ESP32-S3-DEVKITC-1 with ESPHOME

Hi all, wanted to share a small issue I was having with th I2C interfaces. I initially tried GPIO pins 8 and 9 to control the SCD30. This worked for about 3-4 minutes, and then sensor starting timing out and hanging the esp32 device. I then tried various other GPIOS, including 43&44, 11&12, but was faced with the same issue. I have 2 kits, so I know it was some sort of configuration issue. I finally tried pins 1&2 and this did the trick. Both are stable. Here is the yaml contents for anyone interested:

 esphome:
  name: esphome-s3
  friendly_name: ESPHome s3

esp32:
  board: esp32-s3-devkitc-1
  framework:
    type: arduino

# Enable logging
logger:
....
i2c:
  sda: GPIO1
  scl: GPIO2
  scan: True
  id: bus_a
  
sensor:
  - platform: scd30
    co2:
      name: "CO2 Sensor1"
      accuracy_decimals: 1
    temperature:
      name: "Temperature 1"
      accuracy_decimals: 2
    humidity:
      name: "Humidity 1"
      accuracy_decimals: 1
    address: 0x61
    i2c_id: bus_a
    update_interval: 30s

Interesting findings. According to the hardware design guidelines GPIO0 is a bad choice as it is a bootstrapping pin:

Additionally

GPIO1, 2, 8 and 9 all appear to have the same start up glitch specification:

In terms of mcu, 3-4 mins is an eternity, so I doubt the 60µs glitches are related.

Call me Capt. Obvious, but have you tried that sensor on another ESP model, and tried another I²C sensor on that one, with the same results?

Yeah I was actually pointing out that there should be no difference between the first and second set of GPIOs used. Other than GPIO0 being a potentially dangerous choice.

1 Like

Thanks for the comments. I have one working set (S3+SCD30) using pins 1 and 2. However on the second set (also using pins 1 and 2), I seem to have lost both my USB ports (com, and jtag). When I plug in using the COM port, I get the error that the USB device is not recognized and can’t retreive logs from the device through wi-fi. Using the other USB port, nothing happens. I can still flash the unit and collect logs over wi-fi using Esphome. In this “bad” unit, it may work for a minute or 2 but then start to timeout. It sometimes also becomes unresponsive as well but I can ping it. The tx LED is always green? It seems to flash now and then? Which pins would you recommend for I2C connections? edit: Forgot to mention that the reset button no longer seems to work. In the log after power down/up, I sometimes get the error: reset failed, will go into safe mode after 8 failures

Log of bad set:

NFO ESPHome 2023.7.1
INFO Reading configuration /config/esphome/esphome-web-2fb0d8.yaml…
INFO Starting log output from esphome-web-2fb0d8.local using esphome API
WARNING Can’t connect to ESPHome API for esphome-web-2fb0d8.local: Error connecting to (‘192.168.2.180’, 6053): [Errno 111] Connect call failed (‘192.168.2.180’, 6053) (SocketAPIError)
INFO Trying to connect to esphome-web-2fb0d8.local in the background
INFO Successfully connected to esphome-web-2fb0d8.local
[11:30:51][I][app:102]: ESPHome version 2023.7.1 compiled on Aug 11 2023, 11:13:02
[11:30:51][C][wifi:543]: WiFi:
[11:30:51][C][wifi:379]: Local MAC: 48:27:E2:2F:B0:D8
[11:30:51][C][wifi:380]: SSID: ‘ace-2.4’[redacted]
[11:30:51][C][wifi:381]: IP Address: 192.168.2.180
[11:30:51][C][wifi:383]: BSSID: 00:03:7F:82:46:76[redacted]
[11:30:51][C][wifi:384]: Hostname: ‘esphome-web-2fb0d8’
[11:30:51][C][wifi:386]: Signal strength: -26 dB ▂▄▆█
[11:30:51][C][wifi:390]: Channel: 6
[11:30:51][C][wifi:391]: Subnet: 255.255.255.0
[11:30:51][C][wifi:392]: Gateway: 192.168.2.2
[11:30:51][C][wifi:393]: DNS1: 192.168.2.2
[11:30:51][C][wifi:394]: DNS2: 0.0.0.0
[11:30:51][C][logger:301]: Logger:
[11:30:51][C][logger:302]: Level: DEBUG
[11:30:51][C][logger:303]: Log Baud Rate: 115200
[11:30:51][C][logger:305]: Hardware UART: UART0
[11:30:51][C][i2c.arduino:053]: I2C Bus:
[11:30:51][C][i2c.arduino:054]: SDA Pin: GPIO1
[11:30:51][C][i2c.arduino:055]: SCL Pin: GPIO2
[11:30:51][C][i2c.arduino:056]: Frequency: 50000 Hz
[11:30:51][C][i2c.arduino:059]: Recovery: bus successfully recovered
[11:30:51][I][i2c.arduino:069]: Results from i2c bus scan:
[11:30:51][I][i2c.arduino:075]: Found i2c device at address 0x61
[11:30:51][C][scd30:120]: scd30:
[11:30:51][C][scd30:121]: Address: 0x61
[11:30:51][C][scd30:139]: Altitude compensation: OFF
[11:30:51][C][scd30:143]: Automatic self calibration: ON
[11:30:51][C][scd30:144]: Ambient pressure compensation: 0mBar
[11:30:51][C][scd30:145]: Temperature offset: 0.00 °C
[11:30:51][C][scd30:146]: Update interval: 60s
[11:30:51][C][scd30:147]: CO2 ‘CO2 Sensor 2’
[11:30:51][C][scd30:147]: Device Class: ‘carbon_dioxide’
[11:30:51][C][scd30:147]: State Class: ‘measurement’
[11:30:51][C][scd30:147]: Unit of Measurement: ‘ppm’
[11:30:51][C][scd30:147]: Accuracy Decimals: 1
[11:30:51][C][scd30:147]: Icon: ‘mdi:molecule-co2’
[11:30:51][C][scd30:148]: Temperature ‘Temperature 2’
[11:30:51][C][scd30:148]: Device Class: ‘temperature’
[11:30:51][C][scd30:148]: State Class: ‘measurement’
[11:30:51][C][scd30:148]: Unit of Measurement: ‘°C’
[11:30:51][C][scd30:148]: Accuracy Decimals: 2
[11:30:51][C][scd30:149]: Humidity ‘Humidity 2’
[11:30:51][C][scd30:149]: Device Class: ‘humidity’
[11:30:51][C][scd30:149]: State Class: ‘measurement’
[11:30:51][C][scd30:149]: Unit of Measurement: ‘%’
[11:30:51][C][scd30:149]: Accuracy Decimals: 1
[11:30:51][C][captive_portal:088]: Captive Portal:
[11:30:51][C][mdns:112]: mDNS:
[11:30:51][C][mdns:113]: Hostname: esphome-web-2fb0d8
[11:30:51][C][ota:093]: Over-The-Air Updates:
[11:30:51][C][ota:094]: Address: esphome-web-2fb0d8.local:3232
[11:30:51][C][api:138]: API Server:
[11:30:51][C][api:139]: Address: esphome-web-2fb0d8.local:6053
[11:30:51][C][api:141]: Using noise encryption: YES
[11:30:54][W][component:204]: Component scd30.sensor took a long time for an operation (0.06 s).
[11:30:54][W][component:205]: Components should block for at most 20-30ms.
[11:30:56][W][component:204]: Component scd30.sensor took a long time for an operation (1.00 s).
[11:30:56][W][component:205]: Components should block for at most 20-30ms.
[11:30:57][W][component:204]: Component scd30.sensor took a long time for an operation (1.00 s).
[11:30:57][W][component:205]: Components should block for at most 20-30ms.

I have 2 separate units: ESP32-S3+SCD30 (1), ESP32-S3+SCD30 (2). Both the units were having timeout issues when using pins other than 1 & 2. One unit is “perfect”. It ran all night and no issues this morning. The second unit is having issues as described in my response below

I managed to get the bad set working by trying different combinations of boot + reset and separating out the dupont wires away from each other. I still have the USB issues but at least the sensor is now reporting reliably at least within an hour

[12:25:56][D][scd30:186]: Got CO2=101.87ppm temperature=24.06°C humidity=47.07%
[12:25:56][D][sensor:094]: ‘CO2 Sensor 2’: Sending state 101.87086 ppm with 1 decimals of accuracy
[12:25:57][D][sensor:094]: ‘Temperature 2’: Sending state 24.06271 °C with 2 decimals of accuracy
[12:25:57][D][sensor:094]: ‘Humidity 2’: Sending state 47.06879 % with 1 decimals of accuracy
[12:26:22][I][ota:113]: Boot seems successful, resetting boot loop counter.
[12:26:22][D][esp32.preferences:114]: Saving 1 preferences to flash…
[12:26:22][D][esp32.preferences:143]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[12:27:05][D][scd30:186]: Got CO2=112.81ppm temperature=24.15°C humidity=47.37%
[12:27:05][D][sensor:094]: ‘CO2 Sensor 2’: Sending state 112.80892 ppm with 1 decimals of accuracy
[12:27:05][D][sensor:094]: ‘Temperature 2’: Sending state 24.14549 °C with 2 decimals of accuracy
[12:27:05][D][sensor:094]: ‘Humidity 2’: Sending state 47.36633 % with 1 decimals of accuracy

How long are your I2C wires?

20cm/8 inches. A bit too long? Should I try a twisted pair instead or just get shorter 10 cm wires?

Getting a bit long. Have a read of the note at bottom part of this post: Outdoor Lux Sensor

1 Like

Thanks! I put much shorter wires for the I2C (about 8cm), and ran it overnight. It ran good for several hours (this is the one with the USB issue) but I woke up this morning to find the unit unresponsive. The other unit with the longer wires has been rock solid. I think I have a defective esp32-s3 dev kit, as there is no USB connection possible. Anything I can do to confirm that I have a HW issue and not a SW issue?

Only Chris’s suggestion above, unless you have an i2C protocol analyser with logging?

Actually, I disconnected the sensor from the esp32 and still have the same issue where the esp32 is unresponsive and USB is not recognized so right now it doesn’t seem to be related to the sensor

Power supply issues perhaps?

What are you powering it with (V @ Amps)?

Suspected that too initially. Tried USB from a computer, phone chargers: 5V 750ma, and 5V 3A. It was using 5V 3A charger yesterday and is unresponsive now. Other set was tested using the same power with no issues so far

If you have one, try putting a smoothing capacitor (any value from 220uF and up) from the 3.3V (not 5V) pin to GND on the ESP Board.

I used a 470uf one, and no difference. Still unresponsive. Power light is on only. When I press boot or rst button, light goes off and when I release it comes on. When USB is connected to COM port, laptop says USB device is not recognized. When connected to USB port, laptop detects nothing.

Cpt Obvious strikes back.

Would you have another esp32-s3-devkitc-1 that you could flash with the same firmware?
If that one works, Cpt Obvious tells you: That board is defect.

Yes I have done that and other board is working perfectly. I am planning to ship the defective board back.