Skip to content

Pi4J 2.8.0 always reads GPIO inputs as LOW on Raspberry Pi Zero W (Bookworm, kernel 6.12, libgpiod 1.6.3) while gpioget works #519

@jandeclerck

Description

@jandeclerck

Title:
Pi4J 2.8.0 always reads GPIO inputs as LOW on Raspberry Pi Zero W (Bookworm, kernel 6.12, libgpiod 1.6.3) while gpioget works


Description:
On my Raspberry Pi Zero W running Raspberry Pi OS Bookworm (32-bit), kernel 6.12.47+rpt-rpi-v6, and libgpiod 1.6.3, Pi4J 2.8.0 always reads all GPIO input pins as LOW, regardless of their actual hardware state.
Other tools (gpioget, raspi-gpio, pinctrl) report the correct state.


Environment:

  • Board: Raspberry Pi Zero W (code: 9000c1)
  • OS:
    PRETTY_NAME="Raspberry Pi OS Bookworm"
    NAME="Raspberry Pi OS"
    VERSION_ID="12"
    VERSION="12 (bookworm)"
    ID=raspbian
    ID_LIKE=debian
  • Kernel:
    Linux 24sPiZero 6.12.47+rpt-rpi-v6 66666 #1 SMP PREEMPT Debian 1:6.12.47-1+rpt1 (2024-08-01) armv6l GNU/Linux
  • Java:
    openjdk version "17.0.16" 2023-07-18
    OpenJDK Runtime Environment (build 17.0.16+8-Raspbian-1deb12u1rpi1rpt1)
    OpenJDK Client VM (build 17.0.16+8-Raspbian-1deb12u1rpi1rpt1, mixed mode)
  • libgpiod:
    gpiod version 1.6.3
  • Pi4J: 2.8.0
  • pigpiod: Not running (systemctl status pigpiod shows inactive)

Steps to Reproduce:

  1. Connect jumpers or set GPIO pins to HIGH/LOW using hardware or external pull resistors.

  2. Confirm correct pin state using:

    • gpioget gpiochip0 <pin>
    • raspi-gpio get <pin>
    • pinctrl
  3. Run the following minimal Pi4J test program:

    package org.janssen.twentyfour;
    
    import com.pi4j.Pi4J;
    import com.pi4j.context.Context;
    import com.pi4j.io.gpio.digital.*;
    
    public class GpioInputTest {
        public static void main(String[] args) throws Exception {
            Context pi4j = Pi4J.newAutoContext();
    
            int[] pins = {4, 7, 8, 11, 17, 18, 23, 24, 27};
            String[] names = {
                "reset14Btn (GPIO4)",
                "jump2 (GPIO7)",
                "jump1 (GPIO8)",
                "start60Btn (GPIO11)",
                "reset24Btn (GPIO17)",
                "show24Btn (GPIO18)",
                "pls1SecondBtn (GPIO23)",
                "mns1SecondBtn (GPIO24)",
                "timerBtn (GPIO27)"
            };
    
            for (int i = 0; i < pins.length; i++) {
                DigitalInput input = pi4j.create(DigitalInput.newConfigBuilder(pi4j)
                    .id("gpio" + pins[i])
                    .name(names[i])
                    .address(pins[i])
                    .pull(PullResistance.OFF)
                    .build());
                System.out.printf("%-20s : %s%n", names[i], input.state());
            }
    
            pi4j.shutdown();
        }
    }
  4. Run with:

    sudo java -cp /home/pi/twentyfour/classes:/home/pi/twentyfour/lib/* org.janssen.twentyfour.GpioInputTest
    

Expected Result:
Pi4J should report the actual state of each GPIO input (HIGH or LOW), matching the result from gpioget and raspi-gpio.

Actual Result:
All GPIO inputs are always reported as LOW by Pi4J, regardless of their actual state.
gpioget and raspi-gpio report the correct state.


Additional Information:

  • No other GPIO daemons (e.g., pigpiod) are running.
  • The issue persists with both hardware and software pull resistors.
  • This issue blocks GPIO-based configuration and input detection on Pi Zero W.

Thank you for your help!

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions