0

I need to find a solution for my project. Basically I just need to define if there is a voltage or not by using GPIO event detection.

For my basic scheme I used 3.3v pin and one of the GPIO pin for the pull_down input:

GPIO.setmode(GPIO.BCM)
GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

GPIO.add_event_detect(24, GPIO.RISING, callback=rising_callback, bouncetime=200)

That code worked fine for me. However, I want to make possible to detect voltage up to 16.5v. I don't need to read its exact value.

How can I setup everything so the 'add_event_detect' will run a callback if some voltage is received?

Some notes: I'm using Pi-3 b+. I also have an ADC0832 and a Voltage Sensor. And I know how to use the ADC to read the exact voltage. But I don't like to run a loop to always read the ADC value to define if there is some voltage. Also it is possible that the voltage will appear for a very short period of time, so I can't add a delay between ADC readings. Also I want to avoid the situation when the voltage is lower than 3v so the event detect might not trigger the callback (this is why and don't like a solution to reduce high voltage by using a voltage divider). I wonder if it is possible to use the ADC and the sensor with the event_detection to trigger a callback if there is a 0.5-16.5v voltage received without using 'read_adc_value' loop.

1

No, the ADC can't be used to trigger an event. It's only function is to represent some analogue input as a digitally quantized output.

What you are looking for is called a comparator. This will "compare" two analogue inputs (call them "A" and "B") and output a "1" if A > B. Typically you'd have an adjustable reference voltage on "B" and your sensor on "A" and the output into your Pi GPIO (with appropriate level shifting etc.etc.). You can then use the hardware edge detection on the GPIO to trigger your callback.

If the signal you are measuring, once over the trigger point, tends to hover and then drop back down then it might be worth considering a Schmitt trigger, a special type of comparator with a well defined hysteresis between two thresholds. It will "latch" on when the input first crosses the upper threshold and stay on until the input drops below the lower threshold.

If you are concerned about catching "fast" events you may want to think about using an RC network on the output to lengthen short pulses (or a NE555 in monostable configuration).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.