Using the LPS28 breakout with Arduino involves wiring up the breakout to your Arduino-compatible microcontroller, installing the Adafruit_LPS28 library, and running the provided example code.
Wiring
Wire as shown for a 5V board like an Uno. If you are using a 3V board, like an Adafruit Feather, wire the board's 3V pin to the sensor VIN.
Here is an Adafruit Metro wired up to the sensor using the STEMMA QT connector:
-
Board 5V to sensor VIN (red wire)
-
Board GND to sensor GND (black wire)
-
Board SCL to sensor SCL (yellow wire)
- Board SDA to sensor SDA (blue wire)
Here is an Adafruit Metro wired up using a solderless breadboard:
-
Board 5V to sensor VIN (red wire)
-
Board GND to sensor GND (black wire)
-
Board SCL to sensor SCL (yellow wire)
- Board SDA to sensor SDA (blue wire)
Library Installation
You can install the Adafruit_LPS28 library for Arduino using the Library Manager in the Arduino IDE.
Click the Manage Libraries ... menu item, search for Adafruit_LPS28, and select the Adafruit LPS28 library:
If asked about dependencies, click "Install all".
If the "Dependencies" window does not come up, then you already have the dependencies installed.
If the dependencies are already installed, you must make sure you update them through the Arduino Library Manager before loading the example!
#include <Wire.h> #include <Adafruit_LPS28.h> // Instantiate the sensor Adafruit_LPS28 lps28; void setup() { Serial.begin(115200); while (!Serial) delay(10); // Wait for Serial monitor Serial.println("LPS28 Test"); // Initialize the sensor if (!lps28.begin()) { Serial.println("Failed to find LPS28 sensor!"); while (1) delay(10); } Serial.println("LPS28 sensor found!"); // Set the highest ODR (200 Hz) and 4-sample averaging, new value every 20ms lps28.setDataRate(LPS28_ODR_200_HZ); lps28.setAveraging(LPS28_AVG_4); // Set range to 4060 hPa lps28.setFullScaleMode(true); // Enable DRDY interrupt on the interrupt pin lps28.setInterruptPin( true, // Polarity: Active high false // Pin mode: Push-pull ); // Enable DRDY interrupt output on INT pin (we could use this with an interrupt) lps28.setIntPinOutput( true, // DRDY active false, // DRDY pulse not enabled false, // INT output not enabled false, // FIFO full interrupt not enabled false, // FIFO watermark interrupt not enabled false // FIFO overrun interrupt not enabled ); } void loop() { // Check if data is ready by reading the STATUS register if (lps28.getStatus() & LPS28_STATUS_PRESS_READY) { // Pressure data available // Read and print pressure and temperature float pressure = lps28.getPressure(); float temperature = lps28.getTemperature(); Serial.print("Pressure (hPa): "); Serial.println(pressure); Serial.print("Temperature (°C): "); Serial.println(temperature); } delay(10); // Polling delay }
Upload the sketch to your board and open up the Serial Monitor (Tools -> Serial Monitor) at 115200 baud. You'll see the LPS28 recognized over I2C. Then, pressure and temperature readings will be printed to the Serial Monitor.
Page last edited February 05, 2025
Text editor powered by tinymce.