Example Code for Raspberry Pi-Single-shot Measurement

This tutorial demonstrates how to perform a single-shot measurement with the SCD41 sensor on a Raspberry Pi.

Hardware Preparation

  • Raspberry Pi 4 Model B (or similar) x 1
  • Gravity: SCD41 Infrared CO2 Sensor - I2C x 1
  • M-M/F-M/F-F Jumper wires x 1

Software Preparation

Wiring Diagram

  • Connect the module to Raspberry Pi according to the connection diagram. The I2C address is 0x62.

Other Preparation Work

  1. Enable the I2C interface of Raspberry Pi. If it's already enabled, skip this step. Open Terminal, type the following command, and press Enter:

    pi@raspberrypi:~ $ sudo raspi-config

    Then use the up and down keys to select "5 Interfacing Options" -> "P5 I2C" and press Enter to confirm “YES”. Reboot the Raspberry Pi.

  2. Installing Python dependency libraries and git (networking required). If it is already installed, skip this step. In the Terminal, type the following commands, and press Enter:

    pi@raspberrypi:~ $ sudo apt-get update
    pi@raspberrypi:~ $ sudo apt-get install build-essential python-dev python-smbus git

  3. Download DFRobot_SCD4X driver library. In Terminal, type the following commands, and press Enter:

    pi@raspberrypi:~ $ cd Desktop/

    pi@raspberrypi:~/Desktop $ git clone https://github.com/dfrobot/DFRobot_SCD4X

Sample Code

In Terminal, type the following commands and press Enter to run sample codes:

pi@raspberrypi:~/Desktop $ cd DFRobot_SCD4X/python/raspberrypi/examples/

pi@raspberrypi:~/Desktop/DFRobot_SCD4X/python/raspberrypi/examples/ $ python single_shot_measure.py

Was this article helpful?

TOP