2

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

Let's say I want to access this pin:

J8Header

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) .id("motor") .name("motor-output") .address(23) .shutdown(DigitalState.LOW) .initial(DigitalState.LOW) .provider("pigpio-digital-output") .build(); final DigitalOutput output = context.dout().create(config); output.high(); synchronized (Thread.currentThread()) { try { Thread.currentThread().wait(1000); } catch (InterruptedException e) { } finally { output.low(); } }

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.

nexalbyte
  • 123
  • 4

2 Answers2

3

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.

Milliways
  • 62,573
  • 32
  • 113
  • 225
2

Pi4J version 2 uses Broadcom numbering for the GPIO.

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

See https://pinout.xyz/

joan
  • 71,852
  • 5
  • 76
  • 108