Go to most recent revision | Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 5 | mjames | 1 | //============================================================================== |
| 2 | // E - R A D I O N I C A . C O M, H.Kolomana 6/A, Djakovo 31400, Croatia |
||
| 3 | //============================================================================== |
||
| 4 | // Project : SHT21 Arduino Library (V1.0) |
||
| 5 | // File : SHT21.h |
||
| 6 | // Author : e-radionica.com 2017 |
||
| 7 | // Licence : Open-source ! |
||
| 8 | //============================================================================== |
||
| 9 | //============================================================================== |
||
| 10 | // Use with any SHT21 breakout. Check ours: |
||
| 11 | // https://e-radionica.com/en/sht21-humidity-and-temperature-sensor.html |
||
| 12 | // If any questions, |
||
| 13 | // just contact techsupport@e-radionica.com |
||
| 14 | //============================================================================== |
||
| 15 | |||
| 16 | #ifndef SHT21_H |
||
| 17 | #define SHT21_H |
||
| 18 | |||
| 19 | //---------- Defines ----------------------------------------------------------- |
||
| 20 | #define I2C_ADD 0x40 // I2C device address |
||
| 21 | |||
| 22 | const uint16_t POLYNOMIAL = 0x131; // P(x)=x^8+x^5+x^4+1 = 100110001 |
||
| 23 | |||
| 24 | //============================================================================== |
||
| 25 | #define TRIGGER_T_MEASUREMENT_HM 0XE3 // command trig. temp meas. hold master |
||
| 26 | #define TRIGGER_RH_MEASUREMENT_HM 0XE5 // command trig. hum. meas. hold master |
||
| 27 | #define TRIGGER_T_MEASUREMENT_NHM 0XF3 // command trig. temp meas. no hold master |
||
| 28 | #define TRIGGER_RH_MEASUREMENT_NHM 0XF5 // command trig. hum. meas. no hold master |
||
| 29 | #define USER_REGISTER_W 0XE6 // command writing user register |
||
| 30 | #define USER_REGISTER_R 0XE7 // command reading user register |
||
| 31 | #define SOFT_RESET 0XFE // command soft reset |
||
| 32 | //============================================================================== |
||
| 33 | // HOLD MASTER - SCL line is blocked (controlled by sensor) during measurement |
||
| 34 | // NO HOLD MASTER - allows other I2C communication tasks while sensor performing |
||
| 35 | // measurements. |
||
| 36 | |||
| 37 | |||
| 38 | class SHT21 |
||
| 39 | { |
||
| 40 | private: |
||
| 41 | //============================================================================== |
||
| 42 | uint16_t readSensor_hm(uint8_t command); |
||
| 43 | //============================================================================== |
||
| 44 | // reads SHT21 with hold master operation mode |
||
| 45 | // input: temp/hum command |
||
| 46 | // return: temp/hum raw data (16bit scaled) |
||
| 47 | |||
| 48 | |||
| 49 | //============================================================================== |
||
| 50 | float CalcRH(uint16_t rh); |
||
| 51 | //============================================================================== |
||
| 52 | // calculates the relative humidity |
||
| 53 | // input: rh: humidity raw value (16bit scaled) |
||
| 54 | // return: relative humidity [%RH] (float) |
||
| 55 | |||
| 56 | //============================================================================== |
||
| 57 | float CalcT(uint16_t t); |
||
| 58 | //============================================================================== |
||
| 59 | // calculates the temperature |
||
| 60 | // input: t: temperature raw value (16bit scaled) |
||
| 61 | // return: relative temperature [°C] (float) |
||
| 62 | |||
| 63 | //============================================================================== |
||
| 64 | uint8_t CRC_Checksum(uint8_t data[], uint8_t no_of_bytes, uint8_t checksum); |
||
| 65 | //============================================================================== |
||
| 66 | // CRC-8 checksum for error detection |
||
| 67 | // input: data[] checksum is built based on this data |
||
| 68 | // no_of_bytes checksum is built for n bytes of data |
||
| 69 | // checksum expected checksum |
||
| 70 | // return: 1 = checksum does not match |
||
| 71 | // 0 = checksum matches |
||
| 72 | |||
| 73 | |||
| 74 | public: |
||
| 75 | // I2C config for this chip |
||
| 76 | static const I2CConfig i2ccfg = { OPMODE_I2C, 400000, FAST_DUTY_CYCLE_2, }; |
||
| 77 | |||
| 78 | |||
| 79 | |||
| 80 | //============================================================================== |
||
| 81 | float getHumidity(void); |
||
| 82 | //============================================================================== |
||
| 83 | // calls humidity measurement with hold master mode |
||
| 84 | |||
| 85 | //============================================================================== |
||
| 86 | float getTemperature(void); |
||
| 87 | //============================================================================== |
||
| 88 | // calls temperature measurement with hold master mode |
||
| 89 | |||
| 90 | //============================================================================== |
||
| 91 | void reset(); |
||
| 92 | //============================================================================== |
||
| 93 | // performs a soft reset, delays 15ms |
||
| 94 | |||
| 95 | //============================================================================== |
||
| 96 | uint8_t getSerialNumber(uint8_t return_sn); |
||
| 97 | //============================================================================== |
||
| 98 | // returns electronical identification code depending of selected memory |
||
| 99 | // location |
||
| 100 | |||
| 101 | }; |
||
| 102 | |||
| 103 | #endif |