danjperron / PicoDHT22

Micropython DHT22 class using PIO
MIT License
49 stars 12 forks source link

OSError: [Errno 12] ENOMEM on Pico W #6

Open magnussommarsjo opened 1 year ago

magnussommarsjo commented 1 year ago

When using new Pico W together with the DHT22 sensor I get a reading the first time I run the code. The second time and all the following I get the ENOMEM error. I need to physically disconnect and reconbnect the usb to be able to get a reading once more.

Code I run:

from DHT22 import DHT22
from machine import Pin

data_pin = Pin(2, Pin.IN, Pin.PULL_UP)
sensor = DHT22(data_pin)
print(sensor.read())

And the output for two runs:

MicroPython v1.19.1 on 2022-07-05; Raspberry Pi Pico W with RP2040

Type "help()" for more information.
>>> %Run -c $EDITOR_CONTENT
(27.2, 59.8)
>>> %Run -c $EDITOR_CONTENT
Traceback (most recent call last):
  File "<stdin>", line 7, in <module>
  File "DHT22.py", line 156, in read
  File "DHT22.py", line 141, in read_array
OSError: [Errno 12] ENOMEM
>>> 
danjperron commented 1 year ago

Hi Magnus,

I can't verify right now.

Some thing to check.

1- run exactly my code and check. same Pin. 2- Change Pin. 3- Is the PicoW run at the same speed?

B.T.W. I will order another picow since the one I got is buzy reading data on my garden.

magnussommarsjo commented 1 year ago

Hi Daniel,

I moved the data pin to GPIO15 and ran snippets of your dht22Test.py. (I had to remove all related to the lcd)

Code that I ran

from machine import Pin
from DHT22 import DHT22
import time

# day of the week in French
jour = ["Lun", "Mar", "Mer", "Jeu", "Ven", "Sam", "Dim"]

# init DHT22 on Pin 15
dht22 = DHT22(Pin(15,Pin.IN,Pin.PULL_UP))
while True:
    T, H = dht22.read()
    now = time.localtime()
    print("{} {:02}  {:02d}:{:02d}:{:02d}".format(jour[now[6]],
                                                      now[2],now[3],
                                                      now[4],now[5]))

    if T is None:
        print("T=----\xdfC H=----}%")
    else:
        print("T={:3.1f}\xdfC H={:3.1f}%".format(T,H))
    time.sleep_ms(500)

Output

MicroPython v1.19.1 on 2022-07-05; Raspberry Pi Pico W with RP2040

Type "help()" for more information.
>>> %Run -c $EDITOR_CONTENT
Dim 31  14:07:30
T=27.6ßC H=49.7%
Dim 31  14:07:30
T=27.5ßC H=50.8%
Dim 31  14:07:31
T=27.5ßC H=50.8%
Dim 31  14:07:32
T=27.6ßC H=50.9%
Dim 31  14:07:32
T=27.6ßC H=50.8%
Dim 31  14:07:33
T=27.5ßC H=50.7%
Dim 31  14:07:34
T=27.5ßC H=50.6%
Dim 31  14:07:35
T=27.6ßC H=50.6%
Dim 31  14:07:35
T=27.6ßC H=50.5%
Dim 31  14:07:36
T=27.6ßC H=50.5%
Dim 31  14:07:37
T=27.6ßC H=50.5%
Dim 31  14:07:37
T=27.5ßC H=50.4%
Dim 31  14:07:38
T=27.5ßC H=50.4%
Dim 31  14:07:39
T=27.5ßC H=50.4%
Dim 31  14:07:40
T=27.6ßC H=50.4%
Dim 31  14:07:40
T=27.5ßC H=50.4%
Dim 31  14:07:41
T=27.5ßC H=50.3%
Dim 31  14:07:42
T=27.5ßC H=50.3%

────────────────────────────────────────────
MicroPython v1.19.1 on 2022-07-05; Raspberry Pi Pico W with RP2040

Type "help()" for more information.
>>> %Run -c $EDITOR_CONTENT
Traceback (most recent call last):
  File "<stdin>", line 11, in <module>
  File "DHT22.py", line 156, in read
  File "DHT22.py", line 141, in read_array
OSError: [Errno 12] ENOMEM
>>> %Run -c $EDITOR_CONTENT
Traceback (most recent call last):
  File "<stdin>", line 11, in <module>
  File "DHT22.py", line 156, in read
  File "DHT22.py", line 141, in read_array
OSError: [Errno 12] ENOMEM
>>> 

Odd thing here is that I can run the readings consistently in a while loop the first time I run the script. But when I stop and restart the script I get the ENOMEM errors.

Have tried with both PIN 2 and PIN 15 but with same result.

Regarding the speed of PicoW I not certain what you mean. I'm new to microcontrollers and I have not the "regular" Pico to compare with.

Just to be complete I also attach how I have connected everything. dht

DannnB commented 1 year ago

Hi, I'm getting the same issue! The same setup pretty much as magnussommarsjo. One run is fine but no matter what you try again it just files with the same error:

Traceback (most recent call last):
  File "<stdin>", line 8, in <module>
  File "dht22.py", line 150, in read
  File "dht22.py", line 135, in read_array
OSError: [Errno 12] ENOMEM

Quite possible a state machine issue but I;ve never dealt with sm before

#start state machine
self.sm.init(DHT22_PIO,freq=500000,
             set_base=self.dataPin,
             in_base=self.dataPin,
             jmp_pin=self.dataPin)

I know this is an old-ish repo but if you have any ideas how to fix this issue it will help a lot as this is the one of the top DHT22/11 scripts out there.

danjperron commented 1 year ago

Wow a lot of people always do the same error. python is case sensitive! it's not dht22.py but DHT22.py

danjperron commented 1 year ago

magnussommarsjo, about the script error when you stop the script. It is something you change in your script because my original script running the original DHT22.py works fine. I know that they were a bug on some micropython release. Maybe try the most recent micropython uf2. Also check just my original DHT22.py script if it works then it is something you change. Be carefull if you are using another function which uses the PIO.

efarias-iado commented 1 year ago

Sorry to bother, I had this problem running con Pi Pico W. I fixed it by adding

rp2.PIO(0).remove_program() after this sentence: self.sm= rp2.StateMachine(self.smID)

The bug is described herehttps://forums.raspberrypi.com/viewtopic.php?t=338158

I hope it would be useful for someone.