Skip to content
This repository has been archived by the owner on Dec 18, 2020. It is now read-only.
/ lps331-arduino Public archive

Arduino library for Pololu LPS331AP pressure/altitude sensor carrier (deprecated; replaced by https://github.com/pololu/lps-arduino)

License

Notifications You must be signed in to change notification settings

pololu/lps331-arduino

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 

Repository files navigation

Arduino library for Pololu LPS331AP boards

Version: 1.0.1
Release Date: 2014-01-08
www.pololu.com

This library is deprecated; you should use the newer Pololu LPS library instead, which also supports the LPS25H.

Summary

This is a library for the Arduino that interfaces with LPS331AP pressure sensors on Pololu boards. It makes it simple to read the raw pressure data from these boards:

The library also provides functions to help calculate altitude based on the measured pressure.

Getting Started

Software

Download the archive from GitHub, decompress it, and move the “LPS331” folder into the “libraries” subdirectory inside your Arduino sketchbook directory. You can view your sketchbook location by selecting File→Preferences in the Arduino environment; if there is not already a “libraries” folder in that location, you should create it yourself. After installing the library, restart the Arduino environment so it can find the LPS331 library and its example.

Hardware

Make the following connections with wires between the Arduino and the LPS331AP:

Arduino Uno/Duemilanove      LPS331AP carrier
                     5V  ->  VIN
                    GND  ->  GND
           Analog pin 4  ->  SDA
           Analog pin 5  ->  SCL
Arduino Leonardo             LPS331AP carrier
                     5V  ->  VIN
                    GND  ->  GND
          Digital pin 2  ->  SDA
          Digital pin 3  ->  SCL
Arduino Mega                 LPS331AP carrier
                     5V  ->  VIN
                    GND  ->  GND
         Digital pin 20  ->  SDA
         Digital pin 21  ->  SCL
Arduino Due                  LPS331AP carrier
                   3.3V  ->  VIN (or VDD)
                    GND  ->  GND
         Digital pin 20  ->  SDA
         Digital pin 21  ->  SCL

Example Programs

Open an example code sketch by selecting File→Examples→LPS331→example_name

SerialMetric

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.

Example output:

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

SerialUS

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.

Example output:

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

Library Reference

bool init(byte sa0)
Initializes the library with the state of the SA0 (slave address least significant bit) pin. Constants for this argument are defined in LPS331.h. The argument is optional; if it is not specified, the library will try to automatically detect the slave address. The return value is a boolean indicating whether auto-detection or communication on the specified address was successful.
void enableDefault(void)
Turns on the pressure sensor in a default configuration that gives continous output at 12.5 Hz.
void writeReg(byte reg, byte value)
Writes a pressure sensor register with the given value. Register address constants are defined in LPS331.h.
byte readReg(byte reg)
Reads a pressure sensor register and returns the value read.
float readPressureMillibars(void)
Returns a pressure reading from the sensor in units of millibars (mbar)/hectopascals (hPa).
float readPressureInchesHg(void)
Returns a pressure reading from the sensor in units of inches of mercury (inHg).
long readPressureRaw(void)
Returns a raw 24-bit pressure reading from the sensor.
float readTemperatureC(void)
Returns a temperature reading from the sensor in units of degrees Celsius.
float readTemperatureF(void)
Returns a temperature reading from the sensor in units of degrees Fahrenheit.
int readTemperatureRaw(void)
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_mbar argument 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 pressureToAltitudeMeters() for details.

Version History

  • 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.

About

Arduino library for Pololu LPS331AP pressure/altitude sensor carrier (deprecated; replaced by https://github.com/pololu/lps-arduino)

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages