Driver for SCD30 CO2 Sensor

Discuss development of drivers for external hardware and components, such as LCD screens, sensors, motor drivers, etc.
Target audience: Users and developers of drivers.
Post Reply
mnvk52
Posts: 11
Joined: Sat Sep 05, 2020 5:31 pm

Driver for SCD30 CO2 Sensor

Post by mnvk52 » Sun Jan 10, 2021 12:26 pm

Hey,
I want to read a SCD30 CO2 Sensor with an ESP32.
I found this driver: https://github.com/agners/micropython-scd30
Trying the example:

Code: Select all

import time
from machine import I2C, Pin
from scd30 import SCD30

i2cbus = I2C(1)
scd30 = SCD30(i2c, 0x61)

while True:
    # Wait for sensor data to be ready to read (by default every 2 seconds)
    while scd30.get_status_ready() != 1:
        time.sleep_ms(200)
    scd30.read_measurement()
doesn't work:

Code: Select all

>>> %Run -c $EDITOR_CONTENT
Traceback (most recent call last):
  File "<stdin>", line 6, in <module>
NameError: name 'i2c' isn't defined
not a surprise because the variable i2c is not defined. How can I do that? I didn't find anything in the readme.

mnvk52
Posts: 11
Joined: Sat Sep 05, 2020 5:31 pm

Re: Driver for SCD30 CO2 Sensor

Post by mnvk52 » Sun Jan 10, 2021 12:32 pm

I found a solution

Code: Select all

i2c = I2C(scl=Pin(22), sda=Pin(21), freq=10000)
Thanks for reading :)

mnvk52
Posts: 11
Joined: Sat Sep 05, 2020 5:31 pm

Re: Driver for SCD30 CO2 Sensor

Post by mnvk52 » Sun Jan 10, 2021 5:41 pm

I encountered an issue. I have modified the example and added a print of the values

Code: Select all

import time
from machine import I2C, Pin
from scd30 import SCD30

i2cbus = I2C(1)
i2c = I2C(scl=Pin(22), sda=Pin(21), freq=10000)
scd30 = SCD30(i2c, 0x61)

while True:
    # Wait for sensor data to be ready to read (by default every 2 seconds)
    while scd30.get_status_ready() != 1:
        time.sleep_ms(200)
    print(scd30.read_measurement())
After some time (seconds to minutes) there is an error:

Code: Select all

>>> %Run -c $EDITOR_CONTENT
(870.4922, 22.77562, 34.85107)
(867.943, 22.80499, 34.83124)
(865.1123, 22.77562, 34.69849)
(862.2131, 22.77562, 34.69849)
(862.3291, 22.79164, 34.70001)
(860.758, 22.81834, 34.74426)
(859.4007, 22.79164, 34.75037)
(859.452, 22.80499, 34.80377)
(859.2345, 22.80499, 34.84497)
(858.7045, 22.79164, 34.82819)
(858.1632, 22.79164, 34.82819)
(857.4939, 22.77562, 34.7641)
(855.0312, 22.77562, 34.80072)
(854.8871, 22.77562, 34.81445)
(853.2128, 22.77562, 34.77631)
(852.5694, 22.76227, 34.77325)
(853.7568, 22.76227, 34.81445)
(853.0764, 22.76227, 34.80072)
(851.2052, 22.76227, 34.78699)
(850.1311, 22.76227, 34.76257)
(849.3401, 22.74891, 34.81293)
(848.5746, 22.77562, 34.85107)
(848.2946, 22.76227, 34.87701)
(848.6511, 22.76227, 34.92737)
(847.8842, 22.76227, 34.89075)
(848.0656, 22.76227, 34.92737)
(847.8646, 22.74891, 34.9411)
(847.7996, 22.77562, 34.97925)
(847.8042, 22.73289, 34.87396)
(846.7725, 22.77562, 34.81445)
(846.6022, 22.74891, 34.82361)
(846.6348, 22.77562, 34.90448)
(846.3162, 22.71954, 34.86023)
(845.8603, 22.71954, 34.79614)
(845.9128, 22.74891, 34.79919)
(844.8734, 22.71954, 34.82208)
(844.1621, 22.73289, 34.91364)
(842.8937, 22.70618, 34.91058)
(843.0404, 22.74891, 34.99146)
(843.6476, 22.71954, 34.92432)
(843.8562, 22.73289, 34.93805)
(844.2594, 22.71954, 35.31799)
(845.3938, 22.71954, 35.38208)
(846.0004, 22.69283, 35.34088)
(847.3644, 22.67681, 35.35309)
(848.2602, 22.69283, 35.20203)
(848.9667, 22.69283, 35.13794)
(849.6739, 22.70618, 35.07538)
(850.7389, 22.73289, 35.05249)
(852.0377, 22.69283, 35.04791)
(852.197, 22.70618, 34.97314)
(852.8499, 22.73289, 35.01587)
(853.2266, 22.71954, 35.06165)
(853.8171, 22.71954, 35.06165)
(853.2935, 22.69283, 35.03418)
(853.2643, 22.69283, 34.99756)
(853.115, 22.70618, 34.98688)
Traceback (most recent call last):
  File "<stdin>", line 12, in <module>
  File "scd30.py", line 95, in get_status_ready
  File "scd30.py", line 161, in __read_bytes
OSError: [Errno 110] ETIMEDOUT
After that I can restart it, but it's resulting with the same error.
Any ideas?

Post Reply