Adafruit LPS2X Barometric Pressure Sensor Library
Adafruit_LPS2X.h
Go to the documentation of this file.
1 
18 #ifndef _ADAFRUIT_LPS2X_H
19 #define _ADAFRUIT_LPS2X_H
20 
21 #include "Arduino.h"
22 #include <Adafruit_BusIO_Register.h>
23 #include <Adafruit_I2CDevice.h>
24 #include <Adafruit_Sensor.h>
25 #include <Wire.h>
26 
27 #define LPS2X_I2CADDR_DEFAULT 0x5D
28 #define LPS2X_WHOAMI 0x0F
29 
30 #define LPS22HB_CHIP_ID 0xB1
31 #define LPS22_THS_P_L_REG 0x0C
32 #define LPS22_CTRL_REG1 0x10
33 #define LPS22_CTRL_REG2 0x11
34 #define LPS22_CTRL_REG3 \
35  0x12
36 
37 #define LPS25HB_CHIP_ID 0xBD
38 #define LPS25_CTRL_REG1 0x20
39 #define LPS25_CTRL_REG2 0x21
40 #define LPS25_CTRL_REG3 \
41  0x22
42 #define LPS25_CTRL_REG4 \
43  0x23
44 #define LPS25_INTERRUPT_CFG 0x24
45 #define LPS25_THS_P_L_REG 0xB0
46 
47 #define LPS2X_PRESS_OUT_XL \
48  (0x28 | 0x80)
49 #define LPS2X_TEMP_OUT_L (0x2B | 0x80)
50 
51 
56 typedef enum {
57  LPS25_RATE_ONE_SHOT,
58  LPS25_RATE_1_HZ,
59  LPS25_RATE_7_HZ,
60  LPS25_RATE_12_5_HZ,
61  LPS25_RATE_25_HZ,
62 } lps25_rate_t;
63 
69 typedef enum {
70  LPS22_RATE_ONE_SHOT,
71  LPS22_RATE_1_HZ,
72  LPS22_RATE_10_HZ,
73  LPS22_RATE_25_HZ,
74  LPS22_RATE_50_HZ,
75  LPS22_RATE_75_HZ,
76 } lps22_rate_t;
77 
78 class Adafruit_LPS2X;
79 
81 class Adafruit_LPS2X_Temp : public Adafruit_Sensor {
82 public:
85  Adafruit_LPS2X_Temp(Adafruit_LPS2X *parent) { _theLPS2X = parent; }
86  bool getEvent(sensors_event_t *);
87  void getSensor(sensor_t *);
88 
89 private:
90  int _sensorID = 0x25;
91  Adafruit_LPS2X *_theLPS2X = NULL;
92 };
93 
96 class Adafruit_LPS2X_Pressure : public Adafruit_Sensor {
97 public:
100  Adafruit_LPS2X_Pressure(Adafruit_LPS2X *parent) { _theLPS2X = parent; }
101  bool getEvent(sensors_event_t *);
102  void getSensor(sensor_t *);
103 
104 private:
105  int _sensorID = 0x26;
106  Adafruit_LPS2X *_theLPS2X = NULL;
107 };
108 
114 public:
115  Adafruit_LPS2X();
116  virtual ~Adafruit_LPS2X(){};
117 
118  bool begin_I2C(uint8_t i2c_addr = LPS2X_I2CADDR_DEFAULT,
119  TwoWire *wire = &Wire, int32_t sensor_id = 0);
120 
121  bool begin_SPI(uint8_t cs_pin, SPIClass *theSPI = &SPI,
122  int32_t sensor_id = 0);
123  bool begin_SPI(int8_t cs_pin, int8_t sck_pin, int8_t miso_pin,
124  int8_t mosi_pin, int32_t sensor_id = 0);
125 
126  void setPresThreshold(uint16_t hPa_delta);
127  bool getEvent(sensors_event_t *pressure, sensors_event_t *temp);
128  void reset(void);
129 
130  Adafruit_Sensor *getTemperatureSensor(void);
131  Adafruit_Sensor *getPressureSensor(void);
132 
133 protected:
137  virtual bool _init(int32_t sensor_id) = 0;
138 
139  void _read(void);
140 
141  float _temp,
142  _pressure;
143 
144  uint16_t _sensorid_pressure,
146  float temp_scaling = 1;
147  float temp_offset = 1;
148  uint8_t inc_spi_flag =
149  0;
150  bool isOneShot = false;
151 
152  Adafruit_I2CDevice *i2c_dev = NULL;
153  Adafruit_SPIDevice *spi_dev = NULL;
154 
155  Adafruit_LPS2X_Temp *temp_sensor = NULL;
156  Adafruit_LPS2X_Pressure *pressure_sensor =
157  NULL;
158 
159  Adafruit_BusIO_Register *ctrl1_reg = NULL;
160  Adafruit_BusIO_Register *ctrl2_reg = NULL;
161  Adafruit_BusIO_Register *ctrl3_reg = NULL;
162  Adafruit_BusIO_Register *threshp_reg = NULL;
163 
164 private:
165  friend class Adafruit_LPS2X_Temp;
166  friend class Adafruit_LPS2X_Pressure;
168 
171  void fillPressureEvent(sensors_event_t *pressure, uint32_t timestamp);
172  void fillTempEvent(sensors_event_t *temp, uint32_t timestamp);
173 };
174 
177 public:
178  ~Adafruit_LPS25();
179  lps25_rate_t getDataRate(void);
180  void setDataRate(lps25_rate_t data_rate);
181  void powerDown(bool power_down);
182  void configureInterrupt(bool activelow, bool opendrain,
183  bool pres_high = false, bool pres_low = false);
184 
185 protected:
186  bool _init(int32_t sensor_id);
187 };
188 
191 public:
192  ~Adafruit_LPS22();
193  lps22_rate_t getDataRate(void);
194  void setDataRate(lps22_rate_t data_rate);
195  void configureInterrupt(bool activelow, bool opendrain, bool data_ready,
196  bool pres_high = false, bool pres_low = false,
197  bool fifo_full = false, bool fifo_watermark = false,
198  bool fifo_overflow = false);
199 
200 protected:
201  bool _init(int32_t sensor_id);
202 };
203 
204 #endif
lps22_rate_t
Allowed values for setDataRate.
Definition: Adafruit_LPS2X.h:69
bool getEvent(sensors_event_t *)
Gets the temperature as a standard sensor event.
Definition: Adafruit_LPS2X.cpp:332
Class that stores state and functions for interacting with the LPS2X I2C Barometric Pressure & Temper...
Definition: Adafruit_LPS2X.h:113
Adafruit_LPS2X_Pressure(Adafruit_LPS2X *parent)
Create an Adafruit_Sensor compatible object for the pressure sensor.
Definition: Adafruit_LPS2X.h:100
void getSensor(sensor_t *)
Gets the sensor_t data for the LPS2X&#39;s tenperature.
Definition: Adafruit_LPS2X.cpp:309
Definition: Adafruit_LPS2X.h:176
float _temp
Last reading&#39;s temperature (C)
Definition: Adafruit_LPS2X.h:141
#define LPS2X_I2CADDR_DEFAULT
LPS2X default i2c address.
Definition: Adafruit_LPS2X.h:27
Definition: Adafruit_LPS2X.h:96
lps25_rate_t
Allowed values for setDataRate.
Definition: Adafruit_LPS2X.h:56
uint16_t _sensorid_temp
ID number for temperature.
Definition: Adafruit_LPS2X.h:144
Adafruit_LPS2X_Temp(Adafruit_LPS2X *parent)
Create an Adafruit_Sensor compatible object for the temp sensor.
Definition: Adafruit_LPS2X.h:85
Definition: Adafruit_LPS2X.h:81
Definition: Adafruit_LPS2X.h:190