WarwickHW
WarwickHW

Reputation: 1

Raspberry PicoW + DHT11 error when reading sensor <bound_method>

I have a Pico running ‘pimoroni-picow-v1.19.1-micropython’ with a DHT11 connected. When running main.py I always get an <bound_method> output instead of the reading.

DHT11 is connected as follows:

DOUT - GP28 GND - GND (32) VCC - 3V3 (30)

Installed dht.py from here

Then I run this as main.py:

from machine import Pin, I2C
import utime as time
from dht import DHT11, InvalidChecksum

while True:
    time.sleep(5)
    pin = Pin(28, Pin.OUT, Pin.PULL_DOWN)
    sensor = DHT11(pin)
    t  = (sensor.temperature)
    h = (sensor.humidity)
    print("Temperature: {}".format(sensor.temperature))
    print("Humidity: {}".format(sensor.humidity))

My output is always:

Temperature: <bound_method>
Humidity: <bound_method>

I've tried multiple pins and tried code from other DHT11 repos, all seem to give the same output after sensor.temperature is called.

I've googled “<bound_method>”, and very few results, none that indicate what I might be doing wrong. Any ideas?

Upvotes: 0

Views: 1012

Answers (1)

Simon
Simon

Reputation: 59

Just tested this and it works, a subtle difference, but not related to the Pin used..

You don't need to install any external modules as there is a built in dht module

Am not sure of the correct terminology but where you have used :

sensor.temperature
sensor.humidity

it should be:

sensor.temperature()
sensor.humidity()

below is a working example

from machine import Pin
import time
import dht

sensor = dht.DHT11(Pin(4))

while True:
    sensor.measure()
    print("Temperature: {}°C   Humidity: {}% ".format(sensor.temperature(), sensor.humidity()))
    time.sleep(2)

Upvotes: 1

Related Questions