Home Code Raspberry Pi and DPS310 barometric pressure sensor example in python

Raspberry Pi and DPS310 barometric pressure sensor example in python

by shedboy71

In this example we take a look at the DPS310 barometric pressure sensor from Infineon to a Raspberry Pi 4


The pressure sensor element is based on a capacitive sensing principle which guarantees high precision during temperature changes.

The small package makes the DPS310 ideal for mobile applications and wearable devices.The internal signal processor converts the output from the pressure and temperature sensor elements to 24 bit results.

Each unit is individually calibrated, the calibration coefficients calculated during this process are stored in the calibration registers.

The coefficients are used in the application to convert the measurement results to high accuracy pressure and temperature values.

The result FIFO can store up to 32 measurement results, allowing for a reduced host processor polling rate. Sensor measurements and calibration coefficients are available through the serial I2C or SPI interface.

The measurement status is indicated by status bits or interrupts on the SDO pin.


  • Supply voltage range 1.7V to 3.6V
  • Operation range 300hPa – 1200hPa
  • Sensor’s precision 0.002hPa
  • Relative accuracy ±0.06hPa
  • Pressure temperature sensitivity of 0.5Pa/K
  • Temperature accuracy  ±0.5C°


This is the sensor that I bought

Parts Required

Various parts used in this example

Name Link
DPS310 DPS310 Precision Barometric Pressure / Altitude
Raspberry Pi P4 Raspberry Pi 4 Model B 2019 Quad Core 64 Bit WiFi Bluetooth (4GB)Official Original Raspberry Pi 4 Model B Dev Board Kit RAM 2G 4G 8G 4 Core CPU 1.5Ghz
Connecting cables Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire



I connected the DPS310 to the Raspberry Pi 4 like this

pi and dps310 layout

pi and dps310 layout


Steps for installation

This is the library from https://github.com/Infineon/RaspberryPi_DPS

Supported hardware –> Raspberry pi Zero/3/3B+/4B

  • Update apt

sudo apt update

  • Enable i2c (Interfacing options menu and then I2C enable). For detailed steps see this article.

sudo raspi-config

  • Install pip3

sudo apt install python3-pip

  • Install smbus

pip3 install smbus
sudo apt-get install -y python-smbus i2c-tools

Installing from PyPI

On supported GNU/Linux systems like the Raspberry Pi, you can install the driver from PyPI

For current user:

pip3 install DigitalPressureSensor

To install system-wide (this may be required in some cases):

sudo pip3 install DigitalPressureSensor

Code Example

I used Thonny for development and the library above, I copied one of the examples from the github repo

[codesyntax lang=”python”]

import DPS

from time import sleep

dps310 = DPS.DPS()

        while True:
            scaled_p = dps310.calcScaledPressure()
            scaled_t = dps310.calcScaledTemperature()
            p = dps310.calcCompPressure(scaled_p, scaled_t)
            t = dps310.calcCompTemperature(scaled_t)
            print(f'{p:8.1f} Pa {t:4.1f} C')

except KeyboardInterrupt:




Run this example in Thonny and you will see something like this in the Shell window

%Run dps.py
81254.0 Pa 111.5 C
99858.5 Pa 111.5 C
98622.3 Pa 17.3 C
98622.3 Pa 17.3 C
98621.5 Pa 17.3 C
98622.1 Pa 17.3 C




You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More