The code was a port from http://developer.mbed.org/cookbook/RHT03, and there is a little confusion on my part about how to read the data. The script below waits for it to drop low and then waits a specified time before reading again and checking whether it is high or low to get the bit data. The data sheet indicates to wait for low and the decide on bit value depending on length of high value, so it may be a timing issue. Guess i'll have to experiment.
https://www.adafruit.com/datasheets/Dig ... AM2302.pdf
-- Step 2 - Read data stream
-- Data recieved as 40 bits of data, 16 bits for humidity, 16 bits for temperature and 6 bits checksum
-- Need to convert from binary to decimal and divide by 10
-- When highest bit of temperature is '1' it means that temperature is below '0'
for i = 0, 5, 1 do
for j = 0, 8, 1 do
-- Reset count
retryCount = 0;
-- Wait for DHT22 pin to pull low
while gpio.read(pin) == 0 do
-- Check retry count
if retryCount > 75 then
print "DHT22 timeout waiting for data"
end
-- Increment count
retryCount = retryCount + 1
-- Wait 1us
tmr.delay(1)
end
-- Once confirmed wait a specified time '40us+'
tmr.delay(40)
-- Check data bit value
if (gpio.read(pin) == 1) then
-- DHT22 pin is high, bit value is a 1
bitData[i*8+j] = 1
else
-- DHT22 pin is low, bit value is a 0
bitData[i*8+j] = 0
end
-- Wait for 1us and pin is high
count = 0
-- Loop
while gpio.read(pin) == 1 and count < 100 do
tmr.delay(1)
-- Increment
count = count + 1
end
end
end