I measured the time of "digitalRead( 2 , INPUT_FAST );" , that is just about 4us.
And I got the DHT11 data bit sucessfully, but need to have some modification below.
If you pull high the IO pin(digitalWrite(pin, HIGH);), the DHT11 will begin send data. And the pinMode() caused about 2XXXus. So we will miss the data.
I mark the"digitalWrite(pin, HIGH);", and the DHT11 will send data after 40ms. We can get the all of data.
But if using digitalRead(pin) extensively, the system will delay in 50us randomly. So will miss the bit.
int dht11::read(int pin) { // BUFFER TO RECEIVE uint8_t bits[5]; uint8_t cnt = 7; uint8_t idx = 0; int w=0,y=0; unsigned long long MaxLoop = 4000; unsigned long currentpulse,lastpulse,Lowpulse,Hipulse, data[MaxLoop],i,bitdata[41]; // EMPTY BUFFER for (int x=0; x< 5; x++) bits[x] = 0; for (int x=0; x< MaxLoop; x++) data[x] = 0; for (int x=0; x< 41; x++) bitdata[x] = 0; // REQUEST SAMPLE pinMode(pin, OUTPUT_FAST); digitalWrite(pin, LOW); delay(18); /////digitalWrite(pin, HIGH); pinMode(pin, INPUT_FAST); i=0; while(i<MaxLoop) { data[i] = digitalRead(pin); i++; } i=0; LoopCount = 0; Lowpulse = 0; Hipulse = 0; lastpulse = 1; //default signal while(i<MaxLoop) { currentpulse = data[i]; if(data[i] == LOW) Lowpulse++; else Hipulse++; if(currentpulse != lastpulse) { if(Lowpulse>1) { } if(Hipulse>1 ) { bitdata[w]=Hipulse; w++; } Lowpulse = 0; Hipulse = 0; }//if(currentpulse != lastpulse) lastpulse = currentpulse; i++; }//while(i<MaxLoop) for (w=0; w<41; w++) { if(w>0) { if ( (bitdata[w] > 25) && (bitdata[w] < 70)) { bits[idx] |= (1 << cnt); } if (cnt == 0) // next byte? { cnt = 7; // restart at MSB idx++; // next byte! } else cnt--; } } // WRITE TO RIGHT VARS // as bits[1] and bits[3] are allways zero they are omitted in formulas. humidity = bits[0]; temperature = bits[2]; uint8_t sum = bits[0] + bits[2]; if (bits[4] != sum) return DHTLIB_ERROR_CHECKSUM; return DHTLIB_OK; }