Arduino library for Pololu LPS pressure sensor boards
Release date: 2016-08-17
This is a library for an Arduino-compatible controller that interfaces with ST LPS25H and LPS331AP pressure sensors on Pololu boards. The library makes it simple to read the raw pressure data from these boards:
- Pololu LPS25H pressure/altitude sensor carrier
- Pololu LPS331AP pressure/altitude sensor carrier
- AltIMU-10 v3 (L3GD20H, LSM303D, and LSM331AP carrier)
- AltIMU-10 (L3GD20, LSM303DLHC, and LSM331AP carrier) (discontinued)
The library also provides functions to help calculate altitude based on the measured pressure.
A LPS carrier can be purchased from Pololu's website. Before continuing, careful reading of the product page as well as the chip datasheet is recommended.
Make the following connections with wires between the Arduino and the LPS board:
5V Arduino boards
(including Arduino Uno, Leonardo, Mega; Pololu A-Star 32U4)
Arduino LPS board ------- --------- 5V - VIN GND - GND SDA - SDA SCL - SCL
3.3V Arduino boards
(including Arduino Due)
Arduino LPS board ------- --------- 3V3 - VIN GND - GND SDA - SDA SCL - SCL
If you are using version 1.6.2 or later of the Arduino software (IDE), you can use the Library Manager to install this library:
- In the Arduino IDE, open the "Sketch" menu, select "Include Library", then "Manage Libraries...".
- Search for "LPS".
- Click the LPS entry in the list.
- Click "Install".
If this does not work, you can manually install the library:
- Download the latest release archive from GitHub and decompress it.
- Rename the folder "lps-arduino-xxxx" to "LPS".
- Drag the "LPS" folder into the "libraries" directory inside your Arduino sketchbook directory. You can view your sketchbook location by opening the "File" menu and selecting "Preferences" in the Arduino IDE. If there is not already a "libraries" folder in that location, you should make the folder yourself.
- After installing the library, restart the Arduino IDE.
Several example sketches are available that show how to use the library. You can access them from the Arduino IDE by opening the "File" menu, selecting "Examples", and then selecting "LPS". If you cannot find these examples, the library was probably installed incorrectly and you should retry the installation instructions above.
This program continuously takes pressure and temperature readings from the sensor and calculates an altitude from the pressure. It shows the data in metric units: pressure in millibars (mbar) (which are equivalent to hectopascals (hPa)), altitude in meters, and temperature in degrees Celsius. The program's output is sent over the serial interface, and you can display it with the Arduino Serial Monitor.
p: 931.93 mbar a: 700.02 m t: 29.92 deg C p: 931.85 mbar a: 700.73 m t: 29.92 deg C p: 931.75 mbar a: 701.68 m t: 29.89 deg C
This program is the same as SerialMetric, except that it shows the data in United States customary units: pressure in inches of mercury (inHg), altitude in feet, and temperature in degrees Fahrenheit.
p: 27.52 inHg a: 2296.55 ft t: 83.19 deg F p: 27.52 inHg a: 2295.50 ft t: 83.18 deg F p: 27.52 inHg a: 2296.42 ft t: 83.17 deg F
bool init(deviceType device, byte sa0)
Initializes the library with the device being used (
LPS::device_auto) and the state of the SA0 pin (
HIGHalso work), which determines the least significant bit of the sensor's address. Both of these arguments are optional; if they are not specified, the library will try to automatically detect the device and address. The return value is a boolean indicating whether a device was successfully detected.
Returns the device type detected by
Returns the address detected by
Turns on the pressure sensor in a default configuration that gives continous output at 12.5 Hz.
void writeReg(int reg, byte value)
Writes a pressure sensor register with the given value. Register addresses are defined by the regAddr enumeration type in LPS.h. Example use:
byte readReg(int reg)
Reads a pressure sensor register and returns the value read.
Returns a pressure reading from the sensor in units of millibars (mbar)/hectopascals (hPa).
Returns a pressure reading from the sensor in units of inches of mercury (inHg).
Returns a raw 24-bit pressure reading from the sensor.
Returns a temperature reading from the sensor in units of degrees Celsius.
Returns a temperature reading from the sensor in units of degrees Fahrenheit.
Returns a raw 16-bit temperature reading from the sensor.
float pressureToAltitudeMeters(float pressure_mbar, float altimeter_setting_mbar)
Converts a pressure in mbar to an altitude in meters, using the 1976 U.S. Standard Atmosphere model (note that this formula only applies up to an altitude of 11 km, or about 36000 ft). If the optional
altimeter_setting_mbarargument is given, specifying an "altimeter setting" or "QNH" (barometric pressure adjusted to sea level, often used in aviation and obtained from a local weather monitoring station), this function returns an indicated altitude compensated for the actual regional pressure. Otherwise, it returns a pressure altitude above the standard pressure level of 1013.25 mbar (29.9213 inHg).
float pressureToAltitudeFeet(float pressure_inHg, float altimeter_setting_inHg)
Converts a pressure in inHg to an altitude in feet. See the preceding description of
- 3.0.0 (2016-08-17): Updated library to work with the Arduino Library Manager.
- 2.0.0 (2014-06-03): Major rewrite. List of significant changes:
- Renamed library to LPS.
- Added support for LPS25H and automatic detection of device type.
- Library constants converted to enums.
- 1.0.1 (2014-01-08): Changed raw output byte combination logic to work properly on 32-bit microcontrollers and be more portable.
- 1.0.0 (2013-03-22): Original release of LPS331 library.