When temperature is below 0C, temperature value for dht.read is -3276.7. Moisture information seems to be OK. Setup has been running fine since June, but now when temperature outside is below 0C, problem arised.
Problem is not new: https://forum.arduino.cc/index.php?topic=129531.0.
Giving a try for this https://github.com/micropython/micropyt ... dht/dht.py
Code: Select all
def temperature(self):
t = ((self.buf[2] & 0x7F) << 8 | self.buf[3]) * 0.1
if self.buf[2] & 0x80:
t = -t
return
-> Humidity 87.2
- >Temperature = blank
bytearray(b'\x03h\xff\xfcf')
If I understand this correctly, first byte shall bring 3 x 256 (MSB), then add FF (LSB) and last two are temperature ([2] and [3]. Seems that 3 is missing. Perhaps first bytecode 03 + h means that because second bytecode is overflow, h (is not hexadecimal) is generated?
In other hand, I do not understand why measure(): passes this (unless if last byte is missing):
Code: Select all
def measure(self):
buf = self.buf
dht_readinto(self.pin, buf)
if (buf[0] + buf[1] + buf[2] + buf[3]) & 0xFF != buf[4]:
raise Exception("checksum error")
Code: Select all
>>> from machine import Pin
>>> from esp import dht_readinto
>>> buffer = bytearray(5)
>>> dht_readinto(Pin(4), buffer)
>>> buffer
bytearray(b'\x03k\xff\xfdj')
>>> dht_readinto(Pin(4), buffer)
>>> buffer
bytearray(b'\x03r\xff\xfdq')
Perhaps someone understand better what is wrong there. Meanwhile I made change to code:
Code: Select all
if tempin < -40:
ttemp = str(tempin).split('.')
msb = int(ttemp[0]) * -1
lsb = ttemp[1]
belowzero = str(3276 - msb) + "." + lsb
if float(belowzero) > 0.0:
tempin = float(belowzero) * -1
else:
tempin = float(belowzero)
dht.c in micropython-master/drivers/dht seems to read 40 bits as it should, so, this should be not problem after all:
Code: Select all
// time 40 pulses for data (either 26us or 70us)
uint8_t *buf = bufinfo.buf;
for (int i = 0; i < 40; ++i) {
ticks = machine_time_pulse_us(pin, 1, 100);
if ((mp_int_t)ticks < 0) {
goto timeout;
}
buf[i / 8] = (buf[i / 8] << 1) | (ticks > 48);
}