Skip to content

The SGP40 is Sensirion’s new digital VOC (volatile organic compounds) sensor designed for easy integration into air purifiers or demand-controlled ventilation.

License

Notifications You must be signed in to change notification settings

Sensirion/raspberry-pi-i2c-sgp40

Repository files navigation

Sensirion Raspberry Pi I2C SGP40 Driver

This document explains how to set up the SGP40 sensor to run on a Raspberry Pi using the provided code.

Click here to learn more about the SGP40 Sensor.

Setup Guide

Connecting the Sensor

Your sensor has the four different connectors: VCC, GND, SDA, SCL. Use the following pins to connect your SGP40:

SGP40 Raspberry Pi
VCC Pin 1 (3.3V)
GND Pin 6
SDA Pin 3
SCL Pin 5

Raspberry Pi

  • Install the Raspberry Pi OS on to your Raspberry Pi
  • Enable the I2C interface in the raspi-config
  • Download the driver for the Sensirion Github Page and extract the .zip on your Raspberry Pi
  • Compile the driver
    1. Open a terminal

    2. Navigate to the driver directory. E.g. cd ~/raspberry-pi-i2c-sgp40

    3. Run the make command to compile the driver

      Output:

      rm -f sgp40_i2c_example_usage
      cc -Os -Wall -fstrict-aliasing -Wstrict-aliasing=1 -Wsign-conversion -fPIC -I. -o sgp40_i2c_example_usage  sgp40_i2c.h sgp40_i2c.c sensirion_i2c_hal.h sensirion_i2c.h sensirion_i2c.c \
          sensirion_i2c_hal.c sensirion_config.h sensirion_common.h sensirion_common.c sgp40_i2c_example_usage.c
      
  • Test your connected sensor
    • Run ./sgp40_i2c_example_usage in the same directory you used to compile the driver.

      Output:

      SRAW VOC: 19720
      SRAW VOC: 20956
      SRAW VOC: 21622
      SRAW VOC: 22076
      SRAW VOC: 22314
      SRAW VOC: 22566
      ...
      

Troubleshooting

Initialization failed

  • Ensure that you connected the sensor correctly: All cables are fully plugged in and connected to the correct pin.
  • Ensure that I2C is enabled on the Raspberry Pi. For this redo the steps on "Enable the I2C interface in the raspi-config" in the guide above.
  • Ensure that your user account has read and write access to the I2C device. If it only works with user root (sudo ./sgp40_i2c_example_usage), it's typically due to wrong permission settings.

About

The SGP40 is Sensirion’s new digital VOC (volatile organic compounds) sensor designed for easy integration into air purifiers or demand-controlled ventilation.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •