Your Contact to Sensirion

Umschlag

Contact

Contact our sensor experts:

Contact Form

Distributoren

Distributors

Here you find the nearest distributor in your area:

Our Distributors

Standorte

Locations

Find out where we are located:

Our Locations

toggle menu
  • Home
  • News
  • Sensirion Products
    • SEK-SensorBridge (Evaluation Kit)
    • SEN5x Environmental Sensor Node
    • SCD4x CO2 Sensors
    • SFA30 Formaldehyde Sensor Module
    • SGP41 VOC+NOx Sensor
    • SGP40 VOC Sensor
    • SHT4x Humidity and Temperature Sensors
  • Partner Spotlight
    • Partner Spotlight SparkFun
    • Partner Spotlight MikroElektronika
    • Partner Spotlight Seeed
  • Archive
    • Platforms
      • Environmental Sensor Shield
      • Smart Gadget Development Kit
      • Wearable Development Kit
      • Raspberry Pi
      • Qualcomm Snapdragon
      • Arduino
      • Cypress PSoC Series
      • Generic Linux Support
      • Thingstream MQTT IoT Sensor Starter Kit
    • Applications
      • Sensors for Ventilation
      • CO2 Monitor Reference Design
      • SHTC3 BLE Beacon Development Kit
      • Directional Wind Meter Using SDP3x
      • Smart Speaker
      • Archive
    • Labs
      • #21 - Using an RJ45 Breakout Board Connect with Evaluation Kit Cables
      • #20 - Integrate Flex-PCB Sensors into Prototyping Setups
      • #19 - Smart Factory Particle Monitor Network
      • #18 - Inhalation Application Benefits
      • #17 - Sleep Analysis and Pulse Monitor
      • #16 - Thermal Comfort Sensor
      • #15 - Anti-Fogging for Bathroom Mirrors
      • #14 - Improved Puff Sensing of Inhalation Devices
      • #13 - Spirometer
      • #12 - Breath Detection
      • #11 - Stress, Mood and Emotion Sensing
      • #10 - CO2 Sensing in Car
      • #9 - Milk Fat Concentration Sensor
      • #8 - Presence Detection with IR Sensor
      • #7 - RH Sensor Trigger for BLE Beacon
      • #6 - Smart Inhaler
      • #5 - Windshield Ice Detector
      • >> See All Labs Ideas
    • Tutorials
      • Wearable Development Kit: Build Your Own Device
      • Wearable Development Kit: Logging Data
      • Raspberry Pi: SFM Software Package
      • Raspberry Pi: Alexa with Indoor Air Quality
      • Raspberry Pi: Using Flow Sensors
      • Raspberry Pi: Weather Station
      • Arduino: Create Your Own CO2 Monitor
      • Arduino: Stand-Alone Liquid Flow Meter
      • Arduino: Interface for Liquid Flow Sensors
      • Arduino: Weather Station
      • Arduino: Closed Loop Volume Controller Using Liquid Flow Sensors
      • Arduino: Interface for Multiple SF06 Liquid Flow Sensors
      • Arduino: Interface for SF06 Liquid Flow Sensors with Level Shifter
      • Arduino: CAN Bus Flow Meter
  • Global Website

연락처

search
cart
DOWNLOAD CENTER BUY NOW INVESTORS
Sensirion AG Switzerland
  • Home
  • News
  • Sensirion Products
    • SEK-SensorBridge (Evaluation Kit)
    • SEN5x Environmental Sensor Node
    • SCD4x CO2 Sensors
    • SFA30 Formaldehyde Sensor Module
    • SGP41 VOC+NOx Sensor
    • SGP40 VOC Sensor
    • SHT4x Humidity and Temperature Sensors
    • Sensirion Products

      Start testing our sensors

      Here you can find all information for evaluating and testing Sensirion's latest sensor solutions. From drivers and software to tutorials and quick start guides - we try to offer all tools necessary so that you can kick-start your application!

  • Partner Spotlight
    • Partner Spotlight SparkFun
    • Partner Spotlight MikroElektronika
    • Partner Spotlight Seeed
  • Archive
    • Platforms
      • Environmental Sensor Shield
      • Smart Gadget Development Kit
      • Wearable Development Kit
      • Raspberry Pi
      • Qualcomm Snapdragon
      • Arduino
      • Cypress PSoC Series
      • Generic Linux Support
      • Thingstream MQTT IoT Sensor Starter Kit
    • Applications
      • Sensors for Ventilation
      • CO2 Monitor Reference Design
      • SHTC3 BLE Beacon Development Kit
      • Directional Wind Meter Using SDP3x
      • Smart Speaker
      • Archive
        • On/Off Body Detection
        • Perspiration
        • Antifogging in VR Goggles
    • Labs
      • #21 - Using an RJ45 Breakout Board Connect with Evaluation Kit Cables
      • #20 - Integrate Flex-PCB Sensors into Prototyping Setups
      • #19 - Smart Factory Particle Monitor Network
      • #18 - Inhalation Application Benefits
      • #17 - Sleep Analysis and Pulse Monitor
      • #16 - Thermal Comfort Sensor
      • #15 - Anti-Fogging for Bathroom Mirrors
      • #14 - Improved Puff Sensing of Inhalation Devices
      • #13 - Spirometer
      • #12 - Breath Detection
      • #11 - Stress, Mood and Emotion Sensing
      • #10 - CO2 Sensing in Car
      • #9 - Milk Fat Concentration Sensor
      • #8 - Presence Detection with IR Sensor
      • #7 - RH Sensor Trigger for BLE Beacon
      • #6 - Smart Inhaler
      • #5 - Windshield Ice Detector
      • >> See All Labs Ideas
    • Tutorials
      • Wearable Development Kit: Build Your Own Device
      • Wearable Development Kit: Logging Data
      • Raspberry Pi: SFM Software Package
      • Raspberry Pi: Alexa with Indoor Air Quality
      • Raspberry Pi: Using Flow Sensors
      • Raspberry Pi: Weather Station
      • Arduino: Create Your Own CO2 Monitor
      • Arduino: Stand-Alone Liquid Flow Meter
      • Arduino: Interface for Liquid Flow Sensors
      • Arduino: Weather Station
      • Arduino: Closed Loop Volume Controller Using Liquid Flow Sensors
      • Arduino: Interface for Multiple SF06 Liquid Flow Sensors
      • Arduino: Interface for SF06 Liquid Flow Sensors with Level Shifter
      • Arduino: CAN Bus Flow Meter
Sensirion AG Switzerland
  • Sensirion Developers
  • Archive
  • Tutorials
  • Raspberry Pi: Using Flow Sensors

Tutorial: Using Differential Pressure and Flow Sensors with Raspberry Pi

In this tutorial we show how to connect Sensirion's differential pressure sensors SDP5xx and flow sensors SFM3xxx to Raspberry Pi.

Challenges

Both, the SFM3xxx and SDP6xx have an I2C interface. We use the Sensirion sfxx Linux kernel driver to access them via Raspberry Pi. This driver has to be compiled as a module for Raspberry, which usually includes recompiling the complete kernel. Here we use a method that only requires compiling the specific modules and can be run entirely on Raspberry Pi.

In the end, we will be able to read out sensor values from a Python application and display them on the console.

1. Prerequisites


You will need

  • A Raspberry Pi. This tutorial was tested with the Pi 3, Pi 2 Model B and the Model B+.
  • An SD card with a current version of the Raspbian operating system. We used the version from 2016-03-18. Make sure you have at least 1Gb of free space. This means you might have to expand the file system using raspi-config.
  • A Sensirion flow or differential pressure sensor. In this tutorial we connect one SFM3000 to the I2C port 0 and one SDP631 to the I2C port 1. However, any compatible sensor with an I2C interface should work.
  • Wires and pull up resistors to connect the sensors to Raspberry Pi
  • An internet connection on Raspberry Pi. We will download the source code and install packages directly on the Pi.

2. Hardware Assembly


Connect the sensors to Raspberry Pi, this is easiest done using some jumper cables. Take care to chose the correct supply voltage for your sensor.

SFM3xxx Wiring

Signal Pin on SFM3xxx (From left to right) Pin on Raspberry Pi
SDA 1 3
GND 2 6
VDD 3 2
SCL 4 5

SDP6xx Wiring

Signal Pin on SDP6xx (from left to right) Pin on Raspberry Pi
SDA 1 3
GND 2 6
VDD 3 1
SCL 4 5
  • Download table as PDF

3. Software Setup


All of the following commands run on console on Raspberry Pi. In general, there are two methods to run a shell:

  • Connect a monitor and a keyboard to Raspberry Pi before turning it on.
  • Set up the networking on Raspberry Pi and connect over the network using ssh.

Configuring I2C

By default the I2C buses on Raspberry Pi are disabled. If you already enabled the bus you need (e.g. using raspi-config) you can skip this step.

echo dtparam=i2c_arm=on | sudo tee -a /boot/config.txt
sudo reboot

The first two commands will configure the Raspberry Pi to use the I2C busses 0 and 1 on the GPIOs 27 and 28, respectively 2 and 3.

The last command will reboot the system.

Install Linux Kernel Headers

Because Raspian doesn't follow the Debian standard for packaging kernels and the corresponding headers, we use a different method to install them. This is necessary to compile modules which should be loaded into the kernel.

sudo wget https://raw.githubusercontent.com/notro/rpi-source/master/rpi-source -O /usr/bin/rpi-source && sudo chmod +x /usr/bin/rpi-source && /usr/bin/rpi-source -q --tag-update
sudo apt-get install libncurses5-dev
rpi-source

The first command installs the rpi-source tool from Github.

The second command installs a dependency of the kernel build process.

The last command will download the source code for the kernel version you are running. This step will take a while, depending on your connection speed.

Download and Compile the Driver

Clone the driver from GitHub and compile it.

mkdir drivers
cd drivers/
git clone https://github.com/Sensirion/sfxx.git
git clone https://github.com/Sensirion/crc8.git

echo obj-y := crc8/ sfxx/ > Makefile
make -C ~/linux M=$PWD

The sfxx driver depends on the crc8 module, which is part of the mainline Linux kernel. However, it is currently not included in the Raspbian images. That's why we have to download it as a separate module and compile it together with the sfxx module.

More information about using symbols from another external module can be found on https://www.kernel.org/doc/Documentation/kbuild/modules.txt, section 6.3.

Load and Instantiate Driver

Load the modules and instantiate the driver.

sudo insmod crc8/crc8.ko
sudo insmod sfxx/sfxx.ko

echo sfxx 0x40 | sudo tee /sys/bus/i2c/devices/i2c-1/new_device

The first two commands load the driver modules into the kernel.

The last command probes for the sensors on the I2C bus 1.

Read out Values

Read out values using the libsensors-python by Sensirion. For more advanced usage of the library, such as streaming the data over the network using MQTT, consult the .readme file and the different example scripts.

cd ~
git clone https://github.com/Sensirion/libsensors-python.git
libsensors-python/sync_example.py

The last command should give you a live output of the measured values to the console.

timestamp[s]    SFxxSensor[sl/min]      SFxxSensor[Pa]
0.001 s 0.000 sl/min    -0.017 Pa
0.101 s -0.028 sl/min   0.000 Pa
0.201 s -0.028 sl/min   0.000 Pa
0.301 s 0.000 sl/min    0.000 Pa
0.401 s 0.057 sl/min    0.000 Pa
0.501 s -0.057 sl/min   0.000 Pa
0.601 s -0.028 sl/min   0.000 Pa
0.701 s 0.028 sl/min    0.000 Pa

4. Notes

Second I2C bus

If you need to connect more than one sensor, you will need to connect them to different I2C buses, because all sensors have the same I2C address. There are two ways of doing that:

  • Use the bus 0 on pins 27 and 28. This is not recommended but works on versions of the Raspberry Pi prior to 3. You will need to set dtparam=i2c0=on in your boot config and install your own pull-up resistors.
  • Use any two GPIOs to emulate an I2C bus. See the i2c-gpio-param module to configure such buses dynamically. Again, you will need to install pull-up resistors to VCC.

Follow Us

Sensirion Products

  • CO2 Sensors
  • Formaldehyde Sensors
  • VOC Sensors
  • Humidity and Temperature Sensors

Partner Spotlight

  • Sparkfun
  • MikroElektronika

Archive

  • Labs
  • Applications
  • Tutorials
  • Platforms

Further Information

  • Developer News
  • Download Center
  • FAQs
  • Contact
  • Locations

Your Contact to Sensirion

Umschlag

Contact

Contact our sensor experts:

Contact Form

Distributoren

Distributors

Here you find the nearest distributor in your area:

Our Distributors

Standorte

Locations

Find out where we are located:

Our Locations

Please Find Here Various Support Topics

Buy Our Products at Your Local Distributor

About Sensirion

Environmental Sensors

Flow Sensors

Media/Newsroom

Investors

Useful Links

Sensirion Automotive Solutions

Career

Support Center

Partner Access

General

Terms and Conditions

Terms and Conditions for US Customers

Supplier Social Responsibility

Quality, Environment and Ethics

Sensirion AG

Laubisruetistrasse 50

8712 Staefa ZH, Switzerland

Tel. +41 44 306 40 00

infosensirioncom

2022 © Sensirion AG Switzerland
  • Home
  • Sitemap
  • Privacy Policy and Cookies
  • Imprint
  • Login
  • Disclaimer