Configuring the Raspberry Pi as an Oracle Java ME Embedded Development Platform

 

Overview

Purpose

This tutorial covers how to configure a Raspberry Pi as a development platform for the Oracle Java ME Embedded 8 platform.

Time to Complete

Approximately 1 hour

Introduction

Intelligent devices are becoming an ever more important and ubiquitous part of our everyday lives. Mobile phones represented the first wave of smaller personal computers. And now, as the price of electronics and processing power continues to fall, there is an intersection between sensors and other electromechanical devices and computers that live on the edge of the Internet: close to the source of the data, processing the data locally and sending just what is required to other computers to consume. This wave of machine-to-machine (M2M) technology, or more broadly, the Internet of Things (IoT), is rapidly shaping the future of computing. Oracle Java Platform, Micro Edition (Java ME) provides Java developers with a direct path to this new market space by using their existing knowledge and skills.

In this tutorial, you prepare a Raspberry Pi to run Java ME Embedded 8, the released version of Java ME Embedded. The Raspberry Pi is a computer that is about the size of a deck of cards, yet it is capable of running a Linux distribution on its ARM 11 processor. The Raspberry Pi also supports USB, Ethernet, audio, HDMI, and RCA video output. But most importantly, the Raspberry Pi provides a 26-pin header that connects the computer to the outside world, through general-purpose input/output (GPIO) pins that can drive LEDs, read switches and other electronic signals, and connect to a wealth of inter-integrated circuit (I2C) devices, universal asynchronous receiver/transmitter (UART) devices, and more.

Hardware and Software Requirements

The following is a list of hardware and software requirements:

Prerequisites

Before starting this tutorial, you should:

  • Install Java JDK 8, Java ME SDK 8, NetBeans IDE, and plugins for Java ME SDK. See this supporting video.
  • Download and install the following software:
    • SD Formatter tool
    • SHA-1 checksum verifier
    • Win32DiskImager
    • PuTTY client
    • PSFTP client
  • Download the Oracle Java ME Embedded 8 Raspberry Pi binary zip file to the C:\Temp directory.
 

Creating a Bootable Image for the Raspberry Pi

In order to boot, the Raspberry Pi requires a bootable Linux image on an SD memory card. There is no hard drive for the computer. Instead, the 4 GB card stores the image that the computer runs when it is powered on. This SD memory card also acts as the storage for other applications that are loaded onto the card.

 

Formatting the SD Memory Card with the SD Formatter Tool

  1. Insert the SD memory card into your computer or connect it to your computer by using an SD card peripheral.

  2. Start the SD Formatter tool and click Option.

    SD Formatter Tool
  3. In the Option Setting dialog box, select FULL (Overwrite) for Format Type and ON for Format Size Adjustment, and then click OK.

    Option Settings
  4. Click Format to start the SD Formatter tool.

    SDFormatter Tool
  5. Click OK to format the SD memory card.

    SD Formatter Confirm dialog

    A dialog box displays the progress of the format.

    Formatter Progress dialog
  6. When the format is complete, click OK to close the dialog box.

    SDFormatter dialog
  7. Click Exit to close the SD Formatter tool.

    SDFormatter dialog

You are now ready to install the Raspbian Wheezy image in the SD memory card. Leave the card in the computer.

 

Downloading and Confirming the Raspbian Wheezy Image

  1. Make a note of the SHA-1 checksum for the zip file that you downloaded.

    Raspberry Pi Downloads page, Raspbian section

    Note: The SHA-1 checksum might be in a file with a sha1 extension.

  2. Open a command window in the directory where you downloaded the zip file and enter sha1sum.exe 2014-01-07-wheezy-raspbian.zip.

    Command Prompt

    Note: If the SHA-1 checksum does not match the checksum listed on the download page, try downloading the zip file again.

  3. Open an unzip tool and extract the contents of unzip 2014-01-07-wheezy-raspbian.zip.
  4. Start the Win32DiskImager application. Make sure that the device address is the same as the mount point for the SD memory card.

    Win32 Disk Imager
  5. Click the folder button, navigate to the location of the image file, and click Write.

    Win32 Disk Imager
  6. Click Yes to confirm that you want to overwrite the contents of the SD memory card.

    Confirm overwrite

    A progress meter is displayed.

    Win32 Disk Imager Progress meter
  7. When the Write Successful message is displayed, click OK.

    Complete dialog
  8. Click Exit to close the Win32 Disk Imager.

    Win32 Disk Imager
  9. Perform one of the following steps:

    • Remove the SD memory card from the computer.
    • If you used a USB SD card reader, remove the SD card from the reader.
    • If you used a micro or mini SD card, remove it from the reader and reinsert it into a full-sized SD adapter.

You are now ready to boot the Raspberry Pi and install the Java ME Embedded 8 binary for Pi.

 

Setting Up the Raspberry Pi as a Headless Embedded Device

To set up the Raspberry Pi as a headless embedded device, you configure Raspbian to allow SSH connections by using a USB/TTY cable or by using a USB keyboard and an HDMI monitor. To ensure that the Raspberry Pi always has the same IP address, you configure the Raspberry Pi to use a static IP address.

Note: If you want to connect your Raspberry Pi to your network by using both wireless (WLAN) and wired (ETH0) options, choose a different fixed IP address for each connection type. Do not use the same IP address.

 

Option 1: Configuring SSH by Using a USB/TTY Cable

Important: You must install the PL2303HX.A drivers before you plug the USB cable into your PC.

  1. Download and unzip the PL2303HX.A driver software.

    Note: The Prolific drivers will not work with Windows 8.

  2. Double-click the PL2303_Prolific_DriverInstaller_v1.9.0.exe file to launch the installer and click Next on the Welcome page.

    Installer
  3. When the InstallShield Wizard displays a success message, click Finish.

    Installer
  4. Attach the connector of the USB/TTL cable to the Raspberry Pi as follows:

    1. Red on the farthest right (closest to the edge of the board) pin of the GPIO header.
    2. Black on the third pin from the right.
    3. White on the fourth pin from the right.
    4. Green on the fifth pin from the right.
    Rasbperry Pi
  5. Perform the following steps:

    1. Insert the SD memory card into the Raspberry Pi.
    2. Connect the Ethernet cable to the Raspberry Pi and to your network.
    3. Plug the USB end of the cable into your PC.

    Note: The USB cable will power the Raspberry Pi. Do not plug in the micro-USB power cable at the same time. The Raspberry Pi should only be powered by one source at a time.

  6. Open an Explorer window, right-click Computer and select Properties.

    Windows Explorer
  7. In the Control Panel dialog box, click Device Manager.

    Control Panel
  8. Scroll to Ports and then perform the following steps:

    1. Expand Ports.
    2. Make a note of the port number for the Prolific USB-to-Serial Comm Port connection.
    Device Manager

    Note: If you don't see the Prolific USB-to-Serial Comm Port connection, try rebooting your PC.

  9. Start putty.exe and then perform the following steps:

    1. Enter the COM port number that you noted in step 8.
    2. Enter 115200 for the speed.
    3. Select Serial as the connection type.
    4. Click Open.
    PuTTY Window
  10. In the PuTTY window, enter pi as the login name and raspberry as the password.

    PuTTY

    Note: You may have to press the Enter key to establish the initial connection.

  11. Enter sudo raspi-config.

    PuTTY
  12. Select Expand Filesystem (setup option 1) and press Enter to expand the file system and use all of the SD memory card storage.

    Raspberry Pi Configuration
  13. Press Enter to close the confirmation screen.

    Raspberry Configuration Screen
  14. Press the up or down arrow key to select Internationalisation Options (setup option 4) and press Enter.

    Raspberry Configuration Screen
  15. Press the up or down arrow key to select Change Timezone (internationalisation option I2) and press Enter.

    Raspberry Configuration Screen
  16. Press the up or down arrow key to select your country and press Enter.

    Raspberry Configuration Screen
  17. Press the up or down arrow key to select the time zone in your country (if applicable) and press Enter.

    Raspberry Configuration Screen
  18. Press the up or down arrow key to select Advanced Options (setup option 8) and press Enter.

    Raspberry Configuration Screen
  19. Press the up or down arrow key to select SSH (advanced option A4) and press Enter.

    Raspberry Configuration Screen
  20. Press the left or right arrow key to select Enable and press Enter

    Raspberry Configuration Screen
  21. Press Enter.

    Raspberry Configuration Screen
  22. Press the left or right arrow key to select Finish and press Enter.

    Raspberry Configuration Screen
  23. Press the left or right arrow key to select Yes and press Enter to reboot the Raspberry Pi.

    Raspberry Configuration Screen

    The Raspberry Pi reboots.

    Raspberry Pi output to console
  24. Enter pi as the login and raspberry as the password.

    Raspberry Configuration Screen
  25. Enter ifconfig -a.

    Raspberry Configuration Screen

    Make a note of the IP address that your network provided for the Raspberry Pi.

    Raspberry Configuration Screen
  26. Unplug the USB cable from the PC and disconnect the leads from the Raspberry Pi.

  27. Plug the power cable into the Raspberry Pi.

Skip to the section titled "Connecting to the Raspberry Pi with the Secure Shell."

 

Option 2: Configuring SSH by Using a USB Keyboard and HDMI Monitor

  1. Perform the following steps:

    1. Insert the SD memory card into the Raspberry Pi.
    2. Connect the USB keyboard and USB mouse.
    3. Connect the HDMI display.
    4. Connect the Ethernet cable.
    5. Plug in the power cable.
    Raspberry Pi

    After a few moments, the monitor displays text, and the Raspberry Pi raspi-config configuration screen appears.

  2. Select Expand Filesystem (setup option 1) and press Enter to expand the file system and use all of the SD memory card storage.

    Raspberry Pi Configuration
  3. Press Enter to close the confirmation screen.

    Raspberry Configuration Screen
  4. Press the up or down arrow key to select Internationalisation Options (setup option 4) and press Enter.

    Raspberry Configuration Screen
  5. Press the up or down arrow key to select Change Timezone (internationalisation option I2) and press Enter.

    Raspberry Configuration Screen

    Note: You may also need to change your locale in order to properly identify your keyboard.

  6. Press the up or down arrow key to select your country and press Enter.

    Raspberry Configuration Screen
  7. Press the up or down arrow key to select the time zone in your country (if applicable) and press Enter.

    Raspberry Configuration Screen
  8. Press the up or down arrow key to select Advanced Options (setup option 8) and press Enter.

    Raspberry Configuration Screen
  9. Press the up or down arrow key to select SSH (advanced option A4) and press Enter.

    Raspberry Configuration Screen
  10. Press the left or right arrow key to select Enable and press Enter.

    Raspberry Configuration Screen
  11. Press Enter.

    Raspberry Configuration Screen
  12. Press the left or right arrow key to select Finish and press Enter.

    Raspberry Configuration Screen
  13. Press the left or right arrow key to select Yes and press Enter to reboot the Raspberry Pi.

    Raspberry Configuration Screen

    The Raspberry Pi reboots.

    Raspberry Pi output to console

    Notice the line that indicates the IP address of the Raspberry Pi.

  14. At this point, you can disconnect the HMDI monitor, the USB mouse, and the USB keyboard.

 

Connecting to the Raspberry Pi with the Secure Shell

  1. Start putty.exe and perform the following steps:

    1. In the boot screen, enter the IP address in the IP address field.
    2. Enter Raspberry SSH in the Saved Sessions field.
    3. Click Save.
    PuTTY Configuration
  2. Click Open.

    PuTTY Configuration
  3. Click Yes to accept the security alert.

    PuTTY Security Alert dialog
  4. Enter pi as the login name and raspberry as the password.

    PuTTY Connection
 

Configuring the Raspberry Pi with a Fixed IP Address by Using a Wired or Wireless Network

To ensure that the Raspberry Pi always has the same IP address, you configure the Raspberry Pi to use a static IP address. You may choose to set your Raspberry Pi by using a wired or wireless network.

Note: If you want to connect your Raspberry Pi to your network by using both wired (ETH0) and wireless (WLAN) options, choose a different fixed IP address for each connection type. Do not use the same IP address.

 

Option 1: Setting Up the Raspberry Pi to Use a Fixed Wired IP Address

  1. In a separate command prompt window, enter ipconfig to display the netmask and default gateway for your network.

    Windows Command Prompt

    Note: If you are using a wireless connection, the information appears under the Wireless LAN adapter heading.

  2. In a PuTTY window, enter sudo nano /etc/network/interfaces and then perform the following steps:

    1. Comment out the iface eth0 inet dhcp line by placing a # symbol at the beginning of the line.
    2. Below that, add the iface eth0 inet static line.
    3. Use your network settings to add the IP, network, netmask, broadcast, and gateway addresses. For example:
      address 192.168.1.105
      network 192.168.1.0
      netmask 255.255.255.0
      broadcast 192.168.1.255
      gateway 192.168.1.1

    PuTTY Connection
  3. Press Ctrl + O and then press Enter to write the file.

    PuTTY Connection
  4. Press Ctrl + X and then press Enter to close nano and return to the prompt.

  5. Enter sudo reboot to reboot the Raspberry Pi and make the changes.

    PuTTY Connection
 

Option 2: Setting Up the Raspberry Pi to Use a Wireless Network with a Fixed IP Address

If you plan to use a wireless USB module with your Raspberry Pi, you need to edit the network interfaces file.

  1. In a PuTTY window, enter sudo nano /etc/network/interfaces and then perform the following steps:

    1. Comment out the following lines:
    2. allow-hotplug wlan0
      iface wlan0 inet manual
      wpa-roam /etc/wpa_spplicant/wpa_supplicant.conf

    3. Below that, add the following lines:
    4. auto wlan0
      iface wlan0 inet static

    5. Use your network settings to add the IP address, network mask, and gateway address. For example:
      address 192.168.1.105
      netmask 255.255.255.0
      gateway 192.168.1.1

    6. Add the network SSID and passkey for your network in double quotation marks. For example:
      wpa-ssid "mynetwork"
      wpa-psk "cants@y"

    PuTTY Connection
  2. Press Ctrl + O and then press Enter to write the file. Press Ctrl + X to exit nano.

  3. Enter sudo halt to stop the Raspberry Pi.

    PuTTY Connection
  4. Unplug the power cable to the Raspberry Pi.

  5. The Raspberry Pi supports only two USB connections. To use the USB Wifi Module, unplug the USB mouse, USB keyboard, and Ethernet cable, and then plug in the USB Wifi module.

    Raspberry Pi
  6. Plug the power cable into the Raspberry Pi.

 

Installing the Java ME Embedded 8.1 Early Access Binary on the Raspberry Pi

To install the Java ME 8.1 EA Embedded binary on the Raspberry Pi, you transfer the Raspberry Pi binary zip file from your desktop to the Pi over the SSH connection. Next, you unzip the file into a new directory.

 

Restarting the PuTTY Connection

  1. To reconnect to the Raspberry Pi, right-click in the header of the PuTTY window and select Restart Session.

    PuTTY Connection
  2. Enter pi as the login name and raspberry as the password.

    PuTTY Connection
 

Transferring the Java ME Embedded 8.1 Early Access Binary to the Raspberry Pi by Using PSFTP

  1. Launch the PSFTP tool and then perform the following steps:

    1. Enter open 192.168.1.105.
    2. Enter pi as the login name and raspberry as the password.
    PSFTP Window
  2. Enter lcd C:\Temp  to change the local directory to the location of the Java ME Embedded 8 binary zip file for the Raspberry Pi.

    PSFTP Window
  3. Enter put oracle-jmee-8-1-ea-raspberrypi-linux-bin-b01-20_may_2014.zip.

    PSFTP Window

    Depending on your connection speed, this action can take several minutes.

  4. Enter exit to quit and close the PSFTP tool.

    PSFTP Window
 

Unzipping the Raspberry Pi Binary and Starting the AMS

  1. Enter unzip oracle-jmee-8-1-ea-raspberrypi-linux-bin-b01-20_may_2014.zip -d javame8 to unzip the Raspberry Pi binary into a new javame8 directory.

    PuTTY Connection
  2. Enter cd javame8/bin to change directories to the javame8/bin directory.

    PuTTY Connection
  3. Enter sudo ./usertest.sh to start the Application Management System (AMS).

    PuTTY Window

    Note: Because you must run the script as root, be sure to use sudo.

 

Connecting the Emulator to the Raspberry Pi

To connect the NetBeans IDE to the Raspberry Pi as a deployment platform, you add the Raspberry Pi as an Embedded External Device.

  1. In the lower left corner of your Windows desktop, click the Show Hidden Icons button, and then click Oracle Java ME SDK Device Manager.

    Windows Show Hidden icons
  2. In the Driver Connections Manager dialog box, click Add.

    Windows Show Hidden icons
  3. In the Add Device Connection dialog box, perform the following steps:

    1. If the IP address of the Raspberry Pi wasn't automatically populated, manually enter it.
    2. Click OK.
    Windows Show Hidden icons

    The following message is displayed in the Windows tray: "Device is now registered."

    Windows Tray
  4. In the Device Connections Manager, review the Raspberry Pi IP address and status, and then click Close.

    Windows Show Hidden icons
 

Running a Simple IMlet on the Raspberry Pi

To test the connection between NetBeans and the Raspberry Pi, you write a small program to test the IMlet lifecycle methods (startApp and destroyApp). Next, you deploy the IMlet to the Raspberry Pi through the EmbeddedExternalDevice1 emulator and control the IMlet application by using the emulator.

  1. In NetBeans 8.0, select File > New Project to create an IMlet project in NetBeans.

    NetBeans New Project
  2. Select Java ME Embedded from Categories and Java ME Embedded Application from Projects and click Next.

    New Project dialog
  3. In the New Java ME Embedded Application dialog box, perform the following steps:

    1. Enter TestME8Embedded as the project name.
    2. Select EmbeddedExternalDevice1 as the device.
    3. Change the Midlet package name (the string before the dot) to com.example.
    4. Click Finish.
    New Embedded Application dialog
  4. Add console messages to the startApp and destroyApp methods in the class.


    public class TestME8Embedded extends MIDlet {

    @Override
    public void startApp() {
    System.out.println("Starting...");
    }

    @Override
    public void destroyApp(boolean unconditional) {
    System.out.println("Destroyed...");
    }
    }
  5. Right-click the project and select Run.

    NetBeans

    In the PuTTY window that is connected to the Raspberry Pi, a message indicates that the console output is written to the window where the AMS was started.

    PuTTY Connection

    An emulator window also opens.

    Emulator

    You can include multiple IMlets in a single suite. In this case, the suite name and IMlet name are the same.

  6. Click Stop in the emulator window.

    Emulator window

    The Destroyed message is displayed in the PuTTY window (the running AMS on the Raspberry Pi).

    PuTTY window
  7. In the emulator window, click Output to open the Output Console.

    Output Console

    Messages also appear in the Output Console.

    Output Console
 

Summary

In this tutorial, you learned to:

  • Create a bootable image for the Raspberry Pi
  • Set up the Raspberry Pi as a headless device
  • Install the Java ME Embedded 8 binary in the Raspberry Pi
  • Connect the Windows emulator to the Raspberry Pi
  • Run a simple IMlet on the Raspberry Pi

Resources

Credits

  • Lead Curriculum Developer: Tom McGinn
  • Other Contributors: Edgar Alberto Martinez Cruz, Matt Heimer