Raspberry Pi with Java: Programming the Internet of Things (IoT)
Thursday, December 10, 2015 at 5:15PM
Robert Savage in Embedded Computing, Java, JavaFX, Pi4J, Raspberry Pi, Raspberry Pi, gpio, i2c, java, pi4j, raspberry, serial, spi, uart

Book Review - Raspberry Pi with Java: Programming the Internet of Things (IoT)
by Stephen Chin and James L. Weaver

Buy On Amazon > (~ $21.64 USD)


I had the opportunity to read this book cover to cover and can confidently say that it provides an excellent primer for any hobbyist or professional developer getting started with the Raspberry Pi with a focus on Java development.  Fundamentally, this book is a compilation of projects that demonstrate various integrations where Java can be used with the Raspberry Pi to produce some functional "product".  Along the way each project gets increasingly more complex thus exposing the reader to more sophisticated integration capabilities and techniques.  While some projects seem daunting, the authors meticulously walk the reader through all the necessary environment configuration settings, development environment configuration, and build steps.  

To clarify what this book is not ...  This book is not a programmer's reference guide.  It is not intended to provide a comprehensive reference for available APIs and libraries.  It is not an exhaustive textbook covering every development pattern and/or capability of Java on the Raspberry Pi platform.  This book does not teach you Java programming.  If you are new to Java, I would suggest getting some other books or online introductory courses to learn the basics of Java programming and then use this book to to get started with Java on the Raspberry Pi.

The book takes a fun and sometimes whimsical approach while sneaking in some educational instruction along the way.  Personally, I prefer this type of example-based learning approach.  I find that engaging in sample projects with concrete goals helps me better understand the subject at hand and seeing a completed project provides a more comprehensive end-to-end understanding. 

Chapter 1: Baking Pi


If you are new to the Raspberry Pi platform, then this is the chapter for you.  This chapter covers all the prerequisites required to power the Raspberry Pi, build a bootable SD (or microSD) card, installing the Linux-based Raspbian operating system, connecting the Raspberry Pi to the network, configuring default system settings and running your first "Hello World" Java application on the Pi.  If you are a Raspberry Pi veteran, then you can probably skip this chapter; however, if you have not run a Java program on your Raspberry Pi before, then at least start on Page 24 with the section "Creating A Simple Raspberry Pi Application".  

Chapter 2: Your First Java Project


This chapter focuses on a Java project that helps to brew the prefect cup of coffee.  This project integrates with a USB scale attached to the Raspberry Pi.  The Java program prompts the user through weighing just the right amount of coffee beans, adding a specific volume of water, and providing a countdown timer for the coffee extraction period.  Who knew that making a good cup of "joe" requires such precise measurement, timing, and formulas!  

The project demonstrates how to leverage the usb4java libraries to communicate with an external hardware scale and take measurements of weight in a Java program. 

Chapter 3: Binary Timer


This chapter is probably my favorite chapter.  This chapter teaches the reader how to construct simple/basic circuits and interface to the GPIO (general purpose input/output) pins on the Raspberry Pi.  Interfacing with the GPIO pins is probably one of the most powerful and rewarding experiences for a new Java programmer entering the world of embedded devices.  Harnessing the GPIO pins allows a Java program to interact with the real/physical world.  Buttons, LEDs, Sensors, Switches, Relays, etc can all be controlled or sensed via circuits that connect to the GPIO pins.  Of course, since I started the Pi4J project it probably comes as no surprise that this is my favorite chapter :-)

The project in this chapter focuses on building a timer that displays its current countdown time in a binary pattern using LED lights, but the underlying objective is to teach the reader about GPIO inputs and outputs and some of the various nuances such as button debouncing.  This chapter introduces both the open source Pi4J project and the OpenJDK DIO project as libraries to instrument and communicate from Java with the hardware GPIO interface.  The authors do a nice job of explaining each of the libraries and the pros and cons of each.  The book also provides instructions and example code using both libraries so you can familiarize yourself with each.  

Please see the section titled "Recent Updates to Pi4J" at the end of this article to provide a bit of updated information on the Pi4J project since the time of this books writing.

Chapter 4: IoT Hat


This chapter's project ostensibly recreates a magician's card trick of mind reading to determine the audience member's selected card from a stack of playing cards.  This project uses an RFID reader connected to the Raspberry Pi hidden inside a magician's top hat and RFID tagged playing cards to accomplish the illusion.  This chapter is really teaching you how to interface from the Raspberry Pi to a more sophisticated hardware device such as a RFID reader using each of the data communication busses on the Pi: Serial (UART), SPI (Serial Peripheral Interface), and I2C (Inter-Integrated Circuit).  This chapter is important because communicating over each of these data busses significantly expands the world of possibilities for your project to interface with more complex chips and devices.  While this chapter does not cover Java programming directly using these busses (it uses a NFC library project instead), it does at least familiarize you with the physical connections and the operating system level configurations required for each of the data busses.  Java programming to communicate on these data busses is illustrated in later chapters.

This chapter suggests using the Raspberry Pi Model A+; however, the recent introduction of the Raspberry Pi Zero model may provide a smaller form factor and may be easier to disguise and affix to the hat. 

Chapter 5: Line Runner


In this chapter we encounter our first foray into robotics!  Here we build a robotic vehicle to autonomously navigate a line marked path using an array of sensors to determine if we are on or off course and sensors to determine distance to an object ahead to avoid a collision.  This chapter teaches you how to use PWM (pulse-width-modulation) capabilities to control the drive motors of the robotic vehicle, GPIO pins to sense inputs from the line follower and distance sensors, and serial (UART) data communication to accept input from an infrared remote control.  

Chapter 6: Tea Station


This chapter takes the coffee brewing project from the first chapter to the next level for brewing tea.  This tea brewing project demonstrates using a serial connected scale with greater precision and adds a temperature sensor for measuring the temperature using a 1-Wire interface.  The project also introduces our first JavaFX project where we can create a much improved graphical based user interface.  

Chapter 7: Autonomous Drone


This chapter demonstrates using a Raspberry Pi and Java to add some degree of pre-programmed autonomous flight to a drone.  The reader is introduced to the Parrot AR drone library and the autonomous4j library in this chapter. 

Chapter 8: Retro Video Game Emulator


This chapter walks the reader through creating a complete portable gaming emulator platform using the Raspberry Pi.  This chapter will really start to test your maker skills when it comes to soldering and wiring.     

Chapter 9: NightHacking RetroPi


The final chapter builds on the gaming emulator project created in Chapter 8 to create a 3D printed plastic case to mount all of the electronics and switches to finalize your Raspberry Pi based portable gaming system.


I think this is a great book for any Java programmer just getting started on the Raspberry Pi platform.   The book does a good job of providing detailed and comprehensive instructions, wiring diagrams, and illustrations for each project.  The only technical area that I wish the book took a deeper dive would be more detailed instruction and demonstration on using the SPI and I2C data bus communications from a Java program.  This is a slightly more advanced topic but it does add a lot more extensibility for the would-be maker.

Follow Up: Recent Updates to Pi4J

The Pi4J project, like any open source project, continues to march forward with new features and improvements.  Since the time of this book’s writing there are a few noteworthy updates to Pi4J to point out:

All of these improvements are included in the current Pi4J 1.1-SNAPSHOT builds and available at: http://pi4j.com/download.html


Buy On Amazon (~ $21.64 USD)

Title: Raspberry Pi with Java: Programming the Internet of Things (IoT)
Authors: Stephen Chin and James L. Weaver
Print Length: 336 pages
Publisher: McGraw-Hill Education; 1 edition (October 23, 2015)
Publication Date: October 23, 2015
Language: English
ISBN-13: 978-0071842013
ISBN-10: 0071842012



Thank You for your support.
Article originally appeared on SHA (http://www.savagehomeautomation.com/).
See website for complete article licensing information.