I see similar questions but nothing really the same, hope this isnt duplicated.
Im trying to count LED pulses from a domestic energy meter, I had a basic While: loop running but when the count gets to a certain number I need to trigger other code that takes time to execute, meaning I could miss pulses, also I was sometimes getting double counted pulses due to the duration of the LED pulse.
Im now at this stage:
import RPi.GPIO as gpio gpio.setmode(gpio.BCM) gpio.setup(17, gpio.IN, pull_up_down=gpio.PUD_UP) total_energy = float(raw_input ("What is the start reading on your Solar PV meter: "))/1000 current_energy=0 def currentenergycounter(current_energy): current_energy = current_energy + 0.000001 return current_energy current_energy = gpio.add_event_detect(17, gpio.RISING, callback=currentenergycounter, bouncetime=300) while True: if current_energy >= energy_reporting_increment: total_energy = total_energy + current_energy timestamp() energy_log = maintainenergylog() send_amount = calculateamounttosend() writetoblockchain()
But Im not getting any pulses counted, at least the While: loop isnt triggering, expect the problem is with gpio.add_event_detected but help appreciated.