Installing the SoftwareFirst of all the software required must be installed on the Raspberry Pi:
- Install PI4J.
curl -s get.pi4j.com | sudo bash
- Set up the Raspberry for i2c communication.
- Install the Oracle JDK (if not already installed).
sudo apt-get install oracle-java8-jdk
- Ensure that the Oracle JDK is the one in use (use java –version to verify).
If not change so that it is. There can be a massive performance difference.
- Clone the robo4j repo.
git clone https://github.com/Robo4J/robo4j.git
- Run gradlew build in the robo4j root directory.
- Install Eclipse (optional, but good if you want to play around with the examples a bit).
apt-get install eclipse
Setting up Eclipse (Optional)For an easy way to play around with the examples, we can set up Eclipse on our Raspberry Pi.
- Install Egit.
Inside of Eclipse, go to Help | Install New Software…
Add a new update site with the following URL:
- Install the Gradle plug-in.
- Go to Robo4J on GitHub and clone the repo using Egit from within Eclipse.
- Import the projects into Eclipse.
Normally you would probably like to develop in a more modern version of Eclipse (or some other IDE) and just use the command line to build robo4j.
Running the DemosThere are two ways of running the demos. One through building the robo4j.jar file with Gradle, and one through Eclipse.
Here is how you would, for example, run the LCD demo using the robo4j.jar built by gradle:
sudo java –classpath robo4j-hw-rpi/build/libs/robo4j-hw-rpi-alpha-0.2.jar:/opt/pi4j/lib/* com.robo4j.hw.rpi.i2c.adafruitlcd.DemoIf you are playing around with the code in Eclipse, do the following:
- With Eclipse started, open a command line and change directory to the robo4j/robo4j-hw-rpi/bin folder.
- Search for the demo/example corresponding to the hardware set up you want to test in the examples folder in the eclipse project.
For example, if you have an Adafruit LCD shield, you would use the com.robo4j.hw.rpi.i2c.adafruitlcd.Demo class.
- Run the demo from the command line.
Do not forget to add the PI4J classes to the classpath, for example:
sudo java –classpath .:/opt/pi4j/lib/* com.robo4j.hw.rpi.i2c.adafruitlcd.Demo