0

I am working on raspberry pi to blink the LED using java.
Its working fine for the first time and it giving this error if I try to run for next time.

            GpioController gpioController = GpioFactory.getInstance();            // Initialize the GPIO pin            final GpioPinDigitalOutput pin = gpioController                    .provisionDigitalOutputPin(RaspiPin.GPIO_01, "MyLED",                            PinState.HIGH);            Thread.sleep(2000);            pin.low();            Thread.sleep(1000);            pin.toggle();            Thread.sleep(2000);            pin.toggle();            gpioController.shutdown();

I got the folowing error:

com.pi4j.io.gpio.exception.GpioPinExistsException: This GPIO pin already exists: GPIO 1 com.pi4j.io.gpio.impl.GpioControllerImpl.provisionPin(GpioControllerImpl.java:50‌​7) com.pi4j.io.gpio.impl.GpioControllerImpl.provisionDigitalOutputPin(GpioControlle‌​rImpl.java:645) com.pi4j.io.gpio.impl.GpioControllerImpl.provisionDigitalOutputPin(GpioControlle‌​rImpl.java:672)

mpromonet's user avatar
mpromonet
1,1241 gold badge19 silver badges38 bronze badges
askedFeb 8, 2015 at 11:14
Nabin Pradhan's user avatar
2
  • are you running java with sudo? and is this Raspbian?CommentedFeb 9, 2015 at 9:07
  • yes I am running in root and i am using RaspbianCommentedFeb 10, 2015 at 5:21

1 Answer1

1

After you call .shutdown() add a line in order to unProvision your pin.

gpio.shutdown(); gpio.unProvisionPin(pin);

This will release pi4j's internal reference and allow you to reprovision it later.

Source:https://stackoverflow.com/questions/28425918/this-gpio-pin-already-exists-gpio-1-exception-on-second-time

answeredFeb 13, 2015 at 4:30
Nabin Pradhan's user avatar

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.