I2C Wiring
Use this wiring if you want to connect via I2C interface
By default, the i2c address is 0x5D. If you add a jumper from SDO to GND the address will change to 0x5C
- Connect board VIN (red wire) to Arduino 5V if you are running a 5V board Arduino (Uno, etc.). If your board is 3V, connect to that instead.
- Connect board GND (black wire) to Arduino GND
- Connect board SCL (yellow wire) to Arduino SCL
- Connect board SDA (blue wire) to Arduino SDA
SPI Wiring
Since this is a SPI-capable sensor, we can use hardware or 'software' SPI. To make wiring identical on all microcontrollers, we'll begin with 'software' SPI. The following pins should be used:
- Connect Vin to the power supply, 3V or 5V is fine. Use the same voltage that the microcontroller logic is based off of
- Connect GND to common power/data ground
- Connect the SCK pin to Digital #13 but any pin can be used later
- Connect the SDO pin to Digital #12 but any pin can be used later
- Connect the SDI pin to Digital #11 but any pin can be used later
- Connect the CS pin Digital #10 but any pin can be used later
Later on, once we get it working, we can adjust the library to use hardware SPI if you desire, or change the pins to others.
Library Installation
You can install the Adafruit LPS2X Library for Arduino using the Library Manager in the Arduino IDE.
Click the Manage Libraries ... menu item, search for Adafruit LPS2X, and select the Adafruit LPS2X library:
Then follow the same process for the Adafruit BusIO library.
Finally follow the same process for the Adafruit Unified Sensor library:
Open up File -> Examples -> Adafruit LPS2X -> adafruit_lps25_test and upload to your Arduino wired up to the sensor.
Depending on whether you are using I2C or SPI, change the pin names and comment or uncomment the following lines.
if (!lps.begin_I2C()) { //if (!lps.begin_SPI(LPS_CS)) { //if (!lps.begin_SPI(LPS_CS, LPS_SCK, LPS_MISO, LPS_MOSI)) {
Once you upload the code, you will see the temperature and pressure being printed when you open the Serial Monitor (Tools->Serial Monitor) at 115200 baud, similar to this:
Temperature is calculated in degrees C, you can convert this to F by using the classic F = C * 9/5 + 32 equation.
Pressure is returned in the SI units of Pascals. 100 Pascals = 1 hPa = 1 millibar. Often times barometric pressure is reported in millibar or inches-mercury. For future reference 1 pascal =0.000295333727 inches of mercury, or 1 inch Hg = 3386.39 Pascal. So if you take the pascal value of say 100734 and divide by 3386.39 you'll get 29.72 inches-Hg.
Example Code - LPS25
The following example code is part of the Adafruit LPS2X library, and illustrates how you can retrieve sensor data from the LPS25 for pressure and temperature:
// Basic demo for pressure readings from Adafruit LPS2X #include <Wire.h> #include <Adafruit_LPS2X.h> #include <Adafruit_Sensor.h> // For SPI mode, we need a CS pin #define LPS_CS 10 // For software-SPI mode we need SCK/MOSI/MISO pins #define LPS_SCK 13 #define LPS_MISO 12 #define LPS_MOSI 11 Adafruit_LPS25 lps; void setup(void) { Serial.begin(115200); while (!Serial) delay(10); // will pause Zero, Leonardo, etc until serial console opens Serial.println("Adafruit LPS25 test!"); // Try to initialize! if (!lps.begin_I2C()) { //if (!lps.begin_SPI(LPS_CS)) { //if (!lps.begin_SPI(LPS_CS, LPS_SCK, LPS_MISO, LPS_MOSI)) { Serial.println("Failed to find LPS25 chip"); while (1) { delay(10); } } Serial.println("LPS25 Found!"); // lps.setDataRate(LPS25_RATE_12_5_HZ); Serial.print("Data rate set to: "); switch (lps.getDataRate()) { case LPS25_RATE_ONE_SHOT: Serial.println("One Shot"); break; case LPS25_RATE_1_HZ: Serial.println("1 Hz"); break; case LPS25_RATE_7_HZ: Serial.println("7 Hz"); break; case LPS25_RATE_12_5_HZ: Serial.println("12.5 Hz"); break; case LPS25_RATE_25_HZ: Serial.println("25 Hz"); break; } } void loop() { sensors_event_t temp; sensors_event_t pressure; lps.getEvent(&pressure, &temp);// get pressure Serial.print("Temperature: ");Serial.print(temp.temperature);Serial.println(" degrees C"); Serial.print("Pressure: ");Serial.print(pressure.pressure);Serial.println(" hPa"); Serial.println(""); delay(100); }
Example Code - LPS22
The following example code is part of the Adafruit LPS2X library, and illustrates how you can retrieve sensor data from the LPS22 for pressure and temperature:
// Basic demo for pressure readings from Adafruit LPS2X #include <Wire.h> #include <Adafruit_LPS2X.h> #include <Adafruit_Sensor.h> // For SPI mode, we need a CS pin #define LPS_CS 10 // For software-SPI mode we need SCK/MOSI/MISO pins #define LPS_SCK 13 #define LPS_MISO 12 #define LPS_MOSI 11 Adafruit_LPS22 lps; void setup(void) { Serial.begin(115200); while (!Serial) delay(10); // will pause Zero, Leonardo, etc until serial console opens Serial.println("Adafruit LPS22 test!"); // Try to initialize! if (!lps.begin_I2C()) { //if (!lps.begin_SPI(LPS_CS)) { //if (!lps.begin_SPI(LPS_CS, LPS_SCK, LPS_MISO, LPS_MOSI)) { Serial.println("Failed to find LPS22 chip"); while (1) { delay(10); } } Serial.println("LPS22 Found!"); lps.setDataRate(LPS22_RATE_10_HZ); Serial.print("Data rate set to: "); switch (lps.getDataRate()) { case LPS22_RATE_ONE_SHOT: Serial.println("One Shot / Power Down"); break; case LPS22_RATE_1_HZ: Serial.println("1 Hz"); break; case LPS22_RATE_10_HZ: Serial.println("10 Hz"); break; case LPS22_RATE_25_HZ: Serial.println("25 Hz"); break; case LPS22_RATE_50_HZ: Serial.println("50 Hz"); break; case LPS22_RATE_75_HZ: Serial.println("75 Hz"); break; } } void loop() { sensors_event_t temp; sensors_event_t pressure; lps.getEvent(&pressure, &temp);// get pressure Serial.print("Temperature: ");Serial.print(temp.temperature);Serial.println(" degrees C"); Serial.print("Pressure: ");Serial.print(pressure.pressure);Serial.println(" hPa"); Serial.println(""); delay(100); }