GOB
Posts: 10
Joined: Tue Nov 14, 2017 1:34 am

Does GPIOZero enable pull up resistors?

Sun Oct 21, 2018 5:57 pm

I am using the excellent gpiozero library, but I have a question that I can't find the answer to that I think is quite important.

Does using the Button() function actually enable the built in pull up resistors on the pi?

Looking here:
https://bennuttall.com/gpio-zero-develo ... computing/
However, in GPIO Zero, you create a Button object, which assumes the common pull-up circuit by default. Then to check its state, you access the is_active property. The alias is_pressed is provided for the Button class:

Code: Select all

button = Button(4)

while True:
    if button.is_pressed:
        print("Pressed")
does that mean that the internal pull up resistor is enabled, the same as doing this :

Code: Select all

GPIO.setup(4, GPIO.IN, GPIO.PUD_UP)

while True:
    if not GPIO.input(4):
        print("Pressed")
Thanks for the help! Trying to figure out if I need to use external pull up resistors if using the gpiozero library.

gordon77
Posts: 3401
Joined: Sun Aug 05, 2012 3:12 pm

Re: Does GPIOZero enable pull up resistors?

Sun Oct 21, 2018 6:54 pm

You can enable pull up

Code: Select all

   button1 = Button( 7,pull_up = True,bounce_time= None) 
https://www.raspberrypi.org/blog/gpio-z ... computing/

Although it appears not required...

"We’ve thought really hard to try to get the naming right, and hope people old and young will find the library intuitive once shown a few simple examples. The API has been designed with education in mind and I’ve been demoing it to teachers to get feedback and they love it! Another thing is the idea of minimal configuration – so to use a button you don’t have to think about pull-ups and pull-downs – all you need is the pin number it’s connected to. Of course you can specify this – but the default assumes the common pull-up circuit. For example:

button_1 = Button(4) # connected to GPIO pin 4, pull-up

button_2 = Button(5, pull_up=False) # connected to GPIO pin 5, pull-down"
Last edited by gordon77 on Sun Oct 21, 2018 7:03 pm, edited 1 time in total.

GOB
Posts: 10
Joined: Tue Nov 14, 2017 1:34 am

Re: Does GPIOZero enable pull up resistors?

Sun Oct 21, 2018 7:01 pm

Thanks for the reply. I wanted to double check that the code actually enabled the physical onboard pull up resistors on the pi. It does!

DirkS
Posts: 9213
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Does GPIOZero enable pull up resistors?

Sun Oct 21, 2018 7:12 pm

GOB wrote:
Sun Oct 21, 2018 7:01 pm
Thanks for the reply. I wanted to double check that the code actually enabled the physical onboard pull up resistors on the pi. It does!
So the documentation is correct :)
https://gpiozero.readthedocs.io/en/stab ... tml#button
pull_up (bool) – If True (the default),

GOB
Posts: 10
Joined: Tue Nov 14, 2017 1:34 am

Re: Does GPIOZero enable pull up resistors?

Sun Oct 21, 2018 7:21 pm

just to be picky, that page doesn't specifically say that the built in pulllup resistor is used:
https://gpiozero.readthedocs.io/en/stab ... tml#button
Parameters:
pin (int) – The GPIO pin which the button is attached to. See Pin Numbering for valid pin numbers.
pull_up (bool) – If True (the default), the GPIO pin will be pulled high by default. In this case, connect the other side of the button to ground. If False, the GPIO pin will be pulled low by default. In this case, connect the other side of the button to 3V3.

Return to “Python”