Closed tuomastielinen closed 2 years ago
Hi there
The sensor needs to be connected to the standard i2c pins (GPIO 2 => SDA; GPIO3 => SLC) of the raspberry pi and you need to install our python i2c driver: https://pypi.org/project/sensirion-i2c-driver/
Then you should be able to get this running without the sensor bridge on the basis of the following code.
Thank you for reaching out to us. We'll consider to add such examples to the repository in the future.
from sensirion_i2c_driver import LinuxI2cTransceiver, I2cConnection
with LinuxI2cTransceiver('/dev/i2c-1') as i2c_transceiver:
i2c_connection = I2cConnection(i2c_transceiver)
scd41 = Scd4xI2cDevice(i2c_connection)
# start periodic measurement in high power mode
scd41.start_periodic_measurement()
# Measure every 5 seconds
while True:
time.sleep(5)
co2, temperature, humidity = scd41.read_measurement()
# use default formatting for printing output:
print("{}, {}, {}".format(co2, temperature, humidity))
# custom printing of attributes:
print("{:d} ppm CO2, {:0.2f} °C ({} ticks), {:0.1f} %RH ({} ticks)".format(
co2.co2,
temperature.degrees_celsius, temperature.ticks,
humidity.percent_rh, humidity.ticks))
scd41.stop_periodic_measurement()
Thank you.
MBjoern: It is nice and easy to install the driver via pip! But this driver does not contain "Scd4xI2cDevice" and so it fails to run? Any newer version of the driver anywhere? I also need to run SCD30 on Raspi. I have I2C code for SCD30 and SCD41 which runs on every dongle I tried, but it does not run on Raspi. Is there a trick to make Raspi's hardware I2C run with Sensirion sensors?
Can an example be added for how to use this with RaspberryPi and Python? I would like to use this without SensorBridge.
More specifically, I would like to make a Prometheus exporter in Python to send measurements from this sensor using RaspberryPi.