Adafruit Si7021 Library
Adafruit_Si7021.h
Go to the documentation of this file.
1 
22 #ifndef __Si7021_H__
23 #define __Si7021_H__
24 
25 #include "Arduino.h"
26 #include <Adafruit_I2CDevice.h>
27 
31 #define SI7021_DEFAULT_ADDRESS 0x40
32 
33 #define SI7021_MEASRH_HOLD_CMD \
34  0xE5
35 #define SI7021_MEASRH_NOHOLD_CMD \
36  0xF5
37 #define SI7021_MEASTEMP_HOLD_CMD \
38  0xE3
39 #define SI7021_MEASTEMP_NOHOLD_CMD \
40  0xF3
41 #define SI7021_READPREVTEMP_CMD \
42  0xE0
43 #define SI7021_RESET_CMD 0xFE
44 #define SI7021_WRITERHT_REG_CMD 0xE6
45 #define SI7021_READRHT_REG_CMD 0xE7
46 #define SI7021_WRITEHEATER_REG_CMD 0x51
47 #define SI7021_READHEATER_REG_CMD 0x11
48 #define SI7021_REG_HTRE_BIT 0x02
49 #define SI7021_ID1_CMD 0xFA0F
50 #define SI7021_ID2_CMD 0xFCC9
51 #define SI7021_FIRMVERS_CMD 0x84B8
53 #define SI7021_REV_1 0xff
54 #define SI7021_REV_2 0x20
57 enum si_sensorType {
58  SI_Engineering_Samples,
59  SI_7013,
60  SI_7020,
61  SI_7021,
62  SI_UNKNOWN,
63 };
64 
67  SI_HEATLEVEL_LOWEST = 0x00,
68  SI_HEATLEVEL_LOW = 0x01,
69  SI_HEATLEVEL_MEDIUM = 0x02,
70  SI_HEATLEVEL_HIGH = 0x04,
71  SI_HEATLEVEL_HIGHER = 0x08,
72  SI_HEATLEVEL_HIGHEST = 0x0F,
73 };
74 
80 public:
81  Adafruit_Si7021(TwoWire *theWire = &Wire);
82  bool begin();
83 
84  float readTemperature();
85  void reset();
86  void readSerialNumber();
87  float readHumidity();
88 
93  void heater(bool h);
94  bool isHeaterEnabled();
95 
100  void setHeatLevel(uint8_t level);
101 
106  uint8_t getRevision() { return _revision; };
108 
109  uint32_t sernum_a;
110  uint32_t sernum_b;
112 private:
113  void _readRevision();
114  si_sensorType _model;
115  uint8_t _revision;
116  uint8_t _readRegister8(uint8_t reg);
117  void _writeRegister8(uint8_t reg, uint8_t value);
118 
119  Adafruit_I2CDevice *i2c_dev = NULL;
120  const static int _TRANSACTION_TIMEOUT = 100; // Wire NAK/Busy timeout in ms
121 };
122 
123 #endif // __Si7021_H__
void reset()
Sends the reset command to Si7021.
Definition: Adafruit_Si7021.cpp:129
Adafruit_Si7021(TwoWire *theWire=&Wire)
Instantiates a new Adafruit_Si7021 class.
Definition: Adafruit_Si7021.cpp:38
si_sensorType getModel()
Returns sensor model established during init.
Definition: Adafruit_Si7021.cpp:202
uint32_t sernum_a
Definition: Adafruit_Si7021.h:109
void setHeatLevel(uint8_t level)
Set the sensor heater heat level.
Definition: Adafruit_Si7021.cpp:230
bool isHeaterEnabled()
Return sensor heater state.
Definition: Adafruit_Si7021.cpp:222
void heater(bool h)
Enable/Disable the sensor heater.
Definition: Adafruit_Si7021.cpp:207
void readSerialNumber()
Reads serial number and stores It in sernum_a and sernum_b variable.
Definition: Adafruit_Si7021.cpp:157
bool begin()
Sets up the HW by reseting It, reading serial number and reading revision.
Definition: Adafruit_Si7021.cpp:51
si_sensorType
Definition: Adafruit_Si7021.h:57
float readTemperature()
Reads the temperature value from Si7021 (No Master hold)
Definition: Adafruit_Si7021.cpp:100
Class that stores state and functions for interacting with Si7021 Sensor.
Definition: Adafruit_Si7021.h:79
si_heatLevel
Definition: Adafruit_Si7021.h:66
uint32_t sernum_b
Definition: Adafruit_Si7021.h:110
uint8_t getRevision()
Returns sensor revision established during init.
Definition: Adafruit_Si7021.h:106
float readHumidity()
Reads the humidity value from Si7021 (No Master hold)
Definition: Adafruit_Si7021.cpp:69