SHT30-DIS-B Library
Dependents: M1DK_Skywire_Demo M1DK_Skywire_Demo1
Fork of LPS331 by
Revision 3:7e631c5756e2, committed 2017-02-01
- Comitter:
- GregNash
- Date:
- Wed Feb 01 18:36:34 2017 +0000
- Parent:
- 2:8a7744c5fb42
- Commit message:
- Code share
Changed in this revision
--- a/LPS331.cpp Wed Feb 25 02:52:47 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,84 +0,0 @@ -//********************** -// LPS331.cpp for mbed -// -// LPS331 barometer(P0_5,P0_4); -// or -// I2C i2c(P0_5,P0_4); -// LPS331 barometer(i2c); -// -// (C)Copyright 2014 All rights reserved by Y.Onodera -// http://einstlab.web.fc2.com -//********************** - -#include "mbed.h" -#include "LPS331.h" - -LPS331::LPS331 (PinName sda, PinName scl) : _i2c(sda, scl) { - init(); -} -LPS331::LPS331 (I2C& p_i2c) : _i2c(p_i2c) { - init(); -} - -void LPS331::put(unsigned char a, unsigned char b) -{ - buf[0]=a; - buf[1]=b; - _i2c.write(LPS331_ADDR, buf, 2); -} - - -void LPS331::get(unsigned char a) -{ - buf[0] = a; - _i2c.write(LPS331_ADDR, buf, 1, true); // no stop, repeated - _i2c.read( LPS331_ADDR, buf, 1); - -} - -long LPS331::value() -{ - - // XL first and H last - // get press_xl - get(LPS331_PRESS_POUT_XL_REH); - press.byte.LB=buf[0]; - // get tpress_low - get(LPS331_PRESS_OUT_L); - press.byte.HB=buf[0]; - // get press_high - get(LPS331_PRESS_OUT_H); - press.byte.UB=buf[0]; - return press.Val; - - // hPa = press.Val / 4096 - // Pa = press.Val / 40.96 -} - - -short LPS331::temperature() -{ - - // L first and H last - // get tpress_low - get(LPS331_TEMP_OUT_L); - temp.byte.LB=buf[0]; - // get press_high - get(LPS331_TEMP_OUT_H); - temp.byte.HB=buf[0]; - return temp.S; - - // C = 42.5 + temp.S / 480 - // range:0 to 80C - // accuracy:+-2C -} - - -void LPS331::init() -{ - // Power ON Cycle=1Hz - put(LPS331_CTRL_REG1, 0x90); -} - - -
--- a/LPS331.h Wed Feb 25 02:52:47 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -//********************** -// LPS331.h for mbed -// -// (C)Copyright 2014 All rights reserved by Y.Onodera -// http://einstlab.web.fc2.com -//********************** - -#ifndef LPS331_H_ -#define LPS331_H_ - -#define LPS331_ADDR_L 0xB8 -#define LPS331_ADDR_H 0xBA -#define LPS331_ADDR LPS331_ADDR_H -#define LPS331_REF_P_XL 0x08 -#define LPS331_REF_P_L 0x09 -#define LPS331_REF_P_H 0x0A -#define LPS331_WHO_AM_I 0x0F -#define LPS331_RES_CONF 0x10 -#define LPS331_CTRL_REG1 0x20 -#define LPS331_CTRL_REG2 0x21 -#define LPS331_CTRL_REG3 0x22 -#define LPS331_INT_CFG_REG 0x23 -#define LPS331_INT_SOURCE_REG 0x24 -#define LPS331_THS_P_LOW_REG 0x25 -#define LPS331_THS_P_HIGH_REG 0x26 -#define LPS331_STATUS_REG 0x27 -#define LPS331_PRESS_POUT_XL_REH 0x28 -#define LPS331_PRESS_OUT_L 0x29 -#define LPS331_PRESS_OUT_H 0x2A -#define LPS331_TEMP_OUT_L 0x2B -#define LPS331_TEMP_OUT_H 0x2C -#define LPS331_AMP_CTRL 0x2D -#define LPS331_DELTA_PRESS_XL 0x3C -#define LPS331_DELTA_PRESS_H 0x3D -#define LPS331_DELTA_PRESS_L 0x3E - -#include "mbed.h" -#include "typedef.h" - -class LPS331{ -public: - LPS331 (PinName sda, PinName scl); - LPS331 (I2C& p_i2c); - void init(); - - void put(unsigned char a, unsigned char b); - void get(unsigned char a); - long value(); - short temperature(); - -protected: - - I2C _i2c; - - DWORD_VAL press; - WORD_VAL temp; - char buf[2]; - -}; - -#endif /* LPS331_H_ */ - - -
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SHT30DISB.cpp Wed Feb 01 18:36:34 2017 +0000 @@ -0,0 +1,74 @@ + + +#include "mbed.h" +#include "SHT30DISB.h" + + +SHT30DISB::SHT30DISB (PinName sda, PinName scl) : _i2c(sda, scl) { + init(); +} +SHT30DISB::SHT30DISB (I2C& p_i2c) : _i2c(p_i2c) { + init(); +} + +void SHT30DISB::init(void) +{ + _i2c.frequency(400000); + buf[0]=0x2c; + buf[1]=0x06; + data_buf[6]= _i2c.write(SHT30DISB_ADDR,buf,2); + buf[0]=0x30; + buf[1]=0x66; + data_buf[7]= _i2c.write(SHT30DISB_ADDR,buf,2); + +// put(0x2C,0x06); //Config measurement +// put(0x30, 0x66); //Heat off + +} +void SHT30DISB::put(unsigned char a, unsigned char b) +{ + buf[0]=a; + buf[1]=b; + _i2c.write(SHT30DISB_ADDR, buf, 2); +} + + +void SHT30DISB::get(unsigned char a) +{ + buf[0] = a; + _i2c.write(SHT30DISB_ADDR, buf, 1, true); // no stop, repeated + _i2c.read(SHT30DISB_ADDR, buf, 1); + +} + + +void SHT30DISB::readSensor() +{ +// data_buf[0]=_i2c.read(SHT30DISB_ADDR, SHT30DISB_DATA, 6, true); // no stop, repeated + buf[0]=0x2c; + buf[1]=0x06; + data_buf[0]=_i2c.write(0x8A, buf,2); + wait(.1); + data_buf[1]=_i2c.read(0x8A, SHT30DISB_DATA, 6, false); + +} + + +float SHT30DISB::cTemp(){ + readSensor(); + c_Temp = -45 + 175 * ((((SHT30DISB_DATA[0] * 256.0) + SHT30DISB_DATA[1])) / 65535.0); + return c_Temp; +} + +float SHT30DISB::fTemp(){ + f_Temp = 32 + 1.8 * cTemp(); + return f_Temp; +} + +float SHT30DISB::humidity(){ + humi = 100 * ((((SHT30DISB_DATA[3] * 256.0) + SHT30DISB_DATA[4])) / 65535.0); + return humi; +} + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SHT30DISB.h Wed Feb 01 18:36:34 2017 +0000 @@ -0,0 +1,47 @@ + + +#ifndef SHT30DISB_H_ +#define SHT30DISB_H_ + +#define SHT30DISB_ADDR 0x8A +#define SHT30DISB_CLKENHI 0x2C06 +#define SHT30DISB_HEATON 0x306D +#define SHT30DISB_HEATOFF 0x3066 + + +#include "mbed.h" +#include "typedef.h" + +class SHT30DISB{ +public: + SHT30DISB (PinName sda, PinName scl); + SHT30DISB (I2C& p_i2c); + + void put(unsigned char a, unsigned char b); + void get(unsigned char a); + void readSensor(); + void init(); + float cTemp(); + float fTemp(); + float humidity(); + + char SHT30DISB_DATA[6]; + char data_buf[8]; + + +protected: + + I2C _i2c; + + char buf[2]; + + float c_Temp; + float f_Temp; + float humi; + +}; + +#endif /* SHT30DISB_H_ */ + + +