SCD4X on Pi Pico W (fcntl error)

Afternoon all

I recently received a Pico W, along with an Pico Explorer base and an SCD41 (CO2/Temp/Humidity Sensor), and I’m keen to get even a basic example working. I’ve done a very small amount of IOT tinkering in the past, though please assume that I don’t know enough about it to really understand all the intricacies and technicalities.

I’ve gone through the process of adding the latest release of the Pimoroni firmware (1.20.3 as of writing - github[dot]com/pimoroni/pimoroni-pico/releases/tag/v1.20.3) to the Pico (I’ve made sure to use the W firmware), and demos such as the temperature graph and balls demo all work brilliantly.

I’m now trying to get the SCD4X library added (https://github[dot]com/pimoroni/scd4x-python/tree/main). I’m working on Windows and using Thonny. I added the library via Thonny package manager (Tools > Manage packages > scd4x) which also installs the smbus2 library as a requirement.

When I try to run any of the examples (e.g. scd4x-python/examples/bargraph.py at main · pimoroni/scd4x-python · GitHub), it reports the folowing:

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/lib/scd4x/__init__.py", line 3, in <module>
  File "/lib/smbus2/__init__.py", line 23, in <module>
  File "/lib/smbus2/smbus2.py", line 25, in <module>
ImportError: no module named 'fcntl'

I’ve tracked this down to the smbus2 library. I understand fcntl isn’t available on Windows, but my understanding was that the code I’m adding in via Thonny would be executed on the Pi - so if a package like fcntl isn’t present on Windows, that wouldn’t matter.

I’ve confirmed that the interpreter settings are correct (Micropython raspberry pi pico, Board CDC @ COM11) - which is evidenced by the Pimoroni ‘basic’ examples working as expected on the device.

I do have WSL available on my Windows machine, and I’ve also got a Mac available, but I prefer to use a GUI for the ease of running and stopping samples, installing packages, etc.

Ideally for a first example, I’d like to output the data from the SCD41 to the Pico Explorer screen, but the ultimate goal will be to send the data to a HomeAssistant instance (likely via MQTT).

Can anyone offer any advice?

EDIT: It appears the example at (github[dot]com/pimoroni/pimoroni-pico/blob/main/micropython/examples/breakout_scd41/scd41_demo.py) works effectively. I’ll leave this post here in case anyone else stumbles upon the same issue.

For brevity and future people, this is the code of the demo:

import breakout_scd41
from pimoroni_i2c import PimoroniI2C
from pimoroni import PICO_EXPLORER_I2C_PINS  # or PICO_EXPLORER_I2C_PINS or HEADER_I2C_PINS
import time

i2c = PimoroniI2C(**PICO_EXPLORER_I2C_PINS)  # or PICO_EXPLORER_I2C_PINS or HEADER_I2C_PINS

breakout_scd41.init(i2c)
breakout_scd41.start()

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

Yeah, when using a breakout on a Pi its Python, but on a Pico its Micro Python.
It’s also easy to click examples, instead of micropython, examples. You get used to it after a while, especially if your like me and use those Breakout Garden breakouts on Pi’s and Pico’s.