DHT22 sensor reading issues. #11344
Replies: 1 comment 5 replies
-
I now believe my problem relates to namespace and variable resolving by the interpreter. I still don't have a fix but I think I need to re-visit the basics of Python. Coming from a C environment I just can seem to get my head wrapped around how from one py to another it the globals just don't behave like I expect. |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I can read 2 DHT sensors using a PIO based low level driver I forked from danjperron/PicoDHT22. When calling the driver from a single .py named RdTpUms.py (see code below) I can read both sensors in a forever loop. My issues occur when I try calling the same function from another main.py. When I do so the first reading works but all subsequent fail. I therefore believe its interaction related to using the PIO block that is being used for the low level driver I cloned from Github. Both soft boot or restart from Thonny do not resolve the issue. Only a power down and re-power, get the code to work once only again.
I am obvious very green at this new environment but for the sake of keeping my babies warm in my cold frame I will have to bow down and re-connect the hardware to my old MicroChip Pic16 C based controller for the coming growing season.
One last note the DHT's are being operated via a FET based level converter. I also have a logic analyzer connected to one of the sensors and sure enough once the failure occurs there is no further activity on any sensor line.
Unable to attach file as I always get a file not supported error
below is a raw cut and paste from Thonny!
/// start of Rd_TpUms.txt
from machine import Pin
import PicoDht
from PicoDht import DHT22
import utime
Indr = Pin(2,Pin.IN,Pin.PULL_UP) # set io pin for inside frame
Otdr = Pin(3,Pin.IN,Pin.PULL_UP) # set io pin for outdoor sensor
Dht_Frm = None # one global DHT22 id name
Dht_Out = None
initialise io pin to sensor location
def init_snsrs():
global Dht_Frm,Dht_Out # re-use same global
global Indr,Otdr
function read sensor @ location
def read_snsrs(loctn): # loctn 0->frame 1->outdor
global Dht_Frm,Dht_Out # re-use same global
test code works forever if py is run on its own
if name == "main":
cnt = 0
init_snsrs() # setup sensor driver
#umid = None
while True:
print('Cnt',cnt,'\r')
for i in range(2):
temp,umid=read_snsrs(i)
utime.sleep_ms(500)
print(i,temp,umid)
cnt+=1
utime.sleep_ms(500)
/// end of Rd_TpUms.txt
main.py code from which the issues arise
print("ColdFrame running...")
Rd_TpUms.init_snsrs() # initialize both frame & outdoor sensors
gc.enable() # get the garbage collector happening
while(True):
utime.sleep_ms(500) # pause 1/2 sec
if Alt_flg is True: # alternate
Upd_tmp_umd(0) # frame temp/umid
Alt_flg = False
else:
Upd_tmp_umd(1) # outdoor temp/umid
Alt_flg = True
utime.sleep_ms(500)
utime.sleep(2)
Thanks for caring...Denis
Beta Was this translation helpful? Give feedback.
All reactions