Skip to content

koert/gpio

Repository files navigation

GPIO

This is a Java API library to access the GPIO ports of a Beagleboard Black.

This is a work-in-progress with the intention of implementing the API in Java with a minimal JNI module in C (necessary for pin interrupt handling).

Implemented:

  • Digital out

  • PWM out

  • Digital in - read value

Example for blinking an LED:

Gpio gpio = new Gpio(new BeagleboneGpioFactory());
BinaryOutputPin pin = gpio.binaryOutputPin(BeagleboneGPio.P9_12);
for (int i=0; i<10; i++) {
    pin.low();
    Thread.sleep(1000);
    pin.high();
    Thread.sleep(1000);
}
pin.low();

Blinking LED

Example for reading and waiting for pin value change:

Gpio gpio = new Gpio(new BeagleboneGpioFactory());
BinaryInputPin pin = gpio.binaryInputPin(BeagleboneGPio.P9_11);
System.out.println("value: " + pin.isHigh());
while(true) {
    pin.waitForEdge(Edge.RISING);
    System.out.println("value2: " + pin.isHigh());
}

PWM

Example for PWM output:

Gpio gpio = new Gpio(new BeagleboneGpioFactory());
PwmOutputPin pin = gpio.pwmOutputPin(BeagleboneGPio.P9_22);
for (int i=0; i<10; i++) {
    for (int j=15; j<=1000; j++) {
        pin.dutyCycle((float) j/1000);
        Thread.sleep(1);
    }
    for (int j=1000; j>=15; j--) {
        pin.dutyCycle((float) j/1000);
        Thread.sleep(1);
    }
}
pin.dutyCycle(0);
pin.close();

About

Java API for GPIO (Beaglebone Black)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published