Code Monkey home page Code Monkey logo

raspberry-pi-i2c-sen5x's Introduction

Sensirion Raspberry Pi I2C SEN5x Driver

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

Supported sensors

  • SEN50 (only particulate matter signals available)
  • SEN54 (no NOx signal available)
  • SEN55 (full feature set)

Setup Guide

Connecting the Sensor

Your sensor has the five different connectors: VCC, GND, SDA, SCL, SEL (the sixth connector will not be used for now). Use the following pins to connect your SEN5x:

SEN5x Raspberry Pi Jumper Wire
VCC Pin 2 (5V) Red
GND Pin 6 Black
SDA Pin 3 Green
SCL Pin 5 Yellow
SEL Pin 9 (GND for I2C) Blue

Pin Name Description Comments
1 VCC Supply Voltage 5V ±10%
2 GND Ground
3 SDA I2C: Serial data input / output TTL 5V and LVTTL 3.3V compatible
4 SCL I2C: Serial clock input TTL 5V and LVTTL 3.3V compatible
5 SEL Interface select Pull to GND to select I2C
6 NC Do not connect

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-sen5x

    3. Run the make command to compile the driver

      Output:

      rm -f sen5x_i2c_example_usage
      cc -Os -Wall -fstrict-aliasing -Wstrict-aliasing=1 -Wsign-conversion -fPIC -I. -o sen5x_i2c_example_usage  sen5x_i2c.h sen5x_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 sen5x_i2c_example_usage.c
      
  • Test your connected sensor
    • Run ./sen5x_i2c_example_usage in the same directory you used to compile the driver.

      Output:

      Serial number: 213100019
      Product name: 
      Firmware: 1.0, Hardware: 4.0
      Mass concentration pm1p0: 0.0 µg/m³
      Mass concentration pm2p5: 0.0 µg/m³
      Mass concentration pm4p0: 0.0 µg/m³
      Mass concentration pm10p0: 0.0 µg/m³
      Ambient humidity: 39.6 %RH
      Ambient temperature: 28.0 °C
      Voc index: 0.0
      Nox index: 0.0
      Mass concentration pm1p0: 0.0 µg/m³
      Mass concentration pm2p5: 0.0 µg/m³
      Mass concentration pm4p0: 0.0 µg/m³
      Mass concentration pm10p0: 0.0 µg/m³
      Ambient humidity: 39.2 %RH
      Ambient temperature: 30.1 °C
      Voc index: 0.0
      Nox index: 0.0
      ...
      
    • Wait a few minutes until Voc/NOx index values are stable.

Troubleshooting

Building driver failed

If the execution of make in the compilation step 3 fails with something like

-bash: make: command not found

your RaspberryPi likely does not have the build tools installed. Proceed as follows:

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install build-essential

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 ./sen5x_i2c_example_usage), it's typically due to wrong permission settings. See the next chapter how to solve this.

Missing I2C permissions

If your user is missing access to the I2C interface you should first verfiy the user belongs to the i2c group.

$ groups
users input some other groups etc

If i2c is missing in the list add the user and restart the Raspberry Pi.

$ sudo adduser ${USER} i2c
Adding user `pi' to group `i2c' ...
Adding user pi to group i2c
Done.
$ sudo reboot

If that did not help you can make globally accessible hardware interfaces with a udev rule. Only do this if everything else failed and you are reasonably confident you are the only one having access to your Pi.

Go into the /etc/udev/rules.d folder and add a new file named local.rules.

$ cd /etc/udev/rules.d/
$ sudo touch local.rules

Then add a single line ACTION=="add", KERNEL=="i2c-[0-1]*", MODE="0666" to the file with your favorite editor.

$ sudo vi local.rules

raspberry-pi-i2c-sen5x's People

Contributors

leoniefierz avatar mbjoern avatar optimeasmak avatar psachs avatar rol-la avatar sdmueller avatar sensirion-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

raspberry-pi-i2c-sen5x's Issues

process outputs nan after a while

I changed sen5x_i2c_example_usage.c so it generates one output per minute for several hours. After 80 to 100 minutes it always starts to output only "nan".
If I start a second process in a second terminal in parallel it will sometimes start to output values again in both processes (probably due to the device_reset) or it will return errors regarding device_reset, reading_product_name, etc.
Any idea why this happens?

Error Running Testing Protocol

I encountered an error when running cd ./sen5x_i2c_example_usage . When it ran, it gave errors in executing all functions saying (for example) "Error executing sen5x_device_reset(): -1". What can be done to fix this error? Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.