Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Sht31 by
Sht31.h@3:c4bd8cd5d566, 2018-10-03 (annotated)
- Committer:
- osilvam
- Date:
- Wed Oct 03 13:51:56 2018 +0000
- Revision:
- 3:c4bd8cd5d566
- Parent:
- 0:c90aa4f69539
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
GeofferyOmlette | 0:c90aa4f69539 | 1 | /*************************************************** |
GeofferyOmlette | 0:c90aa4f69539 | 2 | This is a library for the SHT31 Digital Humidity & Temp Sht31 |
GeofferyOmlette | 0:c90aa4f69539 | 3 | |
GeofferyOmlette | 0:c90aa4f69539 | 4 | Designed specifically to work with the SHT31 Digital Sht31 from Adafruit |
GeofferyOmlette | 0:c90aa4f69539 | 5 | ----> https://www.adafruit.com/products/2857 |
GeofferyOmlette | 0:c90aa4f69539 | 6 | |
GeofferyOmlette | 0:c90aa4f69539 | 7 | These displays use I2C to communicate, 2 pins are required to |
GeofferyOmlette | 0:c90aa4f69539 | 8 | interface |
GeofferyOmlette | 0:c90aa4f69539 | 9 | Adafruit invests time and resources providing this open source code, |
GeofferyOmlette | 0:c90aa4f69539 | 10 | please support Adafruit and open-source hardware by purchasing |
GeofferyOmlette | 0:c90aa4f69539 | 11 | products from Adafruit! |
GeofferyOmlette | 0:c90aa4f69539 | 12 | |
GeofferyOmlette | 0:c90aa4f69539 | 13 | Written by Limor Fried/Ladyada for Adafruit Industries. |
GeofferyOmlette | 0:c90aa4f69539 | 14 | BSD license, all text above must be included in any redistribution |
GeofferyOmlette | 0:c90aa4f69539 | 15 | ****************************************************/ |
GeofferyOmlette | 0:c90aa4f69539 | 16 | |
GeofferyOmlette | 0:c90aa4f69539 | 17 | #ifndef Sht31_H |
GeofferyOmlette | 0:c90aa4f69539 | 18 | #define Sht31_H |
GeofferyOmlette | 0:c90aa4f69539 | 19 | |
GeofferyOmlette | 0:c90aa4f69539 | 20 | #include "mbed.h" |
GeofferyOmlette | 0:c90aa4f69539 | 21 | |
GeofferyOmlette | 0:c90aa4f69539 | 22 | #define SHT31_DEFAULT_ADDR 0x44 |
GeofferyOmlette | 0:c90aa4f69539 | 23 | #define SHT31_MEAS_HIGHREP_STRETCH 0x2C06 |
GeofferyOmlette | 0:c90aa4f69539 | 24 | #define SHT31_MEAS_MEDREP_STRETCH 0x2C0D |
GeofferyOmlette | 0:c90aa4f69539 | 25 | #define SHT31_MEAS_LOWREP_STRETCH 0x2C10 |
GeofferyOmlette | 0:c90aa4f69539 | 26 | #define SHT31_MEAS_HIGHREP 0x2400 |
GeofferyOmlette | 0:c90aa4f69539 | 27 | #define SHT31_MEAS_MEDREP 0x240B |
GeofferyOmlette | 0:c90aa4f69539 | 28 | #define SHT31_MEAS_LOWREP 0x2416 |
GeofferyOmlette | 0:c90aa4f69539 | 29 | #define SHT31_READSTATUS 0xF32D |
GeofferyOmlette | 0:c90aa4f69539 | 30 | #define SHT31_CLEARSTATUS 0x3041 |
GeofferyOmlette | 0:c90aa4f69539 | 31 | #define SHT31_SOFTRESET 0x30A2 |
GeofferyOmlette | 0:c90aa4f69539 | 32 | #define SHT31_HEATEREN 0x306D |
GeofferyOmlette | 0:c90aa4f69539 | 33 | #define SHT31_HEATERDIS 0x3066 |
GeofferyOmlette | 0:c90aa4f69539 | 34 | |
GeofferyOmlette | 0:c90aa4f69539 | 35 | class Sht31 { |
GeofferyOmlette | 0:c90aa4f69539 | 36 | public: |
osilvam | 3:c4bd8cd5d566 | 37 | Sht31(PinName sda, PinName scl, bool i2caddr); |
GeofferyOmlette | 0:c90aa4f69539 | 38 | float readTemperature(void); |
GeofferyOmlette | 0:c90aa4f69539 | 39 | float readHumidity(void); |
osilvam | 3:c4bd8cd5d566 | 40 | bool readTempHum(float &_temp, float &_humidity); |
GeofferyOmlette | 0:c90aa4f69539 | 41 | |
GeofferyOmlette | 0:c90aa4f69539 | 42 | private: |
GeofferyOmlette | 0:c90aa4f69539 | 43 | void reset(void); |
GeofferyOmlette | 0:c90aa4f69539 | 44 | uint16_t readStatus(void); |
GeofferyOmlette | 0:c90aa4f69539 | 45 | void writeCommand(uint16_t cmd); |
GeofferyOmlette | 0:c90aa4f69539 | 46 | bool readTempHum(void); |
GeofferyOmlette | 0:c90aa4f69539 | 47 | uint8_t crc8(const uint8_t *data, int len); |
GeofferyOmlette | 0:c90aa4f69539 | 48 | |
GeofferyOmlette | 0:c90aa4f69539 | 49 | I2C _i2c; |
GeofferyOmlette | 0:c90aa4f69539 | 50 | int _i2caddr; |
GeofferyOmlette | 0:c90aa4f69539 | 51 | float humidity, temp; |
GeofferyOmlette | 0:c90aa4f69539 | 52 | }; |
GeofferyOmlette | 0:c90aa4f69539 | 53 | |
GeofferyOmlette | 0:c90aa4f69539 | 54 | #endif |