It transmits 40 bits of data in a burst. I would like to capture that data and print it out to console in a meaningful way.
I am getting confused on how to accomplish this. What built-in library would be best for accomplishing this? Do you have any advice on how to approach this problem?
Then start by looking at the source code of the existing DHT11 library that you don't want to use. Figure out how it works. Then write your own version of the code.
Seems like a strange thing to want to do. But, have at it.
I have reviewed that code but it is confusing to me so I came to this forum to try to reduce the problem to it's base case to help aid in my understanding of the DHT11 library. I think capturing a 40 bit stream would be a simple base case but some people love to run to prepackaged libraries that do everything for you.
I have looked into Serial.available but did not want to bias anyone in their advice to me.
I am just unsure what type of timing is required to make sure that I capture all the bits as it seems like the DHT seems to choose when it wants to send it without much of a preamble or anything.
I thought a preamble would be useful in setting timing on the Microcontroller to match the DHT. I am unsure of how the Microcontroller would naturally set timing to be able to read the burst successfully without the risk of reading the same bit twice.
Ok, I am looking at DHT11.cpp file on github now and it makes a lot more sense this time. I just wanted to give it a solid college try before using the library.
Because the timing is slightly variable, your program needs to determine time differences between rising and falling edges and allow a little slop in what is determined to be a 1 or 0.
Perhaps it was empirically chosen. I'd think it might cause issues dependent of processor speed. The RobTillaart library adjusts the loop counts based on F_CPU. You should check that out and also Adafruit's implementation.
/*
DHT11 Communication Process
Arduino Pull Low at least 18ms, then Arduino Pause 20-40microseconds for DHT's response
*/
void setup() {
Serial.begin(9600);
}
void loop() {
pinMode(2, OUTPUT);
digitalWrite(2, LOW);
delay(18);
pinMode(2, HIGH);
delay(40); // Delay waiting for DHT's response, must wait 20-40us
pinMode(2, INPUT);
while(true)
Serial.println(digitalRead(2));
}
I feel like this should be working but all I am getting is 0's. I understand that 0 or 1 will be represented my length of time at VDD or GND but I am never seeing the signal go high at all.