ch.eitchnet.beaglebone
Go to file
dependabot[bot] 0189488c22
Bump junit from 4.12 to 4.13.1 (#3)
Bumps [junit](https://github.com/junit-team/junit4) from 4.12 to 4.13.1.
- [Release notes](https://github.com/junit-team/junit4/releases)
- [Changelog](https://github.com/junit-team/junit4/blob/main/doc/ReleaseNotes4.12.md)
- [Commits](https://github.com/junit-team/junit4/compare/r4.12...r4.13.1)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-10-13 11:39:14 +02:00
src/main/java/ch/eitchnet/beaglebone [Project] Updated README for new interface GpioBridge 2017-03-06 10:09:53 +01:00
.gitignore Merge request which fix #1 (#2) 2017-03-06 09:20:58 +01:00
LICENSE Initial commit 2016-01-06 17:20:59 +01:00
README.md [Project] Updated README for new interface GpioBridge 2017-03-06 10:09:53 +01:00
compile_dts.sh [New] Major refactoring 2016-02-05 16:40:35 +01:00
deploy.sh [Prohect] Updaded release scripts 2017-03-06 10:13:01 +01:00
exportPins.sh [New] Major refactoring 2016-02-05 16:40:35 +01:00
hotfix.sh [Prohect] Updaded release scripts 2017-03-06 10:13:01 +01:00
pinctrl-eitchnet.dts [New] Major refactoring 2016-02-05 16:40:35 +01:00
pinctrl-test-0.dts [New] Major refactoring 2016-02-05 16:40:35 +01:00
pom.xml Bump junit from 4.12 to 4.13.1 (#3) 2020-10-13 11:39:14 +02:00
release.sh [Project] added release/deploy scripts 2016-11-14 09:39:15 +01:00
setOutPin.sh [New] Major refactoring 2016-02-05 16:40:35 +01:00
setVersion.sh [Project] added release/deploy scripts 2016-11-14 09:39:15 +01:00

README.md

BeagleBoneBlack Java Pin Bridge

This is a pure Java library to access the GPIO pins of a BeagleBoneBlack.

The main component is the GpioBridge which is a singleton. A client will retrieve the instance via the GpioBridge.getInstance() method and then manipulate the GPIOs.

Features are:

  • Reading and writing of pins
  • Registering for input pin changes (currently implemented as file-polling)
  • Thread-safe
  • Simple model for hardware: Pin, Gpio, Signal, Direction
  • Clear exception handling for user and configuration errors (GpioException)
  • No 3rd party dependencies - plain Java SE

If you have any issues, don't hesitate to add an issue to the GitHub project, write me an e-mail (eitch@eitchnet.ch) or reach me on Twitter!

Java API

Before trying to use the Java API and wondering why it does not work, be very careful to ensure that the GPIOs are properly exported to userspace by using a device tree overlay and then using the /sys/class/gpio/export file to export the GPIO to userspace.

The Java API is simple and requires no configuration files. Everything is done programmitically. The main object is the GpioBridge instance which is retrieved as follows:

GpioBridge gpioBridge = GpioBridge.getInstance();

With a reference to the GpioBridge, GPIO objects can be retrieved by their Pin enum and a Direction as follows:

GpioBridge gpioBridge = GpioBridge.getInstance();
Gpio pin8_07 = gpioBridge.getGpio(Pin.P8_07, Direction.IN);

The GpioBridge.getGpio()-method will throw an exception if:

  • the requested direction does not correspond to the direction configured in the kernel's exported pin
  • the file permissions are not set so that the Java process can access the file (read access for input pin, write access for output pin.

Reading Input Pins

To read the current signal of a pin use the GpioBridge.readValue()-method:

GpioBridge gpioBridge = GpioBridgeImpl.getInstance();
Gpio pin8_07 = gpioBridge.getGpio(Pin.P8_07, Direction.IN);
Signal currentSignal = gpioBridge.readValue(pin8_07);
System.out.println(pin8_07 + " currently has signal " + currentSignal);

Writing Output Pins

To write the signal of a pin use the GpioBridge.writeValue()-method:

GpioBridge gpioBridge = GpioBridgeImpl.getInstance();
Gpio pin8_08 = gpioBridge.getGpio(Pin.P8_08, Direction.OUT);
gpioBridge.writeValue(pin8_08, Signal.HIGH);
System.out.println("Set signal of " + pin8_08 + " to " + Signal.HIGH);

Observing Input Pins

To be notified of changes to an input GPIO, register a GpioSignalListener:

GpioBridge gpioBridge = GpioBridgeImpl.getInstance();
Gpio pin8_07 = gpioBridge.getGpio(Pin.P8_07, Direction.IN);
gpioBridge.register(pin8_07, gpio -> System.out.println("Signal of "+pin8_07 + " has changed to " + gpio.getSignal()));

Setup BeagleBone

  • Copy the scripts and files to the BeagleBone:
rsync -a *.sh *.dts ubuntu@beaglebone:.
  • Configure the GPIOs in the kernel driver by: ** Compile the device tree using: ./compile_dts.sh ** Enable the device tree overlay at boot by editing /boot/uEnv.txt:
##Example v4.1.x
#cape_disable=bone_capemgr.disable_partno=
cape_enable=bone_capemgr.enable_partno=pinctrl-eitchnet
  • Export the GPIO pins to userspace using: ./exportPins.sh

If you have a LED properly connected, then you can use the script ./setOutPin.sh to set the state of the pin.

Build Java Bridge

To build the Java bridge, Apache Maven 3.0 is used. This can be done on normal PC, the resulting JAR can then be copied to the BeagleBone:

mvn clean package
rsync target/BeagleBone.jar ubuntu@beaglebone:.

Circuit requirements:

The circuit consists of three buttons (green, blue and red) and 6 LEDs. (2x green, 3x yellow, 1x red).

To use the JavaBridge example unchanged, you need to attach the components as follows:

Buttons (Input):

  • P8_07 = green0
  • P8_08 = blue0
  • P8_09 = red0

LEDs (Output):

  • P8_10 = green0
  • P8_11 = yellow0
  • P8_12 = yellow1
  • P8_14 = yellow2
  • P8_15 = green1
  • P8_16 = red1

How a LED or a button is safely attached to the BeagleBone is explained online:

Running

Once the JAR is on the BeagleBone, running is as follows:

java -jar BeagleBone.jar

Further reading: