1

I am fairly new to Raspberry PI GPIO pins. I have some simple code which sets Pin 29 (BCM 5 in this picture) as an IN (READ) Pin and then reads from it after boot and on raspberry pi 3 it has always been Low however on the raspberry pi 4 it seems to be High.

I am trying to understand why this is the case.

I was not able to find any specification on why that is. My understanding is that the raspberry pi 4 uses BCM2838 however the only spec sheet I can find is this one for the BCM2835 (https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2835/BCM2835-ARM-Peripherals.pdf)

On page 102 there is a table with alternate functions showing the default pull values and for Pin 29 is has a dash (-) and some comment at the bottom about white values not to be used but I am not certain whether this is relevant

The Go code below reproduces the issue by performing a simple READ on the pin (We use the latest periph library with support for rpi 4

package main

import (
    "fmt"
    "log"
    "time"

    "periph.io/x/periph/conn/gpio"
    "periph.io/x/periph/host"
    "periph.io/x/periph/host/rpi"
)

var (
    readPin  = rpi.P1_29
)

func main() {
    fmt.Println("Initializing periph host...")
    if _, err := host.Init(); err != nil {
        log.Panicf("failed to initialize periph host: %v", err)
    }

    if err := readPin.In(gpio.PullDown, gpio.NoEdge); err != nil {
        log.Panicf("failed to set read pin to In(): %v", err)
    }

    ticker := time.NewTicker(2* time.Second)
    want := gpio.Low

    for {
        select {
        case <-ticker.C:
            time.Sleep(time.Millisecond)
            actual := readPin.Read()
            if actual != want {
                log.Printf("ERROR: Actual: %t != Wanted: %t", actual, want)
                continue
            }
            log.Println("EVERYTHING WAS FINE")
        }
    }
}

Any chance somebody can shine a light on the situation? Is there some undocumented behaviour to Pin 29 I am missing causing this? Is this expected behaviour (and if so an explanation would be nice)

1
  • There is no difference in the default pullup and doesn't happen to anyone else. Who knows what Go might do, but the value should be 1. – Milliways Jan 15 '20 at 11:17
2

On all Pis with the 40 pin expansion header pin 29 is connected to GPIO 5.

GPIO 5 defaults to a pull-up at power up.

The pulls are quite weak (about 50k ohms) so they can easily be overridden by an external voltage.

The table you linked shows GPIO 5 as defaulting to pull-up.

GPIO 28/29 are not brought out to the 40-pin expansion header.

2
  • I see what you mean, pin numbers vs gpio numbers can be confusing however this makes me wonder why are we not having the same issue on raspberry pi 3? There we read a low voltage using the exact same code I posted above and exact same pin and the table I link is for the raspberry pi 3 (or maybe even lower version) so it should be high too. I tested this is several different raspberry pi 3 and they all behave the same – ByteFlinger Jan 15 '20 at 12:12
  • @ByteFlinger All Pis are identical as far as the default pulls. The Pi3 will be the same. The obvious explanation is the connected circuit is pulling the GPIO low or software has changed the pulls since power-up. – joan Jan 15 '20 at 12:20

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.