Hello
I have a question about IO processing with GrovePI.
I have extended the multi_digital_read_led_blink.py program to include a DHT sensor on D8, as well as the RBG display on the I2C bus.
Now I want to read the inputs at the beginning of the program and set the outputs at the end of the program.
Unfortunately, only the port reacts to D6. The outputs at D4 and D5 show no reaction.
But if I put the outputs directly after the inputs, then all three work correctly.
Is there a logical explanation for this?
What do I have to consider when connecting IOs.?
Thank you for any support.
#!/usr/bin/env python
#
import time
import grovepi
import grove_rgb_lcd
import math
import datetime
# Connect the Grove Button to digital port D2
WPr_Port2 = 2
WPr_Port3 = 3
# Connect the Grove LED to digital port D4,D5,D6
Lein_Port4 = 4 # Lueftung Ein
WPe_Port5 = 5 # WaermePumpe Enabled
WWd_Port6 = 6 # WarmWasser Disabled
# connect the DHt sensor to port 8
dht_port8 = 8
dht_type = 1 # use 0 for the blue-colored sensor and 1 for the white-colored sensor
grovepi.pinMode(WPr_Port2,"INPUT")
grovepi.pinMode(WPr_Port3,"INPUT")
grovepi.pinMode(Lein_Port4,"OUTPUT")
grovepi.pinMode(WPe_Port5,"OUTPUT")
grovepi.pinMode(WWd_Port6,"OUTPUT")
time.sleep(1)
grove_rgb_lcd.setRGB(0,0,255) # Blau
grove_rgb_lcd.setText("Starting")
iTimePause = 15
ticks_Off=time.time() # Zeit, wenn die WP ausgeschaltet wurde
grovepi.digitalWrite(WPe_Port5,0) # WarmePume Enable (0=freigegeben)
grovepi.digitalWrite(WWd_Port6,1) # WarmWasser Disdable (1=gesperrt)
time.sleep(1)
WPr = False # WaermePume running
WPr_mem = False # WaermePume running Speicher (letzer Berechnungszyklus
WPe = False # WaermePume Enabled / Freigegeben
WWd = True # WarmWasser Disnabled / Gesperrt
bWPTime_ok = True # WP darf laufen
temp = 20.0
temp_m = 20.0
hum = 40.0
hum_m = 40.0
while True:
try:
# Digital Inputs
WPr=grovepi.digitalRead(WPr_Port2)
# d3=grovepi.digitalRead(WPr_Port3)
# all Digital Outputs working well
## grovepi.digitalWrite(Lein_Port4,WPr)
## grovepi.digitalWrite(WPe_Port5,WPr)
## grovepi.digitalWrite(WWd_Port6,not WPr)
# DHT Sensor
[ temp,hum ] = grovepi.dht(dht_port8,dht_type)
# no Calculation while Sensor Error
if ((math.isnan(hum) is False) and (hum>20)):
hum_m += 0.01 * (1.35 * hum - hum_m)
if ((math.isnan(temp) is False) and (temp>10)):
temp_m += 0.01 * (temp - temp_m)
# Pause
iPause = iTimePause - int(time.time()-ticks_Off)
if (iPause<0):
# Pause beendet
bPause = False
else:
# Pause aktiv
bPause = True
# Digital Outputs Port4 and Port 5 NOT working at this place
grovepi.digitalWrite(Lein_Port4,WPr)
grovepi.digitalWrite(WPe_Port5,WPr)
grovepi.digitalWrite(WWd_Port6,not WPr)
# -> string
t = str(temp)
h = str(hum)
sP = str(iPause)
sRGB = [125,125,125] # Grau: Bereit
sLCD = "T:"+t+" RF:"+h +"\nP:"+sP
grove_rgb_lcd.setRGB(sRGB[0],sRGB[1],sRGB[2])
grove_rgb_lcd.setText_norefresh(sLCD)
print ("WPr",WPr,temp,hum,sP)
time.sleep(0.25)
except IOError: # Print "Error" if communication error encountered
print ("Error")