1

I am basically trying to turn on a led by using pi4j library. My code is pretty simple:

public static void main(String args[]) throws InterruptedException {
    GpioController gpioController = GpioFactory.getInstance();
    GpioPinDigitalOutput pinOut = gpioController.provisionDigitalOutputPin(RaspiPin.GPIO_17);
    pinOut.high();
    Thread.sleep(5000);
    pinOut.low();
}

I am exporting the jar file from my computer, copying to my Raspberry Pi 4 than running in there.

To check if my led is not broken or GPIO is set, I've executed following Python scripts and I see my led works perfectly:

python
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
GPIO.output(17,True)

What am I missing?

osumatu
  • 113
  • 1
  • 4

2 Answers2

1

Indeed as mentioned in the comments, Pi4J is using a different pin numbering scheme. "Under the hood", WiringPi is used to control the GPIOs. This library uses a different numbering scheme. This means BCM pin 17 you are using in Python is pin 0 in the WiringPi scheme.

See below a full table with BCM, WiringPi, and physical pin numbering (see link 2 below).

Raspberry Pi numbering scheme with BCM and WiringPi numbering

Next to that, the internal wiring of the Raspberry Pi 4 is different compared to the previous ones, so you'll need to upgrade your WiringPi to the latest version 2.52 with:

$ gpio -v
gpio version: 2.50

$ cd /tmp $ wget https://project-downloads.drogon.net/wiringpi-latest.deb $ sudo dpkg -i wiringpi-latest.deb $ gpio -v gpio version: 2.52

As a side note: we are working on a new version of Pi4J which will make things easiers, but work-in-progress... ;-)

More info in my blog posts on:

  1. Using Pi4j (V1) on the Raspberry Pi 4
  2. Raspberry Pi history, versions, pins and headers as a Java Maven library
  3. Oracle Java Magazine: Getting started with JavaFX on Raspberry Pi
Frank
  • 328
  • 1
  • 9
0

Since I don't have enough reputation to comment...

In the PI4J library, you use constants like "GPIO_16"... However, these are not the GPIO pins that you find in the RPI documentation. They are the WiringPI pins.

A mapping is here: https://pinout.xyz/pinout/wiringpi

winrid
  • 1