0

Working from this example, I'm trying to get the LED to turn on and off. The code runs displaying text, but the LED still remains off. My setup:

(3v3)

  • Redwire: GPIO 7 and 30d
  • LED: (pos) 30e and (neg) 29e
  • Resistor: 29d and 29b
  • GND: pin 9 and 29a

Program:

import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinDigitalOutput;
import com.pi4j.io.gpio.PinState;
import com.pi4j.io.gpio.RaspiPin;

public class HelloRPi 
{
    public static void main(String[] args) throws InterruptedException
    {
         System.out.println("Program started...");

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

        final GpioPinDigitalOutput pin = 
                gpio.provisionDigitalOutputPin(RaspiPin.GPIO_07, "REDLED", PinState.HIGH);

        System.out.println("--> GPIO state should be: ON");

        Thread.sleep(5000);

        // turn off gpio pin 
        pin.low();
        System.out.println("--> GPIO state should be: OFF");

        Thread.sleep(5000);

        pin.toggle();
        System.out.println("--> GPIO state should be: ON");

        Thread.sleep(5000);

        // toggle the current state of gpio pin  (should turn off)
        pin.toggle();
        System.out.println("--> GPIO state should be: OFF");

        Thread.sleep(5000);

        System.out.println("--> GPIO state should be: ON for only 1 second");
        pin.pulse(1000, true); // set second argument to 'true' use a blocking call

        gpio.shutdown();
    }      
}

2 Answers 2

1

Figured out the problem. The problem is that I was going off of the diagram from here (B+) that came with my Raspberry Pi and not going by the one for Pi4J here, since Im using the Pi4J library I assume.

3
  • That wouldn't have stopped you shorting out the LED on the breadboard.
    – joan
    Dec 29, 2014 at 9:57
  • @joan I didn't short out the LED. I was going by the wrong layout based on the library. The reference card laying out the pin locations that came with the Canakit doesn't match the reference image for the Pi4J library. GPIO 7 for Pi4J is pin 7 where GPIO 7 based off of the Canakit card is pin 26 with GPIO 4 as pin 7. Dec 29, 2014 at 23:46
  • Are you not using a breadboard? As described the resistor will have no affect as on a standard breadboard positions 29a, 29b, 29c, 29d, and 29e are all connected. Unless the LED has an in-built resistor you are risking the LED and the gpio.
    – joan
    Dec 30, 2014 at 10:01
0

As described the LED has probably burnt out.

Breadboad positions 29e, 29d, 29b, and 29a are all connected together in the breadboard. The resistor would be shorted.

In effect you have 3V3 - LED - Ground.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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