pimoroni / automation-hat

Python library and examples for the Pimoroni Automation HAT, pHAT and HAT Mini
https://shop.pimoroni.com/products/automation-hat
MIT License
122 stars 41 forks source link

Ability to use Pi's internal pull up/down resistors for digital inputs #19

Closed kiddigital closed 5 years ago

kiddigital commented 6 years ago

Added ability to use RPi's internal PULL_UP/PULL_DOWN resistors for digital input. Extended Input example.

Gadgetoid commented 6 years ago

Interesting- what's your use case for this?

I was originally concerned about the voltage divider the 50K pull-down would create with the 20K current-limiting series resistor but - if my maths serves me correctly - it only lifts the minimum required voltage for a stable "HIGH" to around 2.5v.

kiddigital commented 6 years ago

@Gadgetoid , my original use case is a doorbell.

I used the available 5volt of the Automation HAT directly for my doorbell switch connected to the digital input of the Automation HAT without any pull-down resistor. Because of the floating-ground issue, the readings on the input where not reliable but after activating the internal pull-down resistor of the Pi, the input is now reliable.

Also I use it now for a second use-case which is a 12volt motion detector which gets is 12volt from an external source and pulls a second 12volt line down when it detects motion. Here I also needed to activate the internal pull-up resistor on the analog input to get a reliable reading (same floating-ground issue I assume :) ).

Gadgetoid commented 5 years ago

My maths was wrong. Actually testing this a basic wire from +5v to an input, and activating the internal pull-down causes +5v to not register as a logic HIGH anymore on my Pi setup. This is at the mercy of the tolerances of all the resistors involved on both the HAT and the Pi, plus how the Pi behaves when a logic signal is in its hysterisis band between definite LOW/HIGH.

I think the correct approach for this is to use an external resistor, rather than activating the Pi's internal ones. In most cases, activating the pull-down resistor will effectively disable the input for a vast range of voltages, and has the potential to cause more confusion than help.