AttributeError: 'module' object has no attribute 'DHT11'

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
DiegoArnaiz74
Posts: 1
Joined: Tue Dec 01, 2020 1:35 am

AttributeError: 'module' object has no attribute 'DHT11'

Post by DiegoArnaiz74 » Tue Dec 01, 2020 1:48 am

Hello everyone! I need help! I have an issue with a DHT11 and a generic 39pin ESP32 dev board.

My program returns only sometimes, this error: "AttributeError: 'module' object has no attribute 'DHT11'". But it works most of the times.

I'm reading temperature and humidity, send it to a 16x2 display and uploading the data to AskSensors

This is a part of the code, and my project so far it's here (I'm just testing):
https://github.com/darnaiz/WeatherStationDev1

Code: Select all

from machine import I2C
from machine import Pin
from machine import RTC
from time import sleep
from time import sleep_ms
from time import ticks_ms
from esp8266_i2c_lcd import I2cLcd
import network
import dht
import urequests
import WorldClock

p0 = Pin(4, Pin.OUT)
p1 = Pin(17, Pin.OUT)
d = dht.DHT11(Pin(16))
i2c = I2C(scl=Pin(22), sda=Pin(21), freq=400000)
lcd = I2cLcd(i2c, 0x27, 2, 16)
lcd.backlight_off()
lcd.clear()
(etx. etc)

I'll thanks a lot your help :)

User avatar
karfas
Posts: 193
Joined: Sat Jan 16, 2021 12:53 pm
Location: Vienna, Austria

Re: AttributeError: 'module' object has no attribute 'DHT11'

Post by karfas » Tue Apr 27, 2021 9:52 pm

Sounds like a memory (fragmentation ?) problem for me (especially when it works most of the time).

Does this happen immediate after reset or when started multiple times from the REPL?
Try to spread a few gc.collect() in your code or use the other gc.* functions to analyze the memory used.

Also, look into the esp8266_i2c_lcd driver - maybe this does something incompatible with the ESP32 I2C bus.

Regards,
Thomas
A few hours of debugging might save you from minutes of reading the documentation! :D
My repositories: https://github.com/karfas

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: AttributeError: 'module' object has no attribute 'DHT11'

Post by kevinkk525 » Wed Apr 28, 2021 4:55 am

I agree. Especially with my slightly unreliable Esp32 psram board I experienced this error often.
Some attributes might just vanish after a few hours of operation. Only a reset helps. Looks like memory errors.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

Post Reply