pimoroni-pico/micropython/modules/breakout_scd41
Phil Howard 6a3ba0d421 MicroPython: Shim MP_REGISTER_MODULE for >1.18 compat.
MicroPython has changed MP_REGISTER_MODULE to use only *two* args and now runs the preprocessing stage on files before running makemoduledefs.py.

This change avoids the build exploding, since the new regex matches the last two args as a single argument and generates a malformed module defs include.

The pattern here exploits the fact that 1.18 and below do not preprocess files, so *both* MP_REGISTER_MODULE lines are included in the source, but *only* the three arg version is matched by regex.

In >1.18 the files will be processed and the three arg version removed before makemoduledefs.py processes it.
2022-06-14 12:08:47 +01:00
..
README.md Add SCD41 MicroPython bindings 2021-12-16 11:39:34 +00:00
breakout_scd41.c MicroPython: Shim MP_REGISTER_MODULE for >1.18 compat. 2022-06-14 12:08:47 +01:00
breakout_scd41.cpp MicroPython: Promote machine.I2C() to PimoroniI2C. 2022-05-18 13:20:33 +01:00
breakout_scd41.h Add SCD41 MicroPython bindings 2021-12-16 11:39:34 +00:00
micropython.cmake Add SCD41 MicroPython bindings 2021-12-16 11:39:34 +00:00

README.md

SCD41 CO2 Sensor Driver

Getting Started

Construct a new PimoroniI2C instance for your specific board. Breakout Garden uses pins 4 & 5 and Pico Explorer uses pins 20 & 21.

Since SCD41 has a fixed I2C address and the Sensirion SCD4x library is used under the hood, it's wrapped up as a module for Python.

Import the breakout_scd41 and call init to set up I2C:

import time

import pimoroni_i2c
import breakout_scd41

i2c = pimoroni_i2c.PimoroniI2C(4, 5)

breakout_scd41.init(i2c)

Taking Measurements

Before taking a measurement you must start periodic measurement by calling start().

Poll on ready() and use measure() to read the result when it's True:

breakout_scd41.start()

while True:
    if breakout_scd41.ready():
        co2, temperature, humidity = breakout_scd41.measure()
        print(co2, temperature, humidity)
        time.sleep(1.0)

The measure() method will return a Tuple containing the CO2 reading, temperature in degrees C and humidity.