A DHT11 sensor is connected to the STM32L476VGT Discovery Board to monitor temperature and humidity.
Fork of DHT11-HelloWorld by
Diff: main.cpp
- Revision:
- 2:15a255321242
- Parent:
- 1:aedc2645d841
--- a/main.cpp Fri Apr 21 07:02:29 2017 +0000 +++ b/main.cpp Sat Apr 14 15:56:03 2018 +0000 @@ -1,15 +1,24 @@ #include "mbed.h" #include "DHT.h" -#define DHT_DATA_PIN D4 + +// STM32L476VGT DISCOVERY BOARD +// DHT11 SENSOR RUNNING FROM 3V3 SUPPLY +// PULL DOWN WITH 10K RESISTOR +// DATA VIA THE PIN PA_0 +// COM PORT 4 AT 9600 BAUD + + +#define DHT_DATA_PIN PA_0 // sets pin PA_0 as data input -DHT sensor(DHT_DATA_PIN, DHT11); //DHT(PinName pin, eType DHTtype) +DHT sensor(DHT_DATA_PIN, DHT11); + //DHT(PinName pin, eType DHTtype) int main() { int error = 0; - float h = 0.0f, c = 0.0f, f = 0.0f, k = 0.0f, dp = 0.0f, dpf = 0.0f; - + float h = 0.0f, c = 0.0f, f = 0.0f, k = 0.0f, dp = 0.0f, dpf = 0.0f; + while(1) { wait(2.0f); //wait 2 second @@ -22,12 +31,14 @@ h = sensor.ReadHumidity(); dp = sensor.CalcdewPoint(c, h); dpf = sensor.CalcdewPointFast(c, h); - printf("Temperature in Kelvin: %4.2f, Celcius: %4.2f, Farenheit %4.2f\n", k, c, f); - printf("Humidity is %4.2f, Dewpoint: %4.2f, Dewpoint fast: %4.2f\n", h, dp, dpf); + printf("F: %4.2f, \r\n", f); //prints temp in farenheit to Real Term + // printf("H: %4.2f, \r\n", h); //prints humidity to Real Term + printf(" \r\n "); //acts as empty line to space readings in Real Term + printf(" \r\n "); //acts as empty line to space readings in Real Term } else //case: error { - printf("Error: %d\n", error); + printf("Error: %d\r\n", error); //prints error to Real Term when "if" criteria isn't satisfied } } } \ No newline at end of file