![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Testing SHT75 humidity sensor on STM F303K8 board.
Fork of Nucleo-F303K8-SSD1306_OLED by
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.
main.cpp@0:fa185766e039, 2016-03-19 (annotated)
- Committer:
- joeata2wh
- Date:
- Sat Mar 19 02:18:42 2016 +0000
- Revision:
- 0:fa185766e039
- Child:
- 1:90d213185462
working version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
joeata2wh | 0:fa185766e039 | 1 | /* Example of Reading all the ADC pins available on the Nucleo_F303K8. |
joeata2wh | 0:fa185766e039 | 2 | by Joseph Ellsworth CTO A2WH - Free for all but no warranty, no promises */ |
joeata2wh | 0:fa185766e039 | 3 | |
joeata2wh | 0:fa185766e039 | 4 | #include "mbed.h" |
joeata2wh | 0:fa185766e039 | 5 | |
joeata2wh | 0:fa185766e039 | 6 | // Initialize a pins to perform analog input and digital output fucntions |
joeata2wh | 0:fa185766e039 | 7 | AnalogIn aA7(PA_2); |
joeata2wh | 0:fa185766e039 | 8 | AnalogIn aA6(PA_7); |
joeata2wh | 0:fa185766e039 | 9 | AnalogIn aA5(PA_6); |
joeata2wh | 0:fa185766e039 | 10 | AnalogIn aA4(PA_5); |
joeata2wh | 0:fa185766e039 | 11 | AnalogIn aA3(PA_4); |
joeata2wh | 0:fa185766e039 | 12 | AnalogIn aA2(PA_3); |
joeata2wh | 0:fa185766e039 | 13 | AnalogIn aA1(PA_1); |
joeata2wh | 0:fa185766e039 | 14 | AnalogIn aA0(PA_0); |
joeata2wh | 0:fa185766e039 | 15 | AnalogIn aB0(PB_0); |
joeata2wh | 0:fa185766e039 | 16 | AnalogIn aB1(PB_1); |
joeata2wh | 0:fa185766e039 | 17 | |
joeata2wh | 0:fa185766e039 | 18 | DigitalOut myled(LED1); |
joeata2wh | 0:fa185766e039 | 19 | const float voltMeterARef = 3.3; |
joeata2wh | 0:fa185766e039 | 20 | |
joeata2wh | 0:fa185766e039 | 21 | float readPrint(AnalogIn ain, char *label) { |
joeata2wh | 0:fa185766e039 | 22 | float tval = ain.read(); |
joeata2wh | 0:fa185766e039 | 23 | float volts = tval * voltMeterARef; |
joeata2wh | 0:fa185766e039 | 24 | float perc = tval * 100.0; |
joeata2wh | 0:fa185766e039 | 25 | unsigned short tvalu16 = ain.read_u16 (); |
joeata2wh | 0:fa185766e039 | 26 | |
joeata2wh | 0:fa185766e039 | 27 | printf("adc %s R=%3.3f V=%3.3f%% U16=%u\r\n",label, tval, volts, tvalu16); |
joeata2wh | 0:fa185766e039 | 28 | |
joeata2wh | 0:fa185766e039 | 29 | return tval; |
joeata2wh | 0:fa185766e039 | 30 | } |
joeata2wh | 0:fa185766e039 | 31 | |
joeata2wh | 0:fa185766e039 | 32 | |
joeata2wh | 0:fa185766e039 | 33 | int main() { |
joeata2wh | 0:fa185766e039 | 34 | |
joeata2wh | 0:fa185766e039 | 35 | while(1) { |
joeata2wh | 0:fa185766e039 | 36 | myled = !myled; // toggle led |
joeata2wh | 0:fa185766e039 | 37 | readPrint(aA7, "PA_7"); |
joeata2wh | 0:fa185766e039 | 38 | readPrint(aA6, "PA_6"); |
joeata2wh | 0:fa185766e039 | 39 | readPrint(aA5, "PA_5"); |
joeata2wh | 0:fa185766e039 | 40 | readPrint(aA4, "PA_4"); |
joeata2wh | 0:fa185766e039 | 41 | readPrint(aA3, "PA_3"); |
joeata2wh | 0:fa185766e039 | 42 | readPrint(aA2, "PA_2"); |
joeata2wh | 0:fa185766e039 | 43 | readPrint(aA1, "PA_1"); |
joeata2wh | 0:fa185766e039 | 44 | readPrint(aA0, "PA_0"); |
joeata2wh | 0:fa185766e039 | 45 | |
joeata2wh | 0:fa185766e039 | 46 | readPrint(aB0, "PB_0"); |
joeata2wh | 0:fa185766e039 | 47 | readPrint(aB1, "PB_1"); |
joeata2wh | 0:fa185766e039 | 48 | printf("\r\n\r\n"); |
joeata2wh | 0:fa185766e039 | 49 | wait(7.0); |
joeata2wh | 0:fa185766e039 | 50 | |
joeata2wh | 0:fa185766e039 | 51 | } |
joeata2wh | 0:fa185766e039 | 52 | } |