This is the LPS25HB release by STMicroelectronics. The LPS25HB is an absolute pressure sensor with a feature that functions as a digital output barometer that rages from 260 mbar to 1260 mbar 26 kPa to 126 kPa with absolute accuracy down to ±0.2 mbar and typical RMS (Root Mean Square) noise of 0.01 mbar in high resolution these pressures can easily be transformed to altitudes. As you can see in the circuit diagram it has a 3.3v LDO Linear Regulator and pullup resistors this will allows you to work over an input voltage range of 2.5v to 5.5v and communicates on i2C / TWI and SPI bus. ST’s LPS25HB a MEMS (Microelectromechanical System) an absolute pressure, barometer sensor a small leadless, land grid array package that makes it difficult to wire directly to your microcontroller. However, you can use an LGA / SMD adapter or use our PCB milling file below.
The LPS25HB & LPS331AP pressure and barometer use the same i2C address bus, but different registers field, these IC has embedded temperature compensation with a set of various configuration options, including selectable resolutions, output data rates, FIFO operating modes, and programmable external interrupt signal. This pressure has an absolute pressure accuracy over temperatures as low as ±0.2 mbar with RMS (Root Mean Square) noise of 0.01 mbar at the highest resolution mode with enabled integrated filtering. This pressure and temperature sensor are available through a digital interface. before proceeding to use this sensor please read carefully the LPS25HB / LPS331AP Datasheet.
Requirements
- Arduino IDE | PlatformIO
- Test Boards :
- Note: The Diagram below is using Raspberry Pi PICO (please refer to your MCU’s respective pin-outs & bus configuration)
- Resistors (See below diagram for required value)
- Regulator (3.3V LDO)
- Capacitor(See below diagram for required value)
Wiring Diagram / Schematics
LPS25HB Sketch Source Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
#include <Wire.h> #include <LPS.h> LPS ps; //Initialize i2C void setup() { Serial.begin(9600); Serial.print("14CORE | TEST LPS25HB / LPS331AP"); delay(2000); Wire.begin(); Serial.print("Initializing .................. "); if (!ps.init()) { Serial.println("Error: Failed to read pressure sensor!"); while (1); } ps.enableDefault(); } void loop() { float pressure = ps.readPressureMillibars(); float altitude = ps.pressureToAltitudeMeters(pressure); float temperature = ps.readTemperatureC(); Serial.print("p: "); Serial.print(pressure); Serial.print(" mbar\ta: "); Serial.print(altitude); Serial.print(" m\tt: "); Serial.print(temperature); Serial.println(" deg C"); delay(100); } |
LPS25HB Sketch Code w/o Library
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
#include<Wire.h> // LPS25HB I2C address is 0x5C(92) #define Addr 0x5C void setup() { // Initialise I2C communication as MASTER Wire.begin(); // Initialise Serial communication, set baud rate = 9600 Serial.begin(9600); // Start I2C Transmission Wire.beginTransmission(Addr); // Select control register 1 Wire.write(0x20); // Set active mode, continuous Update Wire.write(0x90); // Stop I2C Transmission Wire.endTransmission(); delay(300); } void loop() { unsigned int data[3]; // Start I2C Transmission Wire.beginTransmission(Addr); // Select pressure data register Wire.write(0x28 | 0x80); // Stop I2C Transmission Wire.endTransmission(); // Request 3 bytes of data Wire.requestFrom(Addr, 3); // Read 3 bytes of data // pressure lsb first if(Wire.available() == 3) { data[0] = Wire.read(); data[1] = Wire.read(); data[2] = Wire.read(); } delay(300); // Convert pressure data float pressure = ((data[2] * 65536) + (data[1] * 256) + data[0]) / 4096.0; // Output data to serial monitor Serial.print("Pressure is : "); Serial.print(pressure); Serial.println(" hPa"); delay(1000); } |
LPS25HB Java Source Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
import com.pi4j.io.i2c.I2CBus; import com.pi4j.io.i2c.I2CDevice; import com.pi4j.io.i2c.I2CFactory; import java.io.IOException; public class LPS25HB { public static void main(String args[]) throws Exception { // Create I2C bus I2CBus bus = I2CFactory.getInstance(I2CBus.BUS_1); // Get I2C device, LPS25HB I2C address is 0x5C(72) I2CDevice device = bus.getDevice(0x5C); // Active mode, Continuous Update device.write(0x20, (byte)0x90); Thread.sleep(500); // Read 3 bytes of data from address 0x28(40), lsb first byte[] data = new byte[3]; device.read(0x28 | 0x80, data, 0, 3); // Convert data to hPa double pressure = (((data[2] & 0xff) * 65536) + ((data[1] & 0xff) * 256) + (data[0] & 0xff)) / 4096.0; // Output to the screen System.out.printf("Pressure is : %.2f hPa %n", pressure); } } |
LPS25HB MicroPython Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import smbus import time # Get I2C bus bus = smbus.SMBus(1) # LPS25HB address, 0x5C(92) # Select Control register, 0x20(32) # 0x90(144) Active mode, Continous update bus.write_byte_data(0x5C, 0x20, 0x90) time.sleep(0.1) # LPS25HB address, 0x5C(92) # Read data back from 0x28(40), with Command register, 0x80(128) # 3 bytes, Pressure LSB first data = bus.read_i2c_block_data(0x5C, 0x28 | 0x80, 3) # Convert the data to hPa pressure = (data[2] * 65536 + data[1] * 256 + data[0]) / 4096.0 # Output data to screen print "Barometric Pressure is : %.2f hPa" %pressure |
LPS25HB C-Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
#include <stdio.h> #include <stdlib.h> #include <linux/i2c-dev.h> #include <sys/ioctl.h> #include <fcntl.h> void main() { // Create I2C bus int file; char *bus = "/dev/i2c-1"; if((file = open(bus, O_RDWR)) < 0) { printf("Failed to open the bus. \n"); exit(1); } // Get I2C device, LPS25HB I2C address is 0x5C(72) ioctl(file, I2C_SLAVE, 0x5C); // Select control register(0x20) // Active mode, Continuous Update(0x90) char config[2] = {0}; config[0] = 0x20; config[1] = 0x90; write(file, config, 2); sleep(1); // Read 3 bytes of data from register(0x28) // Pressure lsb first char reg[1] = {0x28 | 0x80}; write(file, reg, 1); char data[3] = {0}; if(read(file, data, 3) != 3) { printf("Error : Input/Output error \n"); } else { // Convert the data float pressure = ((data[2] * 65536) + ((data[1] * 256) + data[0])) / 4096.0; // Output data to screen printf("Pressure is : %.2f hPa \n", pressure); } } |
LPS25HB CircuitPython Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import time import board import adafruit_lps2x i2c = board.I2C() # uses board.SCL and board.SDA # i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller # uncomment and comment out the line after to use with the LPS22 # lps = adafruit_lps2x.LPS22(i2c) lps = adafruit_lps2x.LPS25(i2c) while True: print("Pressure: %.2f hPa" % lps.pressure) print("Temperature: %.2f C" % lps.temperature) time.sleep(1) |
PCB Board Milling / Gerber File
Downloads
- Download LPS25HD Datasheet | PDF
- Download LPS331AP Datasheet | PDF
- Download i2C / Two Wire Interface Guide | PDF
- Download LPS25HD / LPS331AP Arduino Sketch Code Library | ZIP
- CircuitPython Library can be found here
- MicroPython Compiler