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)

  • are you running java with sudo? and is this Raspbian? – rob Feb 9 '15 at 9:07
  • yes I am running in root and i am using Raspbian – Nabin Pradhan Feb 10 '15 at 5:21
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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