The PSOC™ Edge E84 AI Kit comes packed with sensors that make it really fun to experiment with environmental data. One of them is the XENSIV™ DPS368 barometric pressure sensor, a tiny MEMS device that can measure atmospheric pressure with impressive accuracy.
Pressure sensors are used in everything from weather stations and drones to altitude estimation and navigation systems. In this quick ProTip, we’ll read live pressure and temperature data from the onboard DPS368 using MicroPython.
The nice part? Since the sensor is already integrated on the board, no wiring is needed — we can start experimenting right away.
Hardware OverviewThe pressure sensor communicates with the PSOC™ Edge E84 over I²C and is already connected internally on the PCB.
The relevant pins are:
The only thing we need is the Dps3xx.py file, which handles the communication and compensation calculations for the sensor.
Steps:
1. Connect the PSOC™ Edge E84 to your computer and make sure you have MicroPython enabled on your board. If not, this article will help you. :)
2. Open Thonny IDE
3. Import Libraries
Download the Dps3xx.py file (GitHub link or see attachment below). In Thonny, go to File → Save as... and choose MicroPython device, then save it as Dps3xx.py.
Next, import the necessary modules: I2C and Pin for hardware communication, time for delays, and Dps3xx for the sensor driver.
from machine import I2C, Pin
import time
import Dps3xx4. Initialize I²C and Sensor
Initialize the I²C bus on pins P8_0 (SCL) and P8_1 (SDA) at 400kHz, then create the sensor object.
i2c = I2C(0, scl=Pin("P8_0"), sda=Pin("P8_1"), freq=400000)
sensor = Dps3xx.Dps3xx(i2c)5. Read Sensor Data
Set up an infinite loop (while True:) to continuously read and display real-time data from the sensor. The sensor provides two key measurements:
pressure = sensor.measurePressureOnce()
temperature = sensor.measureTemperatureOnce()sensor.measurePressureOnce(): Reads the current atmospheric pressure in Pascals (Pa). Standard atmospheric pressure at sea level is approximately 101325 Pa (1013.25 hPa). This value changes with altitude and weather conditions — higher altitudes have lower pressure, and approaching storms often bring pressure drops.sensor.measureTemperatureOnce(): Reads the ambient temperature in degrees Celsius (°C) from the built-in temperature sensor. This measurement helps compensate for the pressure readings (since pressure sensors are temperature-sensitive) and can also be used for general environmental monitoring.
The sensor can estimate altitude based on atmospheric pressure:
SEA_LEVEL_PRESSURE = 101325 # Pa (standard sea level pressure)
altitude = 44330 * (1.0 - (pressure / SEA_LEVEL_PRESSURE) ** 0.1903)
print('Altitude: ', round(altitude, 2), 'm')This uses the barometric formula from the International Standard Atmosphere (ISA) model: as you go higher, air pressure drops in a predictable way. The constants (44330 and 0.1903) come from atmospheric physics equations.
Tipps: This gives you altitude relative to sea level under standard conditions. Weather changes affect pressure, so it's better for tracking height changes (climbing, hiking) than absolute elevation. For better accuracy, update SEA_LEVEL_PRESSURE using local weather station data.
Once everything is set up, the board will start printing pressure, temperature and altitude values in the terminal.
Example Code
from machine import I2C, Pin
import time
import Dps3xx
# Sea level standard pressure
SEA_LEVEL_PRESSURE = 101325 # Pa
i2c = I2C(0, scl=Pin("P8_0"), sda=Pin("P8_1"), freq=400000)
sensor = Dps3xx.Dps3xx(i2c)
print('Sensor started')
while True:
pressure = sensor.measurePressureOnce()
temperature = sensor.measureTemperatureOnce()
altitude = 44330 * (1.0 - (pressure / SEA_LEVEL_PRESSURE) ** 0.1903)
print('Pressure: ', pressure, 'Pa')
print('Temperature: ', temperature, '°C')
print('Altitude: ', round(altitude, 2), 'm')
print('-------------------------------')
time.sleep(1)What You Should See
Once the script runs, the terminal will start showing live sensor readings. Something like:
There you have it! You've successfully read atmospheric pressure and temperature data from the XENSIV™ DPS368 barometric pressure sensor on the PSOC™ Edge E84 AI Kit using MicroPython. With just a few lines of code, you can read real-time atmospheric pressure with high accuracy, measure ambient temperature from the built-in sensor, and even calculate altitude based on pressure readings.
This setup provides a flexible foundation that can be expanded in many directions — from portable weather stations and hiking altimeters to smart home environmental monitoring and IoT sensor networks. The atmospheric world is yours to explore, so feel free to create your own climate-aware projects! Happy making! :)











Comments