Adafruit HTS221 Library
Adafruit_HTS221.h
Go to the documentation of this file.
1 
18 #ifndef _ADAFRUIT_HTS221_H
19 #define _ADAFRUIT_HTS221_H
20 
21 #include "Arduino.h"
22 #include <Adafruit_BusIO_Register.h>
23 #include <Adafruit_I2CDevice.h>
24 #include <Adafruit_SPIDevice.h>
25 #include <Adafruit_Sensor.h>
26 #include <Wire.h>
27 
28 #define HTS221_I2CADDR_DEFAULT 0x5F
29 #define HTS221_CHIP_ID 0xBC
30 #define HTS221_CTRL_REG_1 0x20
31 #define HTS221_CTRL_REG_2 \
32  0x21
33 #define HTS221_CTRL_REG_3 0x22
34 #define HTS221_HUMIDITY_OUT 0x28
35 #define HTS221_TEMP_OUT_L 0x2A
36 #define HTS221_H0_RH_X2 0x30
37 #define HTS221_H1_RH_X2 0x31
38 #define HTS221_T0_DEGC_X8 0x32
39 #define HTS221_T1_T0_MSB 0x35
40 #define HTS221_H0_T0 0x36
41 #define HTS221_H0_T1 0x3A
42 #define HTS221_T0_OUT 0x3C
43 #define HTS221_T1_OUT 0x3E
44 
45 #define HTS221_WHOAMI 0x0F
46 
51 typedef enum {
52  HTS221_RATE_ONE_SHOT,
53  HTS221_RATE_1_HZ,
54  HTS221_RATE_7_HZ,
55  HTS221_RATE_12_5_HZ,
57 
58 class Adafruit_HTS221;
59 
65 class Adafruit_HTS221_Humidity : public Adafruit_Sensor {
66 public:
69  Adafruit_HTS221_Humidity(Adafruit_HTS221 *parent) { _theHTS221 = parent; }
70  bool getEvent(sensors_event_t *);
71  void getSensor(sensor_t *);
72 
73 private:
74  int _sensorID = 0x221;
75  Adafruit_HTS221 *_theHTS221 = NULL;
76 };
77 
83 class Adafruit_HTS221_Temp : public Adafruit_Sensor {
84 public:
87  Adafruit_HTS221_Temp(Adafruit_HTS221 *parent) { _theHTS221 = parent; }
88 
89  bool getEvent(sensors_event_t *);
90  void getSensor(sensor_t *);
91 
92 private:
93  int _sensorID = 0x222;
94  Adafruit_HTS221 *_theHTS221 = NULL;
95 };
96 
101 class Adafruit_HTS221 final {
102 public:
103  Adafruit_HTS221();
104  ~Adafruit_HTS221();
105 
106  bool begin_I2C(uint8_t i2c_addr = HTS221_I2CADDR_DEFAULT,
107  TwoWire *wire = &Wire, int32_t sensor_id = 0);
108 
109  bool begin_SPI(uint8_t cs_pin, SPIClass *theSPI = &SPI,
110  int32_t sensor_id = 0);
111  bool begin_SPI(int8_t cs_pin, int8_t sck_pin, int8_t miso_pin,
112  int8_t mosi_pin, int32_t sensor_id = 0);
113 
114  void boot(void);
115 
116  void setActive(bool active);
117  hts221_rate_t getDataRate(void);
118  void setDataRate(hts221_rate_t data_rate);
119 
120  void drdyActiveLow(bool active_low);
121  void drdyIntEnabled(bool drdy_int_enabled);
122 
123  bool getEvent(sensors_event_t *humidity, sensors_event_t *temp);
124  Adafruit_Sensor *getTemperatureSensor(void);
125  Adafruit_Sensor *getHumiditySensor(void);
126 
127 protected:
128  bool _read(void);
129  virtual bool _init(int32_t sensor_id);
130 
132  corrected_humidity;
133 
135  uint16_t _sensorid_temp;
136 
137  Adafruit_I2CDevice *i2c_dev = NULL;
138  Adafruit_SPIDevice *spi_dev = NULL;
139 
140  Adafruit_HTS221_Temp *temp_sensor = NULL;
141  Adafruit_HTS221_Humidity *humidity_sensor =
142  NULL;
143 
144 private:
145  void _fetchTempCalibrationValues(void);
146  void _fetchHumidityCalibrationValues(void);
147  friend class Adafruit_HTS221_Temp;
148  friend class Adafruit_HTS221_Humidity;
150 
152  void fillTempEvent(sensors_event_t *temp, uint32_t timestamp);
153  void fillHumidityEvent(sensors_event_t *humidity, uint32_t timestamp);
154 
155  void _applyTemperatureCorrection(void);
156  void _applyHumidityCorrection(void);
157  uint16_t T0, T1, T0_OUT, T1_OUT;
158  uint8_t H0, H1;
159  uint16_t H0_T0_OUT, H1_T0_OUT;
160  uint16_t raw_temperature;
161  uint16_t raw_humidity;
162 
163  uint8_t multi_byte_address_mask = 0x80; // default to I2C
164 };
165 
166 #endif
float corrected_temp
Last reading&#39;s temperature (C) before scaling.
Definition: Adafruit_HTS221.h:131
Class that stores state and functions for interacting with the HTS221 I2C Digital Potentiometer...
Definition: Adafruit_HTS221.h:101
uint16_t _sensorid_temp
ID number for temperature.
Definition: Adafruit_HTS221.h:135
hts221_rate_t
Allowed values for setDataRate.
Definition: Adafruit_HTS221.h:51
Adafruit_HTS221_Temp(Adafruit_HTS221 *parent)
Create an Adafruit_Sensor compatible object for the temp sensor.
Definition: Adafruit_HTS221.h:87
uint16_t _sensorid_humidity
ID number for humidity.
Definition: Adafruit_HTS221.h:134
Adafruit_HTS221_Humidity(Adafruit_HTS221 *parent)
Create an Adafruit_Sensor compatible object for the humidity sensor.
Definition: Adafruit_HTS221.h:69
Adafruit Unified Sensor interface for the temperature sensor component of HTS221. ...
Definition: Adafruit_HTS221.h:83
bool getEvent(sensors_event_t *)
Gets the humidity as a standard sensor event.
Definition: Adafruit_HTS221.cpp:479
#define HTS221_I2CADDR_DEFAULT
HTS221 default i2c address.
Definition: Adafruit_HTS221.h:28
Adafruit Unified Sensor interface for the humidity sensor component of HTS221.
Definition: Adafruit_HTS221.h:65
void getSensor(sensor_t *)
Gets the sensor_t object describing the HTS221&#39;s humidity sensor.
Definition: Adafruit_HTS221.cpp:459