Testing SHT75 humidity sensor on STM F303K8 board.

Dependencies:   SHT75 mbed

Fork of Nucleo-F303K8-SSD1306_OLED by Joseph Ellsworth

Sample code to test SHT75 humidity sensor using STM F303K8 board. Uses a 3.3V from board to power sensor. 10K resistor Pull-up on data. Must not be on same pins as I2C. Uses D0 for Clk and D1 for Data.

I had to modify sample code supplied by https://developer.mbed.org/users/nimbusgb/code/SHT75/ because the sensor failed to read without the softReset() and readStatus() at beginning of measurement loop. I think this is caused by the 72Mhtz speed of the F303K8 but did not attempt to fully diagnose.

The readStatus() method from library seems to malfunction and always return a -1 which never changes even when sensor is unplugged.

See https://www.sensirion.com/fileadmin/user_upload/customers/sensirion/Dokumente/Humidity_Sensors/Sensirion_Humidity_Sensors_SHT7x_Datasheet_V5.pdf section 2.1 for wiring.

Committer:
joeata2wh
Date:
Wed Jul 27 19:42:41 2016 +0000
Revision:
4:2c46c3bc8032
Parent:
3:47148198f5f2
Child:
5:4b66dfbc52a5
working version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
joeata2wh 4:2c46c3bc8032 1 /* Test ability to read SHT75 sensor
joeata2wh 4:2c46c3bc8032 2 Note: Can not be on same pins as I2C due to different pull up
joeata2wh 4:2c46c3bc8032 3 requirements.
joeata2wh 2:dc3e84d595c3 4
joeata2wh 3:47148198f5f2 5 By Joseph Ellsworth CTO of A2WH
joeata2wh 3:47148198f5f2 6 Take a look at A2WH.com Producing Water from Air using Solar Energy
joeata2wh 4:2c46c3bc8032 7 March-2016 License: https://developer.mbed.org/handbook/MIT-Licence
joeata2wh 3:47148198f5f2 8 Please contact us http://a2wh.com for help with custom design projects.
joeata2wh 3:47148198f5f2 9
joeata2wh 4:2c46c3bc8032 10 See Also: https://www.sensirion.com/fileadmin/user_upload/customers/sensirion/Dokumente/Humidity_Sensors/Sensirion_Humidity_Sensors_SHT7x_Datasheet_V5.pdf
joeata2wh 3:47148198f5f2 11
joeata2wh 1:90d213185462 12 */
joeata2wh 0:fa185766e039 13
joeata2wh 0:fa185766e039 14 #include "mbed.h"
joeata2wh 4:2c46c3bc8032 15 #include <stdint.h>
joeata2wh 2:dc3e84d595c3 16
joeata2wh 4:2c46c3bc8032 17 #define sht75_clk D0
joeata2wh 4:2c46c3bc8032 18 #define sht75_data D1
joeata2wh 4:2c46c3bc8032 19 #include "sht7X.h"
joeata2wh 4:2c46c3bc8032 20 SHT75 sht(sht75_clk, sht75_data);
joeata2wh 4:2c46c3bc8032 21
joeata2wh 2:dc3e84d595c3 22
joeata2wh 2:dc3e84d595c3 23 // Host PC Communication channels
joeata2wh 2:dc3e84d595c3 24 Serial pc(USBTX, USBRX); // tx, rx
joeata2wh 4:2c46c3bc8032 25 char buff[100];
joeata2wh 2:dc3e84d595c3 26
joeata2wh 0:fa185766e039 27 DigitalOut myled(LED1);
joeata2wh 2:dc3e84d595c3 28
joeata2wh 2:dc3e84d595c3 29 int main()
joeata2wh 2:dc3e84d595c3 30 {
joeata2wh 4:2c46c3bc8032 31 pc.baud(38400);
joeata2wh 4:2c46c3bc8032 32 wait(1);
joeata2wh 0:fa185766e039 33 while(1) {
joeata2wh 2:dc3e84d595c3 34 myled = !myled;
joeata2wh 4:2c46c3bc8032 35 float temperature; // temperature -40 to 120 deg C
joeata2wh 4:2c46c3bc8032 36 float humidity; // relative humidity 1% to 100%
joeata2wh 4:2c46c3bc8032 37 float humi_f,rh_lin,rh_true; // working registers for Illustration purposes
joeata2wh 4:2c46c3bc8032 38 int t; // temporary store for the temp ticks
joeata2wh 4:2c46c3bc8032 39 int h;
joeata2wh 4:2c46c3bc8032 40 sht.softReset();
joeata2wh 4:2c46c3bc8032 41 int stat = sht.readStatus();
joeata2wh 4:2c46c3bc8032 42 wait(3.0);
joeata2wh 4:2c46c3bc8032 43 sht.readTempTicks(&t);
joeata2wh 4:2c46c3bc8032 44 temperature = ((float)(t) * 0.01) - 39.61;
joeata2wh 3:47148198f5f2 45
joeata2wh 4:2c46c3bc8032 46 sht.readHumidityTicks(&h);
joeata2wh 4:2c46c3bc8032 47 humi_f = (float)(h);
joeata2wh 4:2c46c3bc8032 48 rh_lin = C3 * humi_f * humi_f + C2 * humi_f + C1;
joeata2wh 4:2c46c3bc8032 49 rh_true=(((temperature/100)-25)*(T1+T2*humi_f)+rh_lin);
joeata2wh 4:2c46c3bc8032 50 if(rh_true>100)rh_true=100; //cut if the value is outside
joeata2wh 4:2c46c3bc8032 51 if(rh_true<1)rh_true=1; //the physical possible range
joeata2wh 4:2c46c3bc8032 52 humidity = rh_true;
joeata2wh 4:2c46c3bc8032 53 pc.printf("stat=%d Temp: %2.2f RH %2.2f\n\r",stat, temperature, humidity);
joeata2wh 4:2c46c3bc8032 54
joeata2wh 2:dc3e84d595c3 55 wait(3.0);
joeata2wh 0:fa185766e039 56 }
joeata2wh 4:2c46c3bc8032 57 }