User avatar
rpiMike
Posts: 1065
Joined: Fri Aug 10, 2012 12:38 pm
Location: Cumbria, UK

GPIO button works on Pi3 not on Pi4

Sun Jun 30, 2019 10:54 am

The following Python code for a button between Ground and GPIO17 works fine on Pi3 (returning 1's when not pressed, 0's when pressed) however only returns 0's on Pi4.

Using Raspbian Buster, Python 3.7.3, RPi.GPIO 0.6.5.

Is this something to do with the Pi4's new GPIO alternate modes?

Code: Select all

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(17,GPIO.IN,pull_up_down=GPIO.PUD_UP)

while True:
    print(GPIO.input(17))
    time.sleep(0.1)

User avatar
joan
Posts: 14599
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: GPIO button works on Pi3 not on Pi4

Sun Jun 30, 2019 11:06 am

The way the pulls work has changed on the Pi4B (new BCM2711 SoC).

The internal pull-up will not be enabled by your code.

If that's the cause the code should work if you use GPIO4 which defaults to an internal pull-up.

User avatar
rpiMike
Posts: 1065
Joined: Fri Aug 10, 2012 12:38 pm
Location: Cumbria, UK

Re: GPIO button works on Pi3 not on Pi4

Sun Jun 30, 2019 11:18 am

Thanks joan, yes GPIO 4 worked.

Edit: I noticed this issue as the gpiozero Button object no longer works on Pi4.

So what options do we have for changing pull-ups?

I guess the config file should work on Pi3 and Pi4?

https://www.raspberrypi.org/documentati ... xt/gpio.md

User avatar
joan
Posts: 14599
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: GPIO button works on Pi3 not on Pi4

Sun Jun 30, 2019 11:53 am

The configuration command you linked should work.

raspio-gpio should also work as I think it has been updated.

The wiringPi gpio utility (no relation to the linked gpio configuration command) should also work if you download an updated wiringPi.

I have made the change to (my) pigpio but other changes are pending before I release the software.

RPi.GPIO is in the process of being updated.

The changes should feed through to gpiozero in the next few days/weeks.

jackson1990
Posts: 2
Joined: Thu Jan 02, 2020 9:38 pm

Re: GPIO button works on Pi3 not on Pi4

Thu Jan 02, 2020 9:47 pm

Hello,
I migrated a node-red application for Raspberry 3B+ with Skretch to Raspberry 4B with Buster.
Everything works fine except my interrupt to restart to board with rpi-gpio in (out of node-red-node-pi-gpio library).
I read in PIN 15 (GPIO 22) and waiting for "1" (3V3), initial value shall be "0" (GND).
On Rasp 3B+ everything works fine, but with 4B I always get a "1" and no changes.

I read that the internal pull-ups changed from Version 3B to 4B, can it be caused by that?
But Pin 15 is configured as tri-state (input)...

Futhermore I can get "stimulate" a trigger if I want to measure the signal on Pin 15 with a probe just by contacting to the pin without closing a measurement loop, which let me assume that there is some internal change/sensibility compared to Version 3B.

I also did the updates mentioned above, but nothing changed.

Would appreciate your support!

Kind regards,
Michael

jackson1990
Posts: 2
Joined: Thu Jan 02, 2020 9:38 pm

Re: GPIO button works on Pi3 not on Pi4

Sat Jan 04, 2020 12:22 pm

Seems that in tri-state condition the Raspberry 3B pulls down the voltage level to GND internally.
On Raspberry 4B the voltage level seems to be pulled up to 3V3 in tri-state condition.

When I added an external 10k pull-down resistor in conjuntion with 4B it works fine.

User avatar
davidcoton
Posts: 4430
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: GPIO button works on Pi3 not on Pi4

Sat Jan 04, 2020 1:26 pm

jackson1990 wrote:
Sat Jan 04, 2020 12:22 pm
Seems that in tri-state condition the Raspberry 3B pulls down the voltage level to GND internally.
On Raspberry 4B the voltage level seems to be pulled up to 3V3 in tri-state condition.

When I added an external 10k pull-down resistor in conjuntion with 4B it works fine.
Tri-state is when an output is high impedance (neither pulled high nor low). The Pi GPIOs only support this by switching to input mode with no pull. But the phrase is not relevant to inputs.

An input is naturally high impedance (or should be). The state in the absence of a signal is not guaranteed. If you are using a single contact to connect to GND, then you need a pull the 3V3 to guarantee correct operation (and, conversely, a pull to GND if switching to 3V3). As you found, a hardware resistor works, but the Pi input can have a programmed pull that saves you the extra hardware. Details depend on the particular GPIO library you are using, check its documentation.
Signature retired

alphanumeric
Posts: 2260
Joined: Tue Jan 19, 2016 2:17 pm
Location: Sydney, Nova Scotia, Canada

Re: GPIO button works on Pi3 not on Pi4

Mon Jan 06, 2020 8:30 pm

Just a FYI post but I've been using

Code: Select all

 dtoverlay=gpio-shutdown,gpio_pin=17,active_low=1,gpio_pull=up 
with my Pimoroni Fan shim. My 4B does a shut down when I press the button on the Fan Shim. The button grounds BCM 3 and BCM 17 when pressed.

hippy
Posts: 6551
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: GPIO button works on Pi3 not on Pi4

Mon Jan 06, 2020 9:23 pm

joan wrote:
Sun Jun 30, 2019 11:06 am
The way the pulls work has changed on the Pi4B (new BCM2711 SoC).
I missed that so it's fortunate this thread had recent posts. I guess I'm going to have to alter my own C Extensions so they will work properly with a 4B - Do you, or anyone, have a link to explain what's changed and what needs to be altered ?

User avatar
joan
Posts: 14599
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: GPIO button works on Pi3 not on Pi4

Mon Jan 06, 2020 10:16 pm

hippy wrote:
Mon Jan 06, 2020 9:23 pm
joan wrote:
Sun Jun 30, 2019 11:06 am
The way the pulls work has changed on the Pi4B (new BCM2711 SoC).
I missed that so it's fortunate this thread had recent posts. I guess I'm going to have to alter my own C Extensions so they will work properly with a 4B - Do you, or anyone, have a link to explain what's changed and what needs to be altered ?
The changes are small. I looked at the sources for the Foundation's gpio utility for guidance. Sorry its name escapes me for the moment. To give an idea this is what I do in pigpio.

Code: Select all

#define GPPUPPDN0 57

   if (pi_is_2711)
   {
      switch (pud)
      {
         case PI_PUD_OFF:  pull = 0; break;
         case PI_PUD_UP:   pull = 1; break;
         case PI_PUD_DOWN: pull = 2; break;
      }

      bits = *(gpioReg + GPPUPPDN0 + (gpio>>4));
      bits &= ~(3 << shift);
      bits |= (pull << shift);
      *(gpioReg + GPPUPPDN0 + (gpio>>4)) = bits;
   }
   else
   {
      *(gpioReg + GPPUD) = pud;

      myGpioDelay(1);

      *(gpioReg + GPPUDCLK0 + BANK) = BIT;

      myGpioDelay(1);

      *(gpioReg + GPPUD) = 0;

      *(gpioReg + GPPUDCLK0 + BANK) = 0;
   }


Milliways
Posts: 497
Joined: Fri Apr 25, 2014 12:18 am
Location: Sydney, Australia

Re: GPIO button works on Pi3 not on Pi4

Mon Jan 13, 2020 12:56 am

joan wrote:
Mon Jan 06, 2020 10:16 pm
hippy wrote:
Mon Jan 06, 2020 9:23 pm
joan wrote:
Sun Jun 30, 2019 11:06 am
The way the pulls work has changed on the Pi4B (new BCM2711 SoC).
I missed that so it's fortunate this thread had recent posts. I guess I'm going to have to alter my own C Extensions so they will work properly with a 4B - Do you, or anyone, have a link to explain what's changed and what needs to be altered ?
The changes are small. I looked at the sources for the Foundation's gpio utility for guidance. Sorry its name escapes me for the moment. To give an idea this is what I do in pigpio.

Code: Select all

#define GPPUPPDN0 57

   if (pi_is_2711)
   {
      switch (pud)
      {
         case PI_PUD_OFF:  pull = 0; break;
         case PI_PUD_UP:   pull = 1; break;
         case PI_PUD_DOWN: pull = 2; break;
      }

      bits = *(gpioReg + GPPUPPDN0 + (gpio>>4));
      bits &= ~(3 << shift);
      bits |= (pull << shift);
      *(gpioReg + GPPUPPDN0 + (gpio>>4)) = bits;
   }
   else
   {
      *(gpioReg + GPPUD) = pud;

      myGpioDelay(1);

      *(gpioReg + GPPUDCLK0 + BANK) = BIT;

      myGpioDelay(1);

      *(gpioReg + GPPUD) = 0;

      *(gpioReg + GPPUDCLK0 + BANK) = 0;
   }
Looks like this should allow the current state of pull to be read on a Pi4. (I don't think peripheral data is yet published.)

User avatar
rpdom
Posts: 15932
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: GPIO button works on Pi3 not on Pi4

Mon Jan 13, 2020 8:52 am

Milliways wrote:
Mon Jan 13, 2020 12:56 am
Looks like this should allow the current state of pull to be read on a Pi4. (I don't think peripheral data is yet published.)
Yes, it can. Someone did mention that feature had been added in the BCM2711 SoC. I don't recall any documentation for it yet.

Return to “Python”