Friday Dec 21, 2012

Quickie Guide Getting Hard-Float Enabled Java Embedded Running on Raspberry Pi

Here's the Quickie Guide in getting the hard-float version of JDK 8 for ARM Early Access running on your Raspberry Pi, and how to compile on the device!

1. Download the Win32DiskImager if you are on Windows, or if your are on a Mac/Linux PC skip this download and use dd instead:

2. Download the RPi Hard-Float Debian Wheezy image from here:

3. Insert a blank SD Card (NOTE: Only use a SD Card from this list) into your Windows or Mac/Linux PC.

4. Use Win32DiskImager on a Windows PC (or on Mac/Linux use "sudo dd if=<path_to_raspian.img> of=/dev/[diskNN|sdd] bs=[1m|4m]" or similar command see: dd ref) to burn the unzipped image from #2 to the SD Card.
(NOTE: After burning the SD Card, it will say the size is ~55MB (or something small like that). That's supposed to be that way and is OK, since the SD Card was imaged to have a swap area on it)

5. Insert the SD Card into your RPi. Connect an Ethernet cable from your RPi Ethernet port to your network. Connect the RPi Power Adapter. (NOTE: Make sure to use your RPi Power Adapter and do not use the USB port of a computer, since only the RPi Power Adapter will have enough current to drive your RPi and the SD Card)

6. The RPi will boot onto your network. Find its IP address by referring to your network DHCP settings or by using Windows Wireshark or the Mac/Linux tcpdump command:
  sudo tcpdump -vv -i[en0|en1|eth0|eth1] port 67 and port 68

7. Download JDK 8 for ARM Early Access (with Hard-Float support):
  NOTE: First click the "Accept License Agreement" button, then choose:
    Linux ARMv6/7 VFP, HardFP ABI "tar.gz" under the "JDK" column

8. scp the bundle from step #7 to your RPi:
   scp <jdk8-zip-bundle> pi@<ip_addr_rpi>:/home/pi
   <Password: "raspberry">

9. ssh to your RPi:
  ssh <ip_addr_rpi> -l pi
  <Password: "raspberry">

10. Untar the bundle from step #8 and rename (move) the toplevel directory to /usr/local/java
   cd /home/pi
   tar zxvf jdk-8-ea-b36e-linux-arm-hflt-29_nov_2012.tar.gz
   sudo mv jdk1.8.0 /usr/local/java
   export PATH=$PATH:/usr/local/java/bin
   java -version
11. Compile on your device!
   cd /home/pi
   cat >
   public class HelloWorld {
     public static void main(String args[]) {
       java.lang.System.out.println("Hello World!");
   java -cp . HelloWorld

Yay! You have the JDK 8 for ARM Early Access (with hardware floating point support!!) on your RPi and can compile Java apps on your device!

Wednesday Dec 19, 2012

RPi and Java Embedded: Hard-Float Support is Here!!!

You wanted Java Embedded with Hardware Floating Point support to install on a default Raspian environment for your Raspberry Pi? Well, you just got your wish. Merry Christmas!


JDK 8 Early Access for ARM w/Hard-Float

Here's a quote:

 The JDK 8 Early Access Release 
 for ARM including JavaFX (JDK 8) on 
 Linux has been made available at The Early 
 Access is provided to the community 
 to get feedback on the ongoing progress 
 of the project. Developers can start 
 developing applications using this 
 build of JDK 8 on an ARM device, 
 such as the a Raspberry Pi.
It's a regular JDK (JDK 8 Early Access) for your Raspberry Pi, so you should note this means there is a javac (and the other typical JDK tools) available to compile your Java apps right there on the device! Woot!

I'll cover step-by-step instructions how to do that in a future blog post. Stay tuned...

Monday Dec 17, 2012

Forbes Article on Big Data and Java Embedded Technology

Whoa, cool! Forbes magazine has an online article about what I've been blogging about all this time: Big Data and Java Embedded Technology, tying it all together with a big bow, connecting small devices to the data center.


Billions of Java Embedded Devices

Here's a quote:

 By the end of the decade we could see 
 tens of billions of new Internet-connected 
 devices... with billions of Internet-
 connected devices generating Big Data, 
 are the next big thing.
 That’s why Oracle has put together an 
 ecosystem of solutions for this new, Big 
 Data-oriented device-to-data center world: 
 secure, powerful, and adaptable embedded 
 Java for intelligent devices, integrated 
This is the next big thing. Java SE Embedded Technology is something to watch for in the new year. Start developing for it now to get a head-start...

Thursday Dec 06, 2012

RPi and Java Embedded GPIO: Sensor Reading using Java Code

And, now to program the Java code for reading the fancy-schmancy static electricity sensor connected to your Raspberry Pi, here is the source code we'll use:

First, we need to initialize ourselves...

 * Java Embedded Raspberry Pi GPIO Input app
package jerpigpioinput;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

 * @author hinkmond
public class JerpiGPIOInput {
    static final String GPIO_IN = "in";
    // Add which GPIO ports to read here
    static String[] GpioChannels = 
    { "25" };
     * @param args the command line arguments
    public static void main(String[] args) {

        try {
            /*** Init GPIO port(s) for input ***/
            // Open file handles to GPIO port unexport and export controls
            FileWriter unexportFile = 
                    new FileWriter("/sys/class/gpio/unexport");
            FileWriter exportFile = 
                    new FileWriter("/sys/class/gpio/export");

            for (String gpioChannel : GpioChannels) {
                // Reset the port
                File exportFileCheck = new File("/sys/class/gpio/gpio"+
                if (exportFileCheck.exists()) {
                // Set the port for use

                // Open file handle to input/output direction control of port
                FileWriter directionFile =
                    new FileWriter("/sys/class/gpio/gpio" + gpioChannel + 
                // Set port for input

And, next we will open up a RandomAccessFile pointer to the GPIO port.

            /*** Read data from each GPIO port ***/
            RandomAccessFile[] raf = new RandomAccessFile[GpioChannels.length];
            int sleepPeriod = 10;
            final int MAXBUF = 256;
            byte[] inBytes = new byte[MAXBUF]; 
            String inLine;
            int zeroCounter = 0;
            // Get current timestamp with Calendar()
            Calendar cal;
            DateFormat dateFormat = 
                    new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS");
            String dateStr;
            // Open RandomAccessFile handle to each GPIO port
            for (int channum=0; channum < raf.length; channum++) {
                raf[channum] = new RandomAccessFile("/sys/class/gpio/gpio"
                        + GpioChannels[channum] + "/value", "r");

Then, loop forever to read in the values to the console.

            // Loop forever
            while (true) {
                // Get current timestamp for latest event
                cal = Calendar.getInstance();
                dateStr = dateFormat.format(cal.getTime());
                // Use RandomAccessFile handle to read in GPIO port value
                for (int channum=0; channum < raf.length; channum++) {
                    // Reset file seek pointer to read latest value of GPIO port
                    inLine = new String(inBytes);
                    // Check if any value was read
                    if (inLine != null) {
                        // Compress 0 values so we don't see too many 
                        //   unimportant lines
                        if (inLine.startsWith("0")) {
                            if (zeroCounter < 1000) {
                            } else {
                                System.out.print(dateStr + ": " + inLine);
                                zeroCounter = 0;
                        } else {
                            // Else, specially mark value non-zero value
                            System.out.print("***" + dateStr + ": " + inLine);
                            zeroCounter = 0;

                    // Wait for a while

        } catch (Exception exception) {

Rinse, lather, and repeat...

Compile this Java code on your host PC or Mac with javac from the JDK. Copy over the JAR or class file to your Raspberry Pi, "sudo -i" to become root, then start up this Java app in a shell on your RPi.

That's it! You should see a "1" value get logged each time you bring a statically charged item (like a balloon you rub on the cat) near the antenna of the sensor. There you go. You've just seen how Java Embedded technology on the Raspberry Pi is an easy way to access sensors.


Hinkmond Wong's blog on making Machine to Machine (M2M) and the Incredible Internet of Things (IoT) smarter with Java Embedded Technologies


« December 2012 »