Giter Site home page Giter Site logo

boothgibson / raspberry-pi4j-samples Goto Github PK

View Code? Open in Web Editor NEW

This project forked from olivierld/raspberry-coffee

0.0 0.0 0.0 127.09 MB

JVM related (Java, Groovy, Scala, Kotlin, etc) samples for the Raspberry PI, relying on PI4J. IoT and friends.

Home Page: http://raspberrypi.lediouris.net/

C 0.22% C++ 1.97% Shell 1.73% JavaScript 35.28% HTML 6.82% Java 47.17% Batchfile 0.07% CSS 0.75% Processing 0.29% Scala 0.46% Clojure 0.02% Groovy 0.04% Kotlin 0.09% Python 0.10% XSLT 4.86% PHP 0.09% Go 0.05%

raspberry-pi4j-samples's Introduction

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, make sure the script named gradlew is executable, and execute gradlew.

 Prompt> chmod +x gradlew
 Prompt> ./gradlew --daemon build

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. 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.

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. I found it actually faster and more efficient than developing directly on the Raspberry PI.

Something to keep in mind

Java - and other JVM Languages - implement 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.


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.

raspberry-pi4j-samples's People

Contributors

olivierld avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.