Automation hat COUNTER

Hy, I have some automation hat and I want to count form 3 Input (0->1->0) or (1->0->1) (SET-RESET) but with python library I’cant read fast as chip … there is a way ??

thanks

How fast is the chip driving those inputs? What chip is it? How accurate do you need to count?

The Pi isn’t well suited to this kind of task, but there may be workarounds depending on your application.

1pulse every 2 second
I use Automation hat with “buffer” on input…
I suppose is possibile to reach this interval

Hmm, that shouldn’t be tricky!

I’d probably use RPi.GPIO directly and so something like:

import RPi.GPIO as GPIO
counter = 0

GPIO.setmode(GPIO.BCM)
GPIO.setup(26, GPIO.IN)  # Set up input 1

def count_pin(channel):
    global counter
    counter += 1

GPIO.add_event_detect(26, GPIO.FALLING, callback=count_pin)  # May need GPIO.RISING depending on your device

while True:
    print("Counter: {}".format(counter))
    time.sleep(1)

ehm I use:

import automationhat

varname = automationhat.input.one.read();

Your sample is direct with GPIO …

import automationhat
import sys
import time

if automationhat.is_automation_hat():
	automationhat.light.power.write(1)
	
input3counter = 0
input2counter = 0
input1counter = 0

while True:
	a = False
	
	input3 = automationhat.input.three.read()
	if input3 == True : 
		input3counter = input3counter +1
		print('read3' + str(input3counter) )
	
	input2 = automationhat.input.two.read()
	if input2 == True : 
		input2counter = input2counter +1
		print('read2' + str(input2counter) )
	
	input1 = automationhat.input.one.read()
	if input1 == True : 
		input1counter = input1counter +1
		print('read1' + str(input1counter) )
	
	time.sleep(0.5)

This not working … when “automationhat.input.three.read()” all input will reset !!!

What do you mean by “all input will reset.” If your inputs are being asserted by an external device they will always be at the logic level supplied to them.

To put it another way; If your input.three.read() doesn’t happen to coincide with the point at which your pulse is happening, it will always read False.