JVM related (Java, Groovy, Scala, Kotlin, etc) samples for the Raspberry PI, relying on PI4J. IoT and friends.
Java JavaScript HTML XSLT Shell C++ Other
Switch branches/tags
Nothing to show
Clone or download
Olivier LeDiouris
Olivier LeDiouris TextArea line wrap
Latest commit aa88b7f Jul 20, 2018
Permalink
Failed to load latest commit information.
ADC-benchmark Update diagrams Jul 3, 2018
ADC Doc and cleanup Jul 20, 2018
Adafruit.IO.REST PWS, threads Jul 1, 2018
AlaMode.101 Tweaked gradle plugins Jun 3, 2018
Arduino.BatterySpy With diagrams Jan 19, 2018
Arduino.RaspberryPI Doc and stuff Jun 11, 2018
C C and JNI Aug 4, 2017
Camera Tweaked gradle plugins Jun 3, 2018
DAC Tweaked gradle plugins Jun 3, 2018
Demos Put the REST request managers in a List Aug 30, 2017
FONA Script Jul 6, 2018
GPIO.01 Tweaked gradle plugins Jun 3, 2018
GPS.read Big cleanup and refactoring Jan 18, 2018
GPS.sun.servo Tweaks in the Adafruit-IO REST forwarder Mar 6, 2018
GPSandSun PWS, threads Jul 1, 2018
HanoiTower ShadowJar Jun 3, 2018
HomeRemoteControl JavaScript tweaks Sep 7, 2017
I2C.SPI updated Kotlin stuff Jul 17, 2018
JNISample Big cleanup and refactoring Jan 18, 2018
JavaSoundDemo WebComponents, thermometer Feb 12, 2018
LelandOilDetector Implemented NotOnRaspberryPIException when needed May 16, 2018
LoRa Cleanup the serial libs Jan 19, 2018
MindWave Retrying web socket connection in case of failure Jan 31, 2018
Monitor.Battery Doc Mar 15, 2018
NMEA.multiplexer Doc and Co Jul 19, 2018
OtherJVM.languages Clojure back on track May 30, 2018
PI4J.email Tweaked gradle plugins Jun 3, 2018
PIR Ah Jun 10, 2018
Papers Added the main highlights Jul 16, 2018
Papirus Twix Feb 10, 2018
PhoneKeyboard3x4 Keypad membrane Jun 4, 2018
PlantWateringSystem Refactored the http.HTTPServer Jul 18, 2018
Processing.Scala Small tweaks Jun 19, 2018
Processing Generic Display, Processing Jun 22, 2018
PurePWM updated Kotlin stuff Jul 17, 2018
Python.101 Servos PWM tweaks Jul 12, 2018
RESTCam Refactored the http.HTTPServer Jul 18, 2018
RESTImageProcessor Refactored the http.HTTPServer Jul 18, 2018
RESTNauticalAlmanac Refactored the http.HTTPServer Jul 18, 2018
RESTNavServer Refactored the http.HTTPServer Jul 18, 2018
RESTRouting Refactored the http.HTTPServer Jul 18, 2018
RESTTideEngine Refactored the http.HTTPServer Jul 18, 2018
RGB-Led Big cleanup and refactoring Jan 18, 2018
RMI.sample Big cleanup and refactoring Jan 18, 2018
RangeSensor Ah Jun 10, 2018
RasPISamples Refactored the http.HTTPServer Jul 18, 2018
ReadSerialPort Source formatting May 25, 2018
Relay.by.email Big cleanup and refactoring Jan 18, 2018
Relay.by.http Big cleanup and refactoring Jan 18, 2018
Relay GPIO interaction Jun 16, 2018
Serial.IO Cleanup the serial libs Jan 19, 2018
SerialRxTx Cleanup the serial libs Jan 19, 2018
SevenSegDisplay Tweaked gradle plugins Jun 3, 2018
Small.Boards Doc and stuff Jun 11, 2018
SunFlower Refactored the http.HTTPServer Jul 18, 2018
TensorFlow TensorFlow stuff Jul 13, 2018
TwoLeds Big cleanup and refactoring Jan 18, 2018
WeatherStation Sensor working, some refactoring Jun 13, 2018
WebComponents Small tweaks Jun 19, 2018
common-image-utils Big cleanup and refactoring Jan 18, 2018
common-utils TextArea line wrap Jul 20, 2018
docker Weather Data Jun 8, 2018
gradle/wrapper Serious cleanup Oct 27, 2017
oliv.scratch.pad Main index, and other stuff Jul 16, 2018
system.utils Big cleanup and refactoring Jan 18, 2018
ukulele Big cleanup and refactoring Jan 18, 2018
.gitignore Minified, so-so with ES6 Feb 27, 2018
README.md Added the main highlights Jul 16, 2018
build.gradle Added a TensorFlow directory Jul 13, 2018
config.txt Added SunData only Mar 3, 2018
config.txt.full Added SunData only Mar 3, 2018
config.txt.tft Added SunData only Mar 3, 2018
gradle-app.setting Nokia 5110/3110 Jan 18, 2016
gradle.properties Tweaked gradle plugins Jun 3, 2018
gradlew Gradle Wrapper Dec 14, 2015
gradlew.bat Gradle Wrapper Dec 14, 2015
makeall More options if the ScreenBuffer Jan 24, 2016
proxy.set After reset Dec 14, 2015
proxy.unset After reset Dec 14, 2015
raspberrypi.png Cleanup in gitignore Jul 19, 2017
scala.install Serial close on Mac Oct 28, 2017
set.gradle.env Added Stepper Motor Demo Jul 30, 2016
settings.gradle Added a TensorFlow directory Jul 13, 2018
switch2fullscreen Communication mechanism in place Oct 17, 2017
switch2tftscreen Communication mechanism in place Oct 17, 2017

README.md

Raspberry Coffee

Java code and wiring for the Raspberry PI, featuring reusable libraries and snippets

It uses the PI4J library.


This project contains Java code, mostly translated from Python, dedicated to usually one board (like BMP180, LSM303, etc). More consistent samples can be found in the RasPISamples project, where several components have been assembled together. Do take a look, it also comes with a readme file.



Note: Java code is compiled into class files, that run on a Java Virtual Machine (JVM). Java is not the only language that runs a JVM, this project also contains some small samples of other JVM-aware languages, invoking and using the features of this project.

Those samples include Scala, Groovy, Kotlin..., and the list is not closed!

See in the OthetJVM.languages directory.


Note: This project uses gradle and git. Gradle will be installed automatically if it is not present on your system, it uses the gradle wrapper (gradlew).

Git is usually installed on Linux and Mac, but not on Windows. On Windows, you need to install the git bash shell, and run in it the commands mentioned in this document.


To build it, clone this project (this repo), make sure the script named gradlew is executable, and execute gradlew.

 Prompt> git clone https://github.com/OlivierLD/raspberry-pi4j-samples.git
 Prompt> cd raspberry-pi4j-samples
 Prompt> chmod +x gradlew
 Prompt> ./gradlew [--daemon] build

You are expecting an end like that one:



BUILD SUCCESSFUL in 55s
97 actionable tasks: 17 executed, 80 up-to-date
Prompt>

See the gradle web site for info about Gradle.

We will also be using the shadowJar gradle plugin is several projects. This plugin is aggregating the required classes and all their dependencies into a single archive, called a fat Jar. This simplifies the syntax of the classpath.

Typically, this operation will be run like this:

 Prompt> cd RESTNavServer
 Prompt> ../gradlew shadowJar

The expected archive will be produced in the local build/libs directory.

Important : If JAVA_HOME is not set at the system level, you can set it in set.gradle.env and execute it before running gradlew:

 Prompt> . ./set.gradle.env

Note: If you are behind a firewall, you need a proxy. Mention it in all the files named gradle.propetries, and in all the build.gradle scripts, uncomment the following two lines:

// ant.setproxy(proxyhost: "$proxyHost", proxyport: "$proxyPort") //, proxyuser="user", proxypassword="password")
// compileJava.dependsOn(tellMeProxy)

Developing on the Raspberry PI, or Developing for the Raspberry PI ?

To write code, the simplest editor is enough. I have used vi for ages, mostly because this was the only one available, but also because it is indeed good enough. vi is available on the Raspberry PI, nano too, graphical editors like gedit, geany are even easier to use, on a grahical desktop.

All the code provided here can be built from Gradle (all gradle scripts are provided), on the Raspberry PI itself. The Raspberry PI is self sufficient, if this is all you have, nothing is preventing you from accessing all the features presented here.

But let us be honest, Integrated Development Environments (IDE) are quite cool. In my opinion, IntelliJ leads the pack, and Eclipse, JDeveloper, NetBeans follow. Cloud9 provides amazing features, on line. Smaller ones like GreenFoot, BlueJ are also options to consider.

Those two last ones might be able to run on a Raspberry PI, but forget about the others..., they use way too much RAM. The features they provide definitely increase productivity, and when you use them, you learn as you code. Code-insight, auto-completion and similar features are here to help. And I'm not even talking about the remote debugging features they provide as well.

So, as the Raspberry PI is not the only machine on my desk, I develop on a laptop using IntelliJ (with several GigaBytes of RAM, like 8, 16, ...), and I use scp to transfer the code to (and possibly from) the Raspberry PI. Worst case scenario, I do a git push from the development machine, and a git pull from the Raspberry PI. I found it actually faster and more efficient than developing directly on the Raspberry PI.

Something to keep in mind

The Java Virtual Machine (JVM) implements the Java Platform Debugging Architecture (JPDA). This allows remote debugging. In other words, you run the code on the Raspberry PI, but you debug it (set breakpoints, introspect variable values, etc) on another machine (the one where the IDE runs). This is specially useful when the code interacts with sensors and other devices that are not supported from the laptop. This will make your life considerably easier than if you used another language missing it (like Python, C, and many others). It uses TCP between the debugger and the debuggee.


Raspberry PI, a possible thing of the Internet of things...

  • The Raspberry PI is a fully featured Linux computer, which can - as such - connect to the Internet.
  • The Raspberry PI has a General Purpose Input Output (GPIO) interface that allows it to drive all kind of electronic components, from a simple LED to a complex robot, and including all kind of sensors (GPS, light resistors, pressure sensors, temperature sensors, all kinds!). None of the above is new. Connecting to the Internet does not impress anyone anymore. Driving a robot, modern kitchens are full of robots, cars are loaded with electronic components... But what if we put those two together, with the Raspberry PI sitting in between. Then, we can drive a robot over the Internet. And this is not that usual (yet).

The snippets provided in this project are here to help in this kind of context. Some will use the network aspect of the story, some others will interact with electronic components. The two aspects should be easy to bridge, that is the goal. If that was not the case, please let me know (email address of the left side).


Several projects are featured here:

  • Basic GPIO interaction
  • Two Leds
  • Use the Raspberry PI to turn LEDs on and off, through email (with doc)
  • Read Serial Port (with doc)
  • Read and parse NMEA Data from a GPS (with doc)
  • Read analog data with an Analog Digital Converter (ADC). (with doc, with node.js and WebSocket)
  • Drive servos using the PCA9685. (with doc).
  • Drive servos using the PCA9685, over the Internet, with an Android client option. (with doc).
  • Use the LSM303. (I2C compass & accelerometer, with doc).
  • Use the BMP180. (I2C temperature and pressure sensor, with doc).
  • Use the BMP183. (SPI temperature and pressure sensor, with doc).
  • Use a relay, through email. (with doc).
  • Use a relay, through HTTP. (with doc).
  • Use a seven-segment display. (with doc).
  • Use the VCNL4000 (I2C proximity sensor).
  • Use the TCS34725 (I2C color sensor, demo).
  • Use the TSL2561 (I2C light sensor).
  • Use the L3GD20 (I2C gyroscope, demo).
  • Use the MCP4725 (I2C Digital to Analog Converter, demo).
  • ... and more.

All the doc - with more details than here - can be reached from this page.