forked from practicalarduino/SHT1x
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSHT1x.h
68 lines (62 loc) · 1.79 KB
/
SHT1x.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* SHT1x Library
*
* Copyright 2009 Jonathan Oxer <[email protected]> / <www.practicalarduino.com>
* Based on previous work by:
* Maurice Ribble: <www.glacialwanderer.com/hobbyrobotics/?p=5>
* Wayne ?: <ragingreality.blogspot.com/2008/01/ardunio-and-sht15.html>
*
* Manages communication with SHT1x series (SHT10, SHT11, SHT15)
* temperature / humidity sensors from Sensirion (www.sensirion.com).
*/
#ifndef SHT1x_h
#define SHT1x_h
#if (ARDUINO >= 100)
#include <Arduino.h>
#else
#include <WProgram.h>
#endif
#define TIMEOUT_MILLIS 1000
enum {
SHT1X_CMD_MEASURE_TEMP = B00000011,
SHT1X_CMD_MEASURE_RH = B00000101,
SHT1X_CMD_READ_STATUS = B00000111,
SHT1X_CMD_SOFT_RESET = B00011110
};
class SHT1x
{
public:
SHT1x(int dataPin, int clockPin);
SHT1x(int dataPin, int clockPin, float voltage, bool intPullup);
void reset();
//composite functions
float readHumidity();
float readTemperatureC();
float readTemperatureF();
uint8_t readStatus();
//decoupled functions
void requestTemperature();
int readInTemperature();
void requestHumidity();
float readInHumidity();
float parseHumidity(int raw);
float parseTemperatureC(int raw);
float parseTemperatureF(int raw);
private:
int _temperatureRaw;
int _dataPin;
int _clockPin;
int _dataInputMode;
uint8_t _status;
int _numBits;
float _D1C; float _D1F; float _D2C; float _D2F;
float _linearInterpolation(float coeffA, float coeffB, float valB, float input);
void _setConversionCoeffs(float voltage);
void sendCommandSHT(uint8_t _command);
void waitForResultSHT();
int getDataSHT(int bits);
void skipCrcSHT();
bool checkCrcSHT(uint8_t cmd, uint16_t data, int datalen);
uint8_t crc8(uint8_t data, uint8_t startval);
};
#endif