![](/media/cache/profiles/eb1feb5ab28dec83652dd1e5c673f256.jpg.50x50_q85.jpg)
A simple example adopting SHT21 Arduino library to mbed.
SHT21.hpp@1:f4a1942b4486, 2017-09-13 (annotated)
- Committer:
- odtulumbedder
- Date:
- Wed Sep 13 13:36:04 2017 +0000
- Revision:
- 1:f4a1942b4486
file order fixed.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
odtulumbedder | 1:f4a1942b4486 | 1 | #ifndef SHT21_HPP_INCLUDED |
odtulumbedder | 1:f4a1942b4486 | 2 | #define SHT21_HPP_INCLUDED |
odtulumbedder | 1:f4a1942b4486 | 3 | |
odtulumbedder | 1:f4a1942b4486 | 4 | #include "mbed.h" |
odtulumbedder | 1:f4a1942b4486 | 5 | |
odtulumbedder | 1:f4a1942b4486 | 6 | class SHT21 { |
odtulumbedder | 1:f4a1942b4486 | 7 | public: |
odtulumbedder | 1:f4a1942b4486 | 8 | SHT21(PinName sda, PinName scl, char addr = (0x40 << 1)); |
odtulumbedder | 1:f4a1942b4486 | 9 | SHT21(I2C &i2c, char addr = (0x40 << 1)); |
odtulumbedder | 1:f4a1942b4486 | 10 | |
odtulumbedder | 1:f4a1942b4486 | 11 | float temperature(); |
odtulumbedder | 1:f4a1942b4486 | 12 | float humidity(); |
odtulumbedder | 1:f4a1942b4486 | 13 | |
odtulumbedder | 1:f4a1942b4486 | 14 | void reset(); |
odtulumbedder | 1:f4a1942b4486 | 15 | void serialNumber(uint8_t *serialNumber); |
odtulumbedder | 1:f4a1942b4486 | 16 | |
odtulumbedder | 1:f4a1942b4486 | 17 | ~SHT21(); |
odtulumbedder | 1:f4a1942b4486 | 18 | private: |
odtulumbedder | 1:f4a1942b4486 | 19 | enum commands { |
odtulumbedder | 1:f4a1942b4486 | 20 | TRIGGER_T_MEASUREMENT_HM = 0xE3, |
odtulumbedder | 1:f4a1942b4486 | 21 | TRIGGER_RH_MEASUREMENT_HM = 0xE5, |
odtulumbedder | 1:f4a1942b4486 | 22 | TRIGGER_T_MEASUREMENT_NHM = 0xF3, |
odtulumbedder | 1:f4a1942b4486 | 23 | TRIGGER_RH_MEASUREMENT_NHM = 0xF5, |
odtulumbedder | 1:f4a1942b4486 | 24 | USER_REGISTER_W = 0xE6, |
odtulumbedder | 1:f4a1942b4486 | 25 | USER_REGISTER_R = 0xE7, |
odtulumbedder | 1:f4a1942b4486 | 26 | SOFT_RESET = 0xFE |
odtulumbedder | 1:f4a1942b4486 | 27 | }; |
odtulumbedder | 1:f4a1942b4486 | 28 | |
odtulumbedder | 1:f4a1942b4486 | 29 | static const uint16_t POLYNOMIAL; |
odtulumbedder | 1:f4a1942b4486 | 30 | |
odtulumbedder | 1:f4a1942b4486 | 31 | char addr_; |
odtulumbedder | 1:f4a1942b4486 | 32 | I2C *pi2c_; |
odtulumbedder | 1:f4a1942b4486 | 33 | I2C &i2c_; |
odtulumbedder | 1:f4a1942b4486 | 34 | |
odtulumbedder | 1:f4a1942b4486 | 35 | uint16_t readRaw(uint8_t cmd); |
odtulumbedder | 1:f4a1942b4486 | 36 | static bool crcChecksum(const uint8_t *data, uint8_t sz, uint8_t checksum); |
odtulumbedder | 1:f4a1942b4486 | 37 | }; |
odtulumbedder | 1:f4a1942b4486 | 38 | |
odtulumbedder | 1:f4a1942b4486 | 39 | #endif // SHT21_HPP_INCLUDED |