Temperature Sensor DHT readings to FRDMk64f

Dependencies:   DHT

Fork of Hexi_Blinky_Example by Hexiwear

Committer:
roborags
Date:
Wed Dec 06 22:52:56 2017 +0000
Revision:
20:6b29e61092b6
Parent:
19:ffd78d964d9f
BLE Mesh Temperature Sensor FRDMK64f

Who changed what in which revision?

UserRevisionLine numberNew contents of line
roborags 14:02ddfa711646 1
dan 0:7dec7e9ac085 2 #include "mbed.h"
roborags 14:02ddfa711646 3 #include "math.h"
roborags 15:67a7cca7ae06 4 #include "DHT.h"
roborags 14:02ddfa711646 5 #include <string>
roborags 14:02ddfa711646 6
roborags 15:67a7cca7ae06 7 Serial FRDM_UART_Debug(USBTX,USBRX);
roborags 20:6b29e61092b6 8 Serial FRDM_Data_Tx(PTC17,PTC16);
roborags 14:02ddfa711646 9
roborags 15:67a7cca7ae06 10
roborags 20:6b29e61092b6 11 DHT sensor(PTC10,DHT11); //DHT Sensor
roborags 18:293c2885af81 12
roborags 15:67a7cca7ae06 13
roborags 15:67a7cca7ae06 14 float Temp_Out = 0;
roborags 15:67a7cca7ae06 15 float Hum_Out = 0;
dan 0:7dec7e9ac085 16
roborags 20:6b29e61092b6 17 void AddEOL(char * s) {
roborags 20:6b29e61092b6 18 char k;
roborags 20:6b29e61092b6 19 k = strlen(s); // Finds position of NULL character
roborags 20:6b29e61092b6 20 s[k] = 0; // Add NULL at the end
roborags 20:6b29e61092b6 21 }
roborags 14:02ddfa711646 22
roborags 14:02ddfa711646 23
roborags 14:02ddfa711646 24 int main()
roborags 14:02ddfa711646 25 {
roborags 14:02ddfa711646 26
roborags 15:67a7cca7ae06 27 FRDM_UART_Debug.baud(115200); // Baud rate used for communicating with Tera-term on PC
roborags 20:6b29e61092b6 28 FRDM_Data_Tx.baud(115200);
roborags 18:293c2885af81 29
roborags 18:293c2885af81 30
roborags 18:293c2885af81 31
roborags 14:02ddfa711646 32 while (1)
roborags 14:02ddfa711646 33 {
roborags 20:6b29e61092b6 34
roborags 20:6b29e61092b6 35 int error = 0;
roborags 20:6b29e61092b6 36 uint16_t Temp = 0;
roborags 20:6b29e61092b6 37 error = sensor.readData();
roborags 20:6b29e61092b6 38 if(error != 0)
roborags 20:6b29e61092b6 39 FRDM_UART_Debug.printf("Error: %d\n", error);
roborags 15:67a7cca7ae06 40
roborags 20:6b29e61092b6 41 Temp_Out = sensor.ReadTemperature(FARENHEIT);
roborags 18:293c2885af81 42
roborags 20:6b29e61092b6 43 Temp = Temp_Out;
roborags 20:6b29e61092b6 44 FRDM_Data_Tx.printf("%d\n",Temp);
roborags 20:6b29e61092b6 45 FRDM_UART_Debug.printf("Temp is %f\r\n",Temp_Out);
roborags 18:293c2885af81 46
roborags 15:67a7cca7ae06 47 wait(5);
roborags 20:6b29e61092b6 48
roborags 15:67a7cca7ae06 49 }
roborags 20:6b29e61092b6 50 }