Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of DHT11_with_Nucleo by
Revision 5:76a9332af64c, committed 2015-01-06
- Comitter:
- kaliczp
- Date:
- Tue Jan 06 00:54:41 2015 +0000
- Parent:
- 4:62b680fac6ed
- Child:
- 6:8027edc2b69f
- Child:
- 7:5b0793a2b391
- Commit message:
- Send the measured data bits of DHT11 through UART!
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Jan 06 00:48:44 2015 +0000 +++ b/main.cpp Tue Jan 06 00:54:41 2015 +0000 @@ -5,6 +5,9 @@ DigitalInOut data_pin(A0); // Activate digital in Serial pc(SERIAL_TX, SERIAL_RX); // Initialize UART connection // Use a terminal program (eg. TeraTerm). +Timer tmr; //initialize timer +char adat[40]; // Array for data +int i; // Function to initialize DHT11 void dht_read(void) { @@ -15,14 +18,40 @@ // After high and release the pin switch input mode data_pin = 1; data_pin.input(); + // Wait until the end of 80 us low + while(!data_pin.read()) {} + // Wait until end of 80 us high + while(data_pin.read()) {} + // 40 bit, 40 read out cycle + for(i=0; i<40; i++) { + tmr.stop(); // Stop timer if runs + tmr.reset(); // Reset timer + // Wait until pin + while(!data_pin.read()) {} + tmr.start(); + while(data_pin.read()) {} + // If DHT11 HIGH longer than 40 micro seconds (hopefully 70 us) + if(tmr.read_us() > 40) { + // bit is 1 + adat[i] = 1; + } + } } int main() { pc.printf("Read the DHT11 temperature and humidity sensor!\n"); //Welcome message while(1) { if (mybutton == 0) { // Button is pressed + // Reset character array + for(i=0; i < 40; i++){ + adat[i] = 0; + } myled = 1; // LED is ON dht_read(); // Call the function + // Send result through UART result + for(i=0; i < 40; i++){ + pc.printf("%d",adat[i]); + } wait_ms(200); // Wait 0.2 sec till continue. } else { myled = 0; // LED is OFF