SHTC3-Soldered Library 1.0.0
This is a library for the SHTC3 sensor
Loading...
Searching...
No Matches
SHTC3.h
Go to the documentation of this file.
1#ifndef _H_ARDUINO_SHTC3_H_
2#define _H_ARDUINO_SHTC3_H_
3
4#include <Arduino.h>
5#include <Wire.h>
6
7// Uncomment this for no float operation
8//#define ARDUINO_SHTC3_NOFLOAT 1
9
10#define SHTC3_RESET_DELAY_US (255)
11
12typedef TwoWire arduino_shtc3_wire_t;
13
15{
16 SHTC3_SLEEP = 0xB098,
17 SHTC3_WAKEUP = 0x3517,
18 SHTC3_RESET = 0x805D,
19 SHTC3_ID = 0xEFC8,
20 SHTC3_READ = 0x7CA2, // T first + Clock streching
21 SHTC3_READ_LP = 0x6458 // T first + Clock streching + Low power
22};
23
24class SHTC3
25{
26 public:
27 SHTC3(arduino_shtc3_wire_t &w = Wire) : _wire(w), _t(0), _h(0)
28 {
29 }
30
31 bool begin(bool do_sample = false);
32 bool sample(uint16_t readcmd = SHTC3_READ_LP, uint8_t pause = 0);
33#if defined(ARDUINO_SHTC3_NOFLOAT)
34 int16_t readTempC();
35 uint16_t readHumidity();
36#else
37 float readTempC();
38 float readHumidity();
39#endif
40
41 inline bool sleep()
42 {
43 return twiCommand(SHTC3_SLEEP);
44 }
45 inline bool wakeup()
46 {
47 bool b = twiCommand(SHTC3_WAKEUP);
48 delayMicroseconds(SHTC3_RESET_DELAY_US);
49 return b;
50 }
51 inline bool reset()
52 {
53 bool b = twiCommand(SHTC3_RESET);
54 delayMicroseconds(SHTC3_RESET_DELAY_US);
55 return b;
56 }
57
58 bool twiCommand(uint16_t cmd, uint8_t stop = true);
59 bool twiTransfer(uint16_t cmd, uint8_t *data, uint8_t len, uint8_t pause = 0);
60
61 private:
62 // Properties
64 uint16_t _t;
65 uint16_t _h;
66 // Private methods
67 inline bool checkCRC(const uint8_t *data)
68 {
69 return crc8(data, 2) == data[2];
70 }
71 uint8_t crc8(const uint8_t *data, uint8_t len);
72};
73
74
75#endif
shtc3_cmds_t
Definition: SHTC3.h:15
@ SHTC3_SLEEP
Definition: SHTC3.h:16
@ SHTC3_READ_LP
Definition: SHTC3.h:21
@ SHTC3_ID
Definition: SHTC3.h:19
@ SHTC3_RESET
Definition: SHTC3.h:18
@ SHTC3_WAKEUP
Definition: SHTC3.h:17
@ SHTC3_READ
Definition: SHTC3.h:20
TwoWire arduino_shtc3_wire_t
Definition: SHTC3.h:12
Definition: SHTC3.h:25
bool wakeup()
Definition: SHTC3.h:45
uint16_t _h
Definition: SHTC3.h:65
bool begin(bool do_sample=false)
Definition: SHTC3.cpp:77
bool checkCRC(const uint8_t *data)
Definition: SHTC3.h:67
uint16_t readHumidity()
Definition: SHTC3.cpp:120
uint16_t _t
Definition: SHTC3.h:64
bool sample(uint16_t readcmd=SHTC3_READ_LP, uint8_t pause=0)
Definition: SHTC3.cpp:94
bool twiCommand(uint16_t cmd, uint8_t stop=true)
Definition: SHTC3.cpp:47
bool reset()
Definition: SHTC3.h:51
SHTC3(arduino_shtc3_wire_t &w=Wire)
Definition: SHTC3.h:27
arduino_shtc3_wire_t & _wire
Definition: SHTC3.h:63
uint8_t crc8(const uint8_t *data, uint8_t len)
Definition: SHTC3.cpp:22
bool twiTransfer(uint16_t cmd, uint8_t *data, uint8_t len, uint8_t pause=0)
Definition: SHTC3.cpp:59
bool sleep()
Definition: SHTC3.h:41
int16_t readTempC()
Definition: SHTC3.cpp:114