''' flash: adafruit-circuitpython-raspberry_pi_pico-en_US-7.0.0.uf2 from adafruit-circuitpython-bundle-7.x-mpy-20211011.zip copy ( to /lib/) : adafruit_display_text adafruit_bus_device adafruit_register adafruit_ssd1306.mpy adafruit_framebuf.mpy from https://github.com/adafruit/Adafruit_CircuitPython_framebuf/blob/main/examples/font5x8.bin copy font5x8.bin to / near code.py adafruit_dht.mpy ''' import time import board print("________ Hallo World") print(dir(board)) import digitalio import supervisor import microcontroller import adafruit_dht from analogio import AnalogIn analog_in0 = AnalogIn(board.A0) # GP26 pin 31 analog_in1 = AnalogIn(board.A1) # GP27 pin 32 analog_in2 = AnalogIn(board.A2) # GP28 pin 34 print("________ analogio lib loaded / A0 GP26 pin 31 / A1 GP27 pin 32 / A2 GP28 pin 34") def get_volt(pin): return (pin.value * 3.3) / 65536 def get_pct(pin): return (pin.value * 100.0) / 65536 print("________ switch PICO on board LED") myled = digitalio.DigitalInOut(board.LED) myled.direction = digitalio.Direction.OUTPUT myled.value = True time.sleep(2) myled.value = False time.sleep(2) myled.value = True #time.sleep(2) print("________ dht-library loaded") dhtDevice = adafruit_dht.DHT22(board.GP7) print("________ data at GP7 pin 10 ") print("________ try OLED") import adafruit_ssd1306 import busio as io # GP1 PICO pin2 I2C0 SCL // GP0 PICO pin1 I2C0 SDA # i2c = io.I2C(scl=board.GP1,sda=board.GP0) # this works from Circuit Python, but want change to DEFAULT PINS! # GP5 PICO pin7 I2C0 SCL // GP4 PICO pin6 I2C0 SDA i2c = io.I2C(scl=board.GP5,sda=board.GP4) #RuntimeError: No pull up found on SDA or SCL; check your wiring # use 10k to 3v3 each # ,addr=0x3d #ValueError: No I2C device at address: 3d #( for 128*64 OLED? ) oled = adafruit_ssd1306.SSD1306_I2C(128,32,i2c,addr=0x3c ) oled.fill(1) #oled.show #time.sleep(2) #oled.pixel(10,0,0) #oled.pixel(10,1,0) #oled.pixel(10,2,0) #oled.pixel(10,3,0) #oled.pixel(10,4,0) # now i see that black line oled.show() # got first time the OLED to lit up ( and stay as long USB power ) print("________ see OLED white screen") time.sleep(5) oled.fill(0) #from adafruit_display_text import label oled.text('Line1: PICO OLED',0,0,1) oled.text('Line2: 0123456789',0,11,1) oled.text('Line3: qwertyuiop[]',0,22,1) print("________ see OLED black screen with white 3 lines text") oled.show() time.sleep(3) print("________ so far so good") # make a DHT sensor function valid = 0 invalid = 0 noskip = False #______________________________ we assume we come from a one sec flag but for DHT need a two sec sampling diagprint = True #____________________________ as parameter for function details def get_dht(diagprint): global valid global invalid global dhtT global dhtH global noskip #_________________________________________ local filter tuning fA = 0.8 #________________________________ use old value fB = 1.0-fA #_____________________________ sum must be 1.0 if ( noskip ): try: newT = dhtDevice.temperature newH = dhtDevice.humidity valid += 1 if (diagprint): print("valid: {}, newT: {}, newH: {}".format(valid, newT,newH) ) dhtT = dhtT*fA + newT*fB dhtH = dhtH*fA + newH*fB noskip = False except: invalid += 1 if (diagprint): print("invalid: {}".format(invalid) ) else: # wait one more sec loop noskip = True #_____________________________________________________ globals loop = True inval = 'p' lastsec = 0 inow = 0 measure = False dhtT =-1.0 dhtH =-1.0 #___________________________________________ MAIN print("________ start main measuring loop") while loop: if ( measure ): measure = False #___________________ reset until main loop find new second get_dht(diagprint) #________________ every 2 secs only and filtered to dhtT and dhtH, with (diagprint) print("DHT22: Temperature:{0:5.1f} [C], Humidity:{1:5.1f} [%]".format( dhtT, dhtH ) ) oled.fill(0) oled.text('DHT22 test, filtered',0,0,1) oled.text('T:{0:5.1f}C H:{1:5.1f}%'.format(dhtT,dhtH),0,11,1) oled.text('later',0,22,1) oled.show() inow = time.time() #____________________ sec after 1.1.1970 if ( inow > lastsec ): lastsec = inow measure = True #____________________ seconds flag #___________________________________________ END