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:
Mon Mar 21 00:11:05 2016 +0000
Revision:
1:90d213185462
Parent:
0:fa185766e039
Child:
2:dc3e84d595c3
initial version request comment

Who changed what in which revision?

UserRevisionLine numberNew contents of line
joeata2wh 1:90d213185462 1 /* Example of Reading all the ADC pins PIN and display ot OLED display using
joeata2wh 1:90d213185462 2 Nucleo_F303K8 by Joseph Ellsworth CTO A2WH - Free for all but no warranty, no promises
joeata2wh 1:90d213185462 3 Attempt to drive:
joeata2wh 1:90d213185462 4 ebay part http://www.ebay.com/itm/152000005331?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT
joeata2wh 1:90d213185462 5 0-96-I2C-IIC-SPI-Serial-White-OLED-LCD-LED-Display-Module-128X64
joeata2wh 1:90d213185462 6 The Datasheet. https://www.adafruit.com/datasheets/SSD1306.pdf
joeata2wh 1:90d213185462 7
joeata2wh 1:90d213185462 8 Unfortunately this part never turns on using the SSD1308 library.
joeata2wh 1:90d213185462 9 Not sure why and don't have time to finish tracking it down at this
joeata2wh 1:90d213185462 10 time.
joeata2wh 1:90d213185462 11
joeata2wh 1:90d213185462 12 Using my I2C address scanner I found that it responds on Added 120 (x78) ,121 (x79)
joeata2wh 1:90d213185462 13 and when the part was unsoldered nothing responded on 120 or 121. According to
joeata2wh 1:90d213185462 14 to the page #19 (8.1.5) of the data sheet the I2C address should be 011110
joeata2wh 1:90d213185462 15 which seems to map correctly to dec=120 hex=79 so I think the chip is responsive
joeata2wh 1:90d213185462 16 and the library must be sending incorrect commands.
joeata2wh 1:90d213185462 17
joeata2wh 1:90d213185462 18 */
joeata2wh 0:fa185766e039 19
joeata2wh 0:fa185766e039 20 #include "mbed.h"
joeata2wh 1:90d213185462 21 #include "SSD1308.h"
joeata2wh 0:fa185766e039 22
joeata2wh 1:90d213185462 23 //#include "mbed_logo.h"
joeata2wh 1:90d213185462 24
joeata2wh 1:90d213185462 25 //Pin Defines for I2C Bus
joeata2wh 1:90d213185462 26 #define D_SDA PB_7 // specific for Nucleo-F303K8
joeata2wh 1:90d213185462 27 #define D_SCL PB_6 // specific for Nucleo-F303K8
joeata2wh 1:90d213185462 28 I2C i2c(D_SDA, D_SCL);
joeata2wh 1:90d213185462 29
joeata2wh 1:90d213185462 30 // Host PC Communication channels
joeata2wh 1:90d213185462 31 Serial pc(USBTX, USBRX); // tx, rx
joeata2wh 1:90d213185462 32
joeata2wh 1:90d213185462 33 // Instantiate OLED
joeata2wh 1:90d213185462 34 //SSD1308 oled = SSD1308(i2c, SSD1308_SA0);
joeata2wh 1:90d213185462 35 SSD1308 oled = SSD1308(i2c, SSD1308_SA1);
joeata2wh 1:90d213185462 36 //SSD1308 oled = SSD1308(i2c, 120);
joeata2wh 1:90d213185462 37
joeata2wh 1:90d213185462 38 AnalogIn pa0(PA_0);
joeata2wh 0:fa185766e039 39
joeata2wh 0:fa185766e039 40 DigitalOut myled(LED1);
joeata2wh 0:fa185766e039 41 const float voltMeterARef = 3.3;
joeata2wh 0:fa185766e039 42
joeata2wh 1:90d213185462 43 char buff[100];
joeata2wh 0:fa185766e039 44 float readPrint(AnalogIn ain, char *label) {
joeata2wh 0:fa185766e039 45 float tval = ain.read();
joeata2wh 0:fa185766e039 46 float volts = tval * voltMeterARef;
joeata2wh 0:fa185766e039 47 float perc = tval * 100.0;
joeata2wh 0:fa185766e039 48 unsigned short tvalu16 = ain.read_u16 ();
joeata2wh 0:fa185766e039 49
joeata2wh 0:fa185766e039 50 printf("adc %s R=%3.3f V=%3.3f%% U16=%u\r\n",label, tval, volts, tvalu16);
joeata2wh 1:90d213185462 51 sprintf(buff, "V=%3.3f%",volts);
joeata2wh 1:90d213185462 52 oled.printf(buff);
joeata2wh 0:fa185766e039 53 return tval;
joeata2wh 0:fa185766e039 54 }
joeata2wh 0:fa185766e039 55
joeata2wh 0:fa185766e039 56
joeata2wh 0:fa185766e039 57 int main() {
joeata2wh 1:90d213185462 58 pc.printf("OLED test start\r");
joeata2wh 1:90d213185462 59 oled.writeString(0, 0, "Hello World !");
joeata2wh 1:90d213185462 60 oled.printf("Hello World !");
joeata2wh 1:90d213185462 61
joeata2wh 1:90d213185462 62 oled.fillDisplay(0xAA);
joeata2wh 1:90d213185462 63 oled.setDisplayOff();
joeata2wh 1:90d213185462 64 wait(1);
joeata2wh 1:90d213185462 65 oled.setDisplayOn();
joeata2wh 1:90d213185462 66 oled.clearDisplay();
joeata2wh 1:90d213185462 67 oled.setDisplayInverse();
joeata2wh 1:90d213185462 68 wait(0.5);
joeata2wh 1:90d213185462 69 oled.setDisplayNormal();
joeata2wh 1:90d213185462 70 //oled.writeBitmap((uint8_t*) mbed_logo);
joeata2wh 1:90d213185462 71 pc.printf("OLED test done\r\n");
joeata2wh 1:90d213185462 72
joeata2wh 1:90d213185462 73
joeata2wh 0:fa185766e039 74
joeata2wh 0:fa185766e039 75 while(1) {
joeata2wh 0:fa185766e039 76 myled = !myled; // toggle led
joeata2wh 1:90d213185462 77 readPrint(pa0, "PA_0");
joeata2wh 1:90d213185462 78 wait(7.0);
joeata2wh 0:fa185766e039 79 }
joeata2wh 0:fa185766e039 80 }