Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5157

General • Re: Pi Pico W - DHT11 - wrong number of pulses ONLY after 2 reads

$
0
0
You seem to be reading the sensor more often, and perhaps more quickly, than you want to admit.

During setup -

Code:

pin = Pin(0, Pin.OUT, Pin.PULL_DOWN)sensor = DHT11(pin)t  = sensor.temperatureh = sensor.humidityprint("Temperature: {}".format(sensor.temperature))print("Humidity: {}".format(sensor.humidity))
That's four - 4 - accesses to the sensor with no time delay anywhere.


Similarly, within the connection code -

Code:

else:            #request = str(request)            pin = Pin(0, Pin.OUT, Pin.PULL_DOWN)            sensor = DHT11(pin)            #time.sleep(3)            t  = sensor.temperature            h = sensor.humidity            print("Temperature: {}".format(sensor.temperature))            print("Humidity: {}".format(sensor.humidity))            response = html % (t, h)            print(t, h)
Again, four accesses to the sensor with no delay.


There is a comment in the library code -

Code:

def measure(self):        current_ticks = utime.ticks_us()        if utime.ticks_diff(current_ticks, self._last_measure) < MIN_INTERVAL_US and (            self._temperature > -1 or self._humidity > -1        ):            # Less than a second since last read, which is too soon according            # to the datasheet            return



I don't have such a sensor to test, but I've got 2 related suggestions.

For troubleshooting purposes forget the network handling code. Concentrate on getting reliable sensor data first.

Write a loop that reads the sensor data 10, 50, 100 times. Experiment first with 2 second delays between each access to the sensor, then increase or decrease it until you find the 'sweet spot' for reliability.


Then retro-fit what you have learnt into the network-aware version of your code.

Statistics: Posted by B.Goode — Tue Jan 30, 2024 5:52 pm



Viewing all articles
Browse latest Browse all 5157

Trending Articles