SHT30-DIS-B Library

Dependents:   M1DK_Skywire_Demo M1DK_Skywire_Demo1

Fork of LPS331 by NimbeLink

Committer:
GregNash
Date:
Wed Feb 01 18:36:34 2017 +0000
Revision:
3:7e631c5756e2
Parent:
LPS331.cpp@1:f70e671b008f
Code share

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GregNash 3:7e631c5756e2 1
yasuyuki 0:ef4f624dc3ec 2
yasuyuki 0:ef4f624dc3ec 3 #include "mbed.h"
GregNash 3:7e631c5756e2 4 #include "SHT30DISB.h"
yasuyuki 0:ef4f624dc3ec 5
GregNash 3:7e631c5756e2 6
GregNash 3:7e631c5756e2 7 SHT30DISB::SHT30DISB (PinName sda, PinName scl) : _i2c(sda, scl) {
yasuyuki 0:ef4f624dc3ec 8 init();
yasuyuki 0:ef4f624dc3ec 9 }
GregNash 3:7e631c5756e2 10 SHT30DISB::SHT30DISB (I2C& p_i2c) : _i2c(p_i2c) {
yasuyuki 0:ef4f624dc3ec 11 init();
yasuyuki 0:ef4f624dc3ec 12 }
yasuyuki 0:ef4f624dc3ec 13
GregNash 3:7e631c5756e2 14 void SHT30DISB::init(void)
GregNash 3:7e631c5756e2 15 {
GregNash 3:7e631c5756e2 16 _i2c.frequency(400000);
GregNash 3:7e631c5756e2 17 buf[0]=0x2c;
GregNash 3:7e631c5756e2 18 buf[1]=0x06;
GregNash 3:7e631c5756e2 19 data_buf[6]= _i2c.write(SHT30DISB_ADDR,buf,2);
GregNash 3:7e631c5756e2 20 buf[0]=0x30;
GregNash 3:7e631c5756e2 21 buf[1]=0x66;
GregNash 3:7e631c5756e2 22 data_buf[7]= _i2c.write(SHT30DISB_ADDR,buf,2);
GregNash 3:7e631c5756e2 23
GregNash 3:7e631c5756e2 24 // put(0x2C,0x06); //Config measurement
GregNash 3:7e631c5756e2 25 // put(0x30, 0x66); //Heat off
GregNash 3:7e631c5756e2 26
GregNash 3:7e631c5756e2 27 }
GregNash 3:7e631c5756e2 28 void SHT30DISB::put(unsigned char a, unsigned char b)
yasuyuki 0:ef4f624dc3ec 29 {
yasuyuki 0:ef4f624dc3ec 30 buf[0]=a;
yasuyuki 0:ef4f624dc3ec 31 buf[1]=b;
GregNash 3:7e631c5756e2 32 _i2c.write(SHT30DISB_ADDR, buf, 2);
yasuyuki 0:ef4f624dc3ec 33 }
yasuyuki 0:ef4f624dc3ec 34
yasuyuki 0:ef4f624dc3ec 35
GregNash 3:7e631c5756e2 36 void SHT30DISB::get(unsigned char a)
yasuyuki 0:ef4f624dc3ec 37 {
yasuyuki 0:ef4f624dc3ec 38 buf[0] = a;
GregNash 3:7e631c5756e2 39 _i2c.write(SHT30DISB_ADDR, buf, 1, true); // no stop, repeated
GregNash 3:7e631c5756e2 40 _i2c.read(SHT30DISB_ADDR, buf, 1);
yasuyuki 0:ef4f624dc3ec 41
yasuyuki 0:ef4f624dc3ec 42 }
yasuyuki 0:ef4f624dc3ec 43
yasuyuki 0:ef4f624dc3ec 44
GregNash 3:7e631c5756e2 45 void SHT30DISB::readSensor()
GregNash 3:7e631c5756e2 46 {
GregNash 3:7e631c5756e2 47 // data_buf[0]=_i2c.read(SHT30DISB_ADDR, SHT30DISB_DATA, 6, true); // no stop, repeated
GregNash 3:7e631c5756e2 48 buf[0]=0x2c;
GregNash 3:7e631c5756e2 49 buf[1]=0x06;
GregNash 3:7e631c5756e2 50 data_buf[0]=_i2c.write(0x8A, buf,2);
GregNash 3:7e631c5756e2 51 wait(.1);
GregNash 3:7e631c5756e2 52 data_buf[1]=_i2c.read(0x8A, SHT30DISB_DATA, 6, false);
GregNash 3:7e631c5756e2 53
yasuyuki 0:ef4f624dc3ec 54 }
yasuyuki 0:ef4f624dc3ec 55
yasuyuki 1:f70e671b008f 56
GregNash 3:7e631c5756e2 57 float SHT30DISB::cTemp(){
GregNash 3:7e631c5756e2 58 readSensor();
GregNash 3:7e631c5756e2 59 c_Temp = -45 + 175 * ((((SHT30DISB_DATA[0] * 256.0) + SHT30DISB_DATA[1])) / 65535.0);
GregNash 3:7e631c5756e2 60 return c_Temp;
yasuyuki 1:f70e671b008f 61 }
GregNash 3:7e631c5756e2 62
GregNash 3:7e631c5756e2 63 float SHT30DISB::fTemp(){
GregNash 3:7e631c5756e2 64 f_Temp = 32 + 1.8 * cTemp();
GregNash 3:7e631c5756e2 65 return f_Temp;
GregNash 3:7e631c5756e2 66 }
GregNash 3:7e631c5756e2 67
GregNash 3:7e631c5756e2 68 float SHT30DISB::humidity(){
GregNash 3:7e631c5756e2 69 humi = 100 * ((((SHT30DISB_DATA[3] * 256.0) + SHT30DISB_DATA[4])) / 65535.0);
GregNash 3:7e631c5756e2 70 return humi;
yasuyuki 0:ef4f624dc3ec 71 }
yasuyuki 0:ef4f624dc3ec 72
yasuyuki 0:ef4f624dc3ec 73
yasuyuki 1:f70e671b008f 74