st-anything/lib/Adafruit_Si7021/Adafruit_Si7021.h

75 lines
2.1 KiB
C
Raw Normal View History

2023-03-11 14:11:03 +00:00
/**************************************************************************/
/*!
@file Adafruit_Si7021.h
@author Limor Fried (Adafruit Industries)
@license BSD (see license.txt)
This is a library for the Adafruit Si7021 breakout board
----> https://www.adafruit.com/products/3251
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
@section HISTORY
v1.0 - First release
*/
/**************************************************************************/
#ifndef __Si7021_H__
#define __Si7021_H__
#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
/*=========================================================================
I2C ADDRESS/BITS
-----------------------------------------------------------------------*/
#define SI7021_DEFAULT_ADDRESS (0x40)
#define SI7021_MEASRH_HOLD_CMD 0xE5
#define SI7021_MEASRH_NOHOLD_CMD 0xF5
#define SI7021_MEASTEMP_HOLD_CMD 0xE3
#define SI7021_MEASTEMP_NOHOLD_CMD 0xF3
#define SI7021_READPREVTEMP_CMD 0xE0
#define SI7021_RESET_CMD 0xFE
#define SI7021_WRITERHT_REG_CMD 0xE6
#define SI7021_READRHT_REG_CMD 0xE7
#define SI7021_WRITEHEATER_REG_CMD 0x51
#define SI7021_READHEATER_REG_CMD 0x11
#define SI7021_ID1_CMD 0xFA0F
#define SI7021_ID2_CMD 0xFCC9
#define SI7021_FIRMVERS_CMD 0x84B8
/*=========================================================================*/
class Adafruit_Si7021 {
public:
Adafruit_Si7021(void);
bool begin(void);
float readTemperature(void);
void reset(void);
void readSerialNumber(void);
float readHumidity(void);
uint32_t sernum_a, sernum_b;
private:
uint8_t readRegister8(uint8_t reg);
uint16_t readRegister16(uint8_t reg);
void writeRegister8(uint8_t reg, uint8_t value);
int8_t _i2caddr;
};
/**************************************************************************/
#endif // __Si7021_H__