Book Image

Raspberry Pi 3 Projects for Java Programmers

By : Rajdeep Chandra, John Sirach, Pradeeka Seneviratne
Book Image

Raspberry Pi 3 Projects for Java Programmers

By: Rajdeep Chandra, John Sirach, Pradeeka Seneviratne

Overview of this book

Raspberry Pi is a small, low cost and yet very powerful development platform. It is used to interact with attached electronics by the use of it's GPIO pins for multiple use cases, mainly Home Automation and Robotics. Our book is a project-based guide that will show you how to utilize the Raspberry Pi's GPIO with Java and how you can leverage this utilization with your knowledge of Java. You will start with installing and setting up the necessary hardware to create a seamless development platform. You will then straightaway start by building a project that will utilize light for presence detection. Next, you will program the application, capable of handling real time data using MQTT and utilize RPC to publish data to Further, you will build a wireless robot on top of the zuma chassis with the Raspberry Pi as the main controller. Lastly, you will end the book with advanced projects that will help you to create a multi-purpose IoT controller along with building a security camera that will perform image capture and recognize faces with the help of notifications. By the end of the book, you will be able to build your own real world usable projects not limited to Home Automation, IoT and/or Robotics utilizing logic, user and web interfaces.
Table of Contents (8 chapters)
Integrating a Real-Time IoT Dashboard

Getting started with the Raspberry Pi

With the release of the Raspberry Pi 3, the Raspberry Pi foundation has made a very big step in the history of the Raspberry Pi. The current hardware architecture is now based on a 1.2 GHz 64 bit ARMv7. This latest release of the Raspberry Pi also includes support for wireless networking and has an onboard Bluetooth 4.1 chip available.

Even though the Raspberry Pi 3 has 64-bit ARMv8, the operating system of the Raspberry Pi which is Raspbian confusingly report it is an 32-bit ARMv7. This is because of the Raspbian OS is currently only available in 32-bit.

To get started with the Raspberry Pi you will need the following components:

  • Keyboard and mouse: Having both a keyboard and mouse present will greatly help with the installation of the Raspbian distribution. Almost any keyboard or mouse will work.
  • Display: You can attach any compatible HDMI display, which can be a computer display or a television. The Raspberry Pi also has composite output shared with the audio connector. You will need an A/V cable if you want to use this output.
  • Power adapter: Because of all the enhancements made, the Raspberry Pi foundation recommends a 5V adapter capable of delivering 2.5 A. You would be able to use a lower-rated one, but I strongly advise against this if you are planning to use all the available USB ports. The connector for powering the device uses a micro USB cable.
  • MicroSD card: The Raspberry Pi 3 uses a MicroSD card. I would advise using at least an 8-GB class 10 version. This will allow us to use the additional space to install applications, and as our projects will log data, you won't be running out of space soon.
  • The Raspberry Pi 3: Last but not least, a Raspberry Pi 3. Some of our projects will be using the on-board Bluetooth chip, and this version will also be focused on in this book.

Our first step will be preparing a SD card for use with the Raspberry Pi. You will need a MicroSD card as the Raspberry Pi 3 only supports this format. The preparation of the SD card is being done on a normal PC, so it is wise to purchase one with an adapter fitting a full-size SD card slot. There are webshops selling preformatted SD cards with the NOOBS installer already present on the card. If you have bought one of these preformatted cards you can skip to the Installing Raspbian section.

Getting a compatible SD card

There is a large number of SD cards available. The Raspberry Pi foundation advises an 8-GB card, which leaves space to install different kinds of application and supplies enough space for us to write log data. When you buy an SD card, it is wise to keep your eyes open for the quality of these cards. Well-known and established manufacturers often supply better quality than the counterfeit ones. SD cards are sold with different class definitions. These classes explain the minimal combined read and write speeds. Class 6 should provide at least 6 MB/s, and class 10 cards should provide at least 10 MB/s. There is a good online resource available that provides tested results of using SD cards with the Raspberry Pi. If you need a resource to check for compatible SD cards, I advise you to go to the embedded Linux page at

Preparing and formatting the SD card

To be able to use the SD card, it first needs to be formatted. Most cards are already formatted with the FAT32 filesystem, which the Raspberry Pi NOOBS installer requires, unless you have bought a large SD card it is possible it is formatted with the exFAT filesystem. These then should also be formatted as FAT32. To format the SD card, we will be using the SD association's SDFormatter utility, which you can download from, as default OS supplied formatters do not always provide optimal results.

In the following screenshot, the SDFormatter for the Mac is shown. This utility is also available for Windows and has the same options. If you are using Linux, you can use GParted. Make sure when using GParted you use FAT32 as the formatting option. As shown in the screenshot, select the Overwrite format option and give the SD card a label. The example shows RPI3JAVA, but this can be the label of your choice so you can quickly recognize the card when it's inserted:

Press the Format button to start formatting the SD card. Depending on the size of the SD card, this could take some time, enabling you to get a cup of coffee. The utility will show a done message in the form of Card Format complete when the formatting is done. You will now have a usable SD card.

To be able to use the NOOBS installer, you will need to follow the following steps:

  1. Download the NOOBS installer from
  2. Unzip the file with your favorite unzip utility. Most OSes already have one installed.
  3. Copy the contents of the unzipped file into the SD card's root directory so that the copy result is as shown in the following screenshot:
When selecting the NOOBS for download, only select the lite version if you do not mind installing Raspbian using the Raspberry Pi's network connection.

After we have copied the required files into the SD card, we can start installing the Raspbian OS.