0

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?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
WarwickHW
  • 1
  • 1

1 Answers1

1

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)
Simon
  • 59
  • 6
  • Thanks Simon and apologies for the delay in replying. I tried that approach and although this improved the situation (i.e. the error went away), the reading was consistently 0.00. I've also tried changing the PIN requests etc. and no joy. Gave up, didn't i? – WarwickHW Nov 15 '22 at 16:59
  • did you get this resolved ? I can only think if not your module is goosed. – Simon Dec 06 '22 at 10:07