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.
Dependents: mbed-os-example_2threads_RAK811
Diff: Sht31.h
- Revision:
- 0:c90aa4f69539
- Child:
- 3:861437b6816f
diff -r 000000000000 -r c90aa4f69539 Sht31.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Sht31.h Wed Jul 20 16:51:28 2016 +0000
@@ -0,0 +1,53 @@
+/***************************************************
+ This is a library for the SHT31 Digital Humidity & Temp Sht31
+
+ Designed specifically to work with the SHT31 Digital Sht31 from Adafruit
+ ----> https://www.adafruit.com/products/2857
+
+ These displays use I2C to communicate, 2 pins are required to
+ interface
+ Adafruit invests time and resources providing this open source code,
+ please support Adafruit and open-source hardware by purchasing
+ products from Adafruit!
+
+ Written by Limor Fried/Ladyada for Adafruit Industries.
+ BSD license, all text above must be included in any redistribution
+ ****************************************************/
+
+#ifndef Sht31_H
+#define Sht31_H
+
+#include "mbed.h"
+
+#define SHT31_DEFAULT_ADDR 0x44
+#define SHT31_MEAS_HIGHREP_STRETCH 0x2C06
+#define SHT31_MEAS_MEDREP_STRETCH 0x2C0D
+#define SHT31_MEAS_LOWREP_STRETCH 0x2C10
+#define SHT31_MEAS_HIGHREP 0x2400
+#define SHT31_MEAS_MEDREP 0x240B
+#define SHT31_MEAS_LOWREP 0x2416
+#define SHT31_READSTATUS 0xF32D
+#define SHT31_CLEARSTATUS 0x3041
+#define SHT31_SOFTRESET 0x30A2
+#define SHT31_HEATEREN 0x306D
+#define SHT31_HEATERDIS 0x3066
+
+class Sht31 {
+public:
+ Sht31(PinName sda, PinName scl);
+ float readTemperature(void);
+ float readHumidity(void);
+
+private:
+ void reset(void);
+ uint16_t readStatus(void);
+ void writeCommand(uint16_t cmd);
+ bool readTempHum(void);
+ uint8_t crc8(const uint8_t *data, int len);
+
+ I2C _i2c;
+ int _i2caddr;
+ float humidity, temp;
+};
+
+#endif