Using Pi4J with Netbeans Remote Debugging

Since I started with my PI, I have to go trough a lot of reading.

Best IDE for programming JAVA with my Raspberry PI 3 was NetBeans, because it supports remote debugging (an awesome feature to program from my windows computer and deploy and run it at my PI).

Good article found here: Using Oracle Java SE Embedded with Raspberry PI

After installing and configuring my NetBeans, I started with a project.

On this site: Pi4J I found a good API to programm with the GPIO of the Raspberry PI.

I added the Pi4J Library to my System and then followed the instruction on this great video: Let’s Get Physical I/O Programming with Java on the Raspberry PI

Please keep in mind the GPIO Mapping to Pi4J is like this:

pi4j_pins

(Hard time to find out, would be faster if I had read Pi4J Website at PI Model 3B rev 1, but well it was some learning)

To find out, I wrote a program to input PIN Number to activate power or deactivate power on specific GPIO:

private static GpioPinDigitalOutput[] gpioPins;

private static long startTime = System.currentTimeMillis();

public static void main(String[] args) {

if(gpioPins == null)
{
GpioController gpio = GpioFactory.getInstance();
gpioPins = new GpioPinDigitalOutput[40];
gpioPins[0] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_00, “MyLED0”, PinState.LOW);
gpioPins[1] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01, “MyLED1”, PinState.LOW);
gpioPins[2] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_02, “MyLED2”, PinState.LOW);
gpioPins[3] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_03, “MyLED3”, PinState.LOW);
gpioPins[4] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_04, “MyLED4”, PinState.LOW);
gpioPins[5] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_05, “MyLED5”, PinState.LOW);
gpioPins[6] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_06, “MyLED6”, PinState.LOW);
gpioPins[7] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_07, “MyLED7”, PinState.LOW);
gpioPins[8] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_08, “MyLED8”, PinState.LOW);
gpioPins[9] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_09, “MyLED9”, PinState.LOW);
gpioPins[10] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_10, “MyLED10”, PinState.LOW);
gpioPins[11] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_11, “MyLED11”, PinState.LOW);
gpioPins[12] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_12, “MyLED12”, PinState.LOW);
gpioPins[13] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_13, “MyLED13”, PinState.LOW);
gpioPins[14] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_14, “MyLED14”, PinState.LOW);
gpioPins[15] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_15, “MyLED15”, PinState.LOW);
gpioPins[16] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_16, “MyLED16”, PinState.LOW);
gpioPins[17] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_17, “MyLED17”, PinState.LOW);
gpioPins[18] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_18, “MyLED18”, PinState.LOW);
gpioPins[19] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_19, “MyLED19”, PinState.LOW);
gpioPins[20] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_20, “MyLED20”, PinState.LOW);
gpioPins[21] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_21, “MyLED21”, PinState.LOW);
gpioPins[22] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_22, “MyLED22”, PinState.LOW);
gpioPins[23] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_23, “MyLED23”, PinState.LOW);
gpioPins[24] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_24, “MyLED24”, PinState.LOW);
gpioPins[25] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_25, “MyLED25”, PinState.LOW);
gpioPins[26] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_26, “MyLED26”, PinState.LOW);
gpioPins[27] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_27, “MyLED27”, PinState.LOW);
gpioPins[28] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_28, “MyLED28”, PinState.LOW);
gpioPins[29] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_29, “MyLED29”, PinState.LOW);
gpioPins[30] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_30, “MyLED30”, PinState.LOW);
gpioPins[31] = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_31, “MyLED31”, PinState.LOW);
}

do{

try {

System.out.println(“Please enter a PIN to toggle (0-31):”);
BufferedReader buffer=new BufferedReader(new InputStreamReader(System.in));
String line=buffer.readLine();
int number = Integer.parseInt(line);
if(number < 0 || number > 31)

continue;

gpioPins[number].toggle();
System.out.println(“PIN number ” + number + ” turned ” + (gpioPins[number].getState().isHigh() ? “ON” : “OFF”));

} catch (IOException ex) {

Logger.getLogger(HelloWorld.class.getName()).log(Level.SEVERE, null, ex);

}

}
while(System.currentTimeMillis() – startTime < (1000*60*10));

System.out.println(“Program ends…”);

Now I am trying to get a button ready, like supposed in the video.

Advertisements