Iam trying to create the error detection application for my battery charger prototype using Rpi.GPIO. I successfully created the add event detect for multiple GPIO pins (totally 8 pins for each error).
My doubt is regarding the assignment of priority for each error. I try to run the call back function depends on the priority list below but unsuccessful. If i give emergency stop signal after earth missing it is not detected. Emergency stop signal gets detected only after earth missing signal. I listed the error according to the priority below.
- Emergency stop
- Phase reversal
- Earth Leakage
- Earth Missing
- Short circuit
- power failure
- Input over voltage
- Input under voltage
I attached the example code below
import RPi.GPIO as GPIO
from time import sleep
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD) # We are accessing GPIOs according to their physical location
GPIO.setup(37, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(35, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(33, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(31, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(29, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(40, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(38, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(36, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def errorDetection(channel):
if(channel == 37):
while GPIO.input(37) == 0:
print('Emergency stop occured')
elif(channel == 35):
while GPIO.input(35) == 0:
print('Phase reverse occured')
elif(channel == 33):
while GPIO.input(33) == 0:
print('Earth leakage occured')
elif(channel == 31):
while GPIO.input(31) == 0:
print('Earth Missing occured')
elif(channel == 29):
while GPIO.input(29) == 0:
print('Short circuit occured')
elif(channel == 40):
while GPIO.input(40) == 0:
print('Power failure occured')
elif(channel == 38):
while GPIO.input(38) == 0:
print('Input over voltage occured')
elif(channel == 36):
while GPIO.input(36) == 0:
print('Input under voltage occured')
GPIO.add_event_detect(37, GPIO.FALLING, errorDetection, bouncetime=2000)
GPIO.add_event_detect(35, GPIO.FALLING, errorDetection, bouncetime=2000)
GPIO.add_event_detect(33, GPIO.FALLING, errorDetection, bouncetime=2000)
GPIO.add_event_detect(31, GPIO.FALLING, errorDetection, bouncetime=2000)
GPIO.add_event_detect(29, GPIO.FALLING, errorDetection, bouncetime=2000)
GPIO.add_event_detect(40, GPIO.FALLING, errorDetection, bouncetime=2000)
GPIO.add_event_detect(38, GPIO.FALLING, errorDetection, bouncetime=2000)
GPIO.add_event_detect(36, GPIO.FALLING, errorDetection, bouncetime=2000)
i = 0;
while i <= 10:
print("i value",i)
i = i+1
sleep(4)
if i == 10:
i = 0