From 32ae70d16df9714f74d7b664810db93eaa10ea80 Mon Sep 17 00:00:00 2001 From: Hel Gibbons Date: Fri, 23 Jun 2023 11:55:25 +0100 Subject: [PATCH 1/3] SCD41: update example to use default pins --- micropython/examples/breakout_scd41/scd41_demo.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/micropython/examples/breakout_scd41/scd41_demo.py b/micropython/examples/breakout_scd41/scd41_demo.py index 8c2c19df..3020ac76 100644 --- a/micropython/examples/breakout_scd41/scd41_demo.py +++ b/micropython/examples/breakout_scd41/scd41_demo.py @@ -1,12 +1,9 @@ +import breakout_scd41 +from pimoroni_i2c import PimoroniI2C +from pimoroni import BREAKOUT_GARDEN_I2C_PINS # or PICO_EXPLORER_I2C_PINS or HEADER_I2C_PINS import time -import pimoroni_i2c -import breakout_scd41 - -PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5} -PINS_PICO_EXPLORER = {"sda": 20, "scl": 21} - -i2c = pimoroni_i2c.PimoroniI2C(**PINS_PICO_EXPLORER) +i2c = PimoroniI2C(**BREAKOUT_GARDEN_I2C_PINS) # or PICO_EXPLORER_I2C_PINS or HEADER_I2C_PINS breakout_scd41.init(i2c) breakout_scd41.start() From dc1f00013486f4e3c55ac43c205e979f40a66359 Mon Sep 17 00:00:00 2001 From: Hel Gibbons Date: Fri, 23 Jun 2023 12:11:05 +0100 Subject: [PATCH 2/3] SCD41: add Plasma 2040 example --- micropython/examples/plasma2040/co2.py | 71 ++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 micropython/examples/plasma2040/co2.py diff --git a/micropython/examples/plasma2040/co2.py b/micropython/examples/plasma2040/co2.py new file mode 100644 index 00000000..4717c550 --- /dev/null +++ b/micropython/examples/plasma2040/co2.py @@ -0,0 +1,71 @@ +import plasma +from plasma import plasma2040 +import breakout_scd41 as scd +from pimoroni_i2c import PimoroniI2C +from pimoroni import RGBLED +import time + +""" +Reads CO2 level from an SCD41 breakout... +... and changes the LED strip an appropriate colour. +https://shop.pimoroni.com/products/scd41-co2-sensor-breakout +""" + +# set how many LEDs you have +NUM_LEDS = 50 + +BRIGHTNESS = 1.0 + +# the range of readings to map to colours +# https://www.kane.co.uk/knowledge-centre/what-are-safe-levels-of-co-and-co2-in-rooms +MIN = 400 +MAX = 2000 + +# pick what bits of the colour wheel to use (from 0-360°) +# https://www.cssscript.com/demo/hsv-hsl-color-wheel-picker-reinvented/ +HUE_START = 100 # green +HUE_END = 0 # red + +# Pick *one* LED type by uncommenting the relevant line below: +# WS2812 / NeoPixel™ LEDs +led_strip = plasma.WS2812(NUM_LEDS, 0, 0, plasma2040.DAT) + +# APA102 / DotStar™ LEDs +# led_strip = plasma.APA102(NUM_LEDS, 0, 0, plasma2040.DAT, plasma2040.CLK) + +# set up I2C +i2c = PimoroniI2C(plasma2040.SDA, plasma2040.SCL) + +# set up onboard LED +led = RGBLED(plasma2040.LED_R, plasma2040.LED_G, plasma2040.LED_B) + +led.set_rgb(0, 0, 0) + +# Start updating the LED strip +led_strip.start() + +# set up SCD41 breakout +scd.init(i2c) +scd.start() + +print("Waiting for SCD41 to be ready") + +while True: + if scd.ready(): + co2, temperature, humidity = scd.measure() + print(f""" +CO2: {co2} ppm +Temperature: {temperature:.2f} °C +Humidity: {humidity:.2f} %""") + + # calculates a colour + hue = max(0, HUE_START + ((co2 - MIN) * (HUE_END - HUE_START) / (MAX - MIN))) + + # set the leds + for i in range(NUM_LEDS): + led_strip.set_hsv(i, hue / 360, 1.0, BRIGHTNESS) + + # flash the onboard LED so you can tell when the script is running + led.set_rgb(0, 255, 0) + time.sleep(0.05) + led.set_rgb(0, 0, 0) From d9064f0162692a46a16f30875f53a98bd799a0bd Mon Sep 17 00:00:00 2001 From: Hel Gibbons Date: Fri, 23 Jun 2023 15:23:41 +0100 Subject: [PATCH 3/3] SCD41: update Plasma Stick example --- micropython/examples/plasma_stick/co2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/micropython/examples/plasma_stick/co2.py b/micropython/examples/plasma_stick/co2.py index 6dc1076b..f7ecd190 100644 --- a/micropython/examples/plasma_stick/co2.py +++ b/micropython/examples/plasma_stick/co2.py @@ -48,7 +48,7 @@ Temperature: {temperature:.2f} °C Humidity: {humidity:.2f} %""") # calculates a colour - hue = HUE_START + ((co2 - MIN) * (HUE_END - HUE_START) / (MAX - MIN)) + hue = max(0, HUE_START + ((co2 - MIN) * (HUE_END - HUE_START) / (MAX - MIN))) # set the leds for i in range(NUM_LEDS):