Digital IO mismatch

grovepi
pending

#1

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")


#2

Hi @skybird,

The GrovePi has a couple of bugs that we need to address as soon as possible, but we’re not there yet - we’re doing things at our max capacity one at a time.

I suspect there’s a timing issue on the GrovePi, so first thing would be to add a delay between those calls. Second of all, I would start testing it manually, like call each function of your given script and see if you get bad responses. If you’re getting good ones, then there’s a timing issue.

Also, incrementally adding sensors to your while loop is a good practice as that allows you to see if the system breaks and if so, where.

Also, if I remember correctly, the DHT sensor could be the problem here - the Atmega we’re using on the GrovePi is pretty limited to what it can do, so for this sensor, we had to cut down the functionalities of it to make it work. I’d suggest you remove the DHT out of the equation and see if it starts working.

Thank you!


#3

Hi RobertLucian

Thank you for your answer.

Without the DHT Sensor, I was able to move the “outputs” to the end of my program, and everything work well.

After several tests with the DHT-Sensor, I decided to move it to the start of the program and was able to decrease the nesessary sleep Time to 0.6 Sec.

On my RaspberryPi, this seems to be the minimum time, that digitalRead/Wirite work properly.

Now, since the IOs do what they should, i can start to write my program.

I enclose my little testprogram for others fighting with the DHT-Sensor.

Kind regards

Kony

WP_multi_digital_read_led_blink.py (2.85 KB)


#4

Hi @skybird,

I’m really glad to see it worked for you. This is great as we’re killing 2 birds with one stone - you’re feedback will help us run tests / fix the issues when the time comes and at the same time you got it to run.

For now, I’ll leave this thread open, should you have any more questions.

Thank you!