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
  • 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
  • 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
  • Partner Spotlight
  • Applications
    • Medical 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
    • #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
  • Global Website

Contact

search
cart
DOWNLOAD CENTER BUY NOW INVESTORS
Sensirion AG Switzerland
  • Home
  • News
  • 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
    • Platforms/Tutorials

      Choose Your Platform

      Here you can find an overview of various platforms which support Sensirion sensors. Furthermore, we have added some tutorials like how to build your own weather station with Arduino or how to use flow sensors on Raspberry Pi and many more. Learn more about which platform supports our sensors.

      Platform overview

  • 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
  • Partner Spotlight
  • Applications
    • Medical 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
    • Applications

      Get Inspired by Our Applications

      On this page we want to inspire you with an assembly of various patented in-house application concepts, which our engineers came up with. Here you can find tutorials as well as documentations showing the versatile usage of Sensirion’s sensors.

      Explore now

  • Labs
    • #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
    • Sensirion Labs

      Welcome to Sensirion Labs

      Sensirion stands for innovation. To inspire engineers and developers who are working with our sensor solutions, we have founded a new section called «Sensirion Labs». There you can find documentation to various ideas, which our employees came up with - for example how to use a differential pressure sensor to measure adblue / urea concentrations in liquids or how to build a pulse monitor. 

      See all labs ideas

Sensirion AG Switzerland
  • Sensirion Developers
  • 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 Pin on Raspberry Pi
SDA 1 3
SCL 4 5
VDD 3 2
GND 2 6

SDP6xx Wiring

Signal Pin on SDP6xx Pin on Raspberry Pi
SDA 1 3
SCL 4 5
VDD 3 1
GND 2 6
  • 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

GitHub

Platforms/Tutorials

  • SHT31 Smart Gadget DevKit
  • Wearable DevKit
  • Raspberry Pi
  • Arduino
  • See all supported platforms

Applications

  • SHTC3 BLE Beacon Development Kit
  • On/Off Body Detection
  • Perspiration
  • Antifogging in VR Goggles
  • Directional Wind Meter Using SDP3x

Latest Labs Ideas

  • #19 - Smart Factory Particle Monitor Network
  • #18 - Inhalation Application Benefits
  • #17 - Sleep Analysis and Pulse Monitor
  • Overview of all labs ideas

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

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