Pin Numbering Schemes

WiringPi Pin Numbering Scheme (Default)

By default, Pi4J uses the WiringPi pin numbering scheme for all supported Raspberry Pi models except the Compute Module. The WiringPi pin numbering scheme is an abstract pin numbering scheme to help insulate software from hardware changes. More information about the WiringPi pin number scheme can be found here:

Broadcom Pin Numbering Scheme

While the WiringPi pin numbering scheme is the default pin numbering scheme used by Pi4J, Pi4J also includes support for using the Broadcom Pin Numbering Scheme. There may be special circumstances or perhaps just personal preference where you may want or need to use the Broadcom Pin numbering scheme. Please be aware that, while a rare occurrence, the Broadcom pins numbers can change physical locations where they are mapped/connected on the GPIO header on different models/board revisions.

Before provisioning any GPIO pins, you must first configure the Pi4J library to use the Broadcom Pin Numbering scheme. The sample code below configures the default GPIO provider in the Pi4J library to use the Broadcom Pin Numbering scheme.

// in order to use the Broadcom GPIO pin numbering scheme, we need to configure the
// GPIO factory to use a custom configured Raspberry Pi GPIO provider
GpioFactory.setDefaultProvider(new RaspiGpioProvider(RaspiPinNumberingScheme.BROADCOM_PIN_NUMBERING));

After Pi4J is configured to use the Broadcom GPIO pin numbering scheme you can then create the GpioController instance and start provisioning GPIO pins.

To access a GPIO pin, you must first provision the pin.
Provisioning configures the pin based on how you intend to use it. Provisioning can automatically export the pin, set its direction, and setup any edge detection for interrupt based events.

Pi4J provides a RaspiBcmPin enumeration that is used to manage the accessible GPIO pins for the Broadcom GPIO pin numbering scheme.

The following code snippet demonstrates creating the GPIO controller instance and provisioning a GPIO output pin for Broadcom pin #2.

// create gpio controller
final GpioController gpio = GpioFactory.getInstance();

// provision broadcom gpio pin #02 as an output pin and turn on
final GpioPinDigitalOutput pin = gpio.provisionDigitalOutputPin(RaspiBcmPin.GPIO_02, "MyLED", PinState.HIGH);

A complete example is included in the Pi4J examples project: RaspiBcmPin