On Sat, 26 Mar 2016 04:46:10 -0700 (PDT), Sumit Bhut
> declaimed the following:
>I'm compilited this code for interface BBB with DHT11(temperature-humidity
>sensor) this code is compiled and run successfully but OUTPUT
>*0'c temperature - 0% humidity ....Plz *, find error this code...
As I recall, you posted this not quite a week ago, and I provided some
suggestions at that time. Have you even looked at them?
I'll admit that they aren't the most specific -- I had to download the
spec sheet for the device and looked at an Arduino library for reading the
My strongest suggestion is to change your algorithm -- drop that whole
"laststate" toggle and the modulo operation. Per the spec sheet, the return
data starts each bit with a short LOW, then produces a HIGH whose duration
determines the difference between a 0 and 1 bit.
So reading a bit should consist of (this presumes you enter the
bit-read when the signal is in the LOW state):
loop until the signal goes HIGH;
loop until the signal goes LOW -- counting loop cycles;
if count is > (mid-point between 0-count and 1-count)
bit is a 1
bit is a 0
shift bit into received data byte
repeat for additional bits
Use similar logic to detect the start-of-response code...
Basically, the way the check works is that you expect to be in the LOW
at the start, and are looking for the transition to HIGH as the start of
data; you process that data on the next transition to LOW.
Or you get ambitious and port the Arduino library -- since it includes
TIMEOUT conditions should it take too long to detect a response (the simple
code I illustrate above will loop forever is the signal never transitions).
My other suggestion is to clean-up your code. You are passing pin
number to functions that never use it as you have hard-coded the path in
them, etc. Either remove the pin number passing completely, and hard-code
all the access functions; or pass the pin number to all the functions and
use it in the function to create the path.
Wulfraed Dennis Lee Bieber AF6VN