I can't seem to get the right pin number.

Let's say I want to access this pin:


What's the actual address of the pin? 11, 26 or what?

Here's the code I use: (THIS CODE WORKS WITH PIN BCM 23)

final Context context = Pi4J.newAutoContext();

final DigitalOutputConfig config = DigitalOutput.newConfigBuilder(context)
final DigitalOutput output = context.dout().create(config);
synchronized (Thread.currentThread()) {
    try {
    } catch (InterruptedException e) {
    } finally {

I have the Raspberry Pi 3B+

EDIT: Just for the context, I've already tried both pin addresses with no success.

EDIT 2: Thanks to the response by @Milliways and the link provided by the answer from @joan, I was able to identify the correct pin address, it's 7 because of the BCM pin numbering scheme. The code works when connecting an LED, but won't work with a motor. I think it's because of the voltage or something, definitly not a problem in Pi4J.

I changed the pin from BCM 7 to BCM 23, that's why the code says .address(23). BCM 7 wouldn't change it's state.

  • great idea to test with a LED! for a motor you may need additional code and/or hardware as you have different types. a simple on/off can require to much A for the Pi to be delivered through a GPIO. And a stepper or servo motor will need other type of control. See for example pi4j.com/examples/components/servo
    – Frank
    Commented Jan 30, 2023 at 7:12
  • I already tried using these example classes and connected the ServoMotor one to the Pi, it worked, when I looked in the code, it appeared that they used a PWM Pin, i don't really know what that is or how to use it with other motors. Thanks for your help though.
    – nexalbyte
    Commented Feb 3, 2023 at 13:52

2 Answers 2


There are 3 pin numbering conventions in use on the Pi; BCM, Physical (or Board) and WiringPi.

  • BCM is the native numbering (and is the only convention understood by the SoC).
  • Board numbers correspond to the header pin number. A subset of GPIO pins are brought to the header. On early models this varied, but all with 40pin headers are identical.
  • WiringPi numbers are an attempt to map to Wiring numbers (used on Arduino). (This probably seemed like a good idea at the time, but has caused considerable confusion.) WiringPi supported all 3 conventions.

Pi4J was (is?) an unofficial Java implementation of WiringPi although I believe the current version is based on pigpio and uses native numbering (but I am not a Java programmer).

The pin you reference is BCM 7, Board 26, WiringPi 11.
The image you included seems to be for Pi4J v1 not v2.

You will need to check the documentation for the version of Pi4J you are using.

  • Pi4J V1 used WiringPi as the native code to call the GPIOs. But as that project got deprecated, a fork could be used that is compatible with newer Pi-boards. See pi4j.com/1.4/install.html#WiringPi_Native_Library. Pi4J V2 uses PiGpio and LinuxFX to achieve the same. So Pi4J is not an implementation of those native libraries, but includes and uses them to "hide" the complexity to Java developers.
    – Frank
    Commented Jan 30, 2023 at 7:14
  • @Frank the problem with Pi4J (at least from my viewpoint) is lack of consistent documentation. The v2 site has lots of unnecessary documentation (largely out of date) for installing Raspbian but all it says about Pi4J is "to do".
    – Milliways
    Commented Jan 31, 2023 at 3:37
  • feedback like this is very valuable! Anything I can do to improve the docs is welcome. Would you be interested to join the Pi4J Slack to explain the problems further? Or via e-mail? Please, let us get in touch directly via frank at pi4j dot com
    – Frank
    Commented Jan 31, 2023 at 6:46

Pi4J version 2 uses Broadcom numbering for the GPIO.

You should be using 7 (to identify GPIO 7).

See https://pinout.xyz/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.