Friday May 15, 2015

Using Line User Interface with Oracle Java ME Embedded 8.1 on STMicroelectronics Evaluation board

Oracle Java ME Embedded 8.1 Developers Preview for ST Micro Evaluation board has been recently released. 

As I mentioned in my previous post, one of the release additions is a Line User Interface (LUI) API hardware implementation. LUI is an optional API of MEEP (JSR 361), which enables rendering text information on a display. In Java ME Embedded 8.0 this functionality was supported only by Java ME SDK Emulator and now it is possible to use a hardware display to implement a simple user interaction in Java ME Embedded applications. 

Java ME SDK 8.1 update includes a very good LUI sample. The sample is an on-screen text menu navigated by a built-in joystick. The menu has 12 items, several nested items, and a status line reflecting a current user choice.  Code of the sample is accompanied very detailed comments, which can definitely helps start developing interactive applications very fast.

Below is a basic example that demonstrates the use of the built-in screen on STM32429I-EVAL board with Java ME Embedded and LUI API.

 Happy Java coding for embedded.

import java.util.Iterator;
import javax.microedition.lui.Display;
import javax.microedition.lui.DisplayColor;
import javax.microedition.lui.DisplayListener;
import javax.microedition.midlet.MIDlet;

public class LUIDemo extends MIDlet implements DisplayListener {

    @Override
    public void startApp() {
        // Get Display instance and configure it
        Iterator<Display> displays = Display.getDisplays(false);
        Display myDisplay = displays.next();
        // Assign a state change listner to Display instance
        myDisplay.addDisplayListener((DisplayListener) this);
        //as soon as the hardware display will be assigned to myDisplay instance
        //hardwareStateChanged method will be invoked with newState = true 
        synchronized (myDisplay) {
            try {
                // Assign hadware display to myDisplay 
                myDisplay.setHardwareAssigned(true);
                // Assigning display may take some time,
                // so that we need to wait the operation acomplishement 
                myDisplay.wait();
                // Now myDisplay has HW display assigned and we can use it
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            }
        }
        //Display.setText is overloaded method. 
        //In the example below the text "Hello world" is blinking.
        myDisplay.setText(0, "Hello world", true, false);
        myDisplay.setText(1, "I love programming Java ME Embedded on STM32429EVAL");
    }

    @Override
    public void destroyApp(boolean unconditional) {
    }

    @Override
    // hardwareStateChanged method is invoked as the hardware display is assigned or unassigned
    public void hardwareStateChanged(Display d, boolean newState) {
        //Setting up assigned hardware display
        d.setLightingColor(new DisplayColor(0xFF, 0, 0));
        d.setCurrentTextColor(new DisplayColor(0, 0, 0xFF));
        d.setBackgroundColor(new DisplayColor(0, 0, 0));
        // notify all threads are waiting for Display Object
        synchronized (d) {
            d.notifyAll();
        }
    }

    @Override
    public void displayAdded(Display d) {
    }

    @Override
    public void displayRemoved(Display d) {
    }
}

Friday May 08, 2015

Oracle Java ME Embedded 8.1 released with support of STMicroelectronics STM32F4 micro controller

Oracle Java ME Embedded 8.1 Developer Preview for STM32429I-EVAL has been released today. With this release, the STM32F4 series of micro controllers is joining the family of platforms supported by Java ME Embedded. 
ST Micro produces widely used and very popular high-performance MCUs with the STM32F4 core, which is based on the ARM Cortex-M4 architecture. The detailed information can be founded at STM web.  The Java ME 8.1 Embedded STM port release enables developers to run feature-rich Java ME Embedded applications on the STMicroelectronics STM32429I-EVAL developer evaluation board. 

The Java ME 8.1 follow-up release for STM has full CLDC 8 support, networking, storage, and peripheral I/O support, including GPIO, I2C, SPI, ADC, UART, and other interfaces. The interesting particularity of the release is the implementation of this port on top of ARM Cortex Microcontroller Software Interface Standard (CMSIS), which will allow Oracle and its partners to make feature porting easier and faster.

With this release, developers are able to access on-board screen with the simple Line User Interface (LUI) API. Java ME SDK Update center is distributing an update package with a great example of developing a text menu operated by on-board joystick. After its installation, a LUI sample can be found at your local drive:
 /Java_ME_platform_SDK_8.1/apps/SimpleLUISample

Do not forget to update Java ME 8.1 SDK by navigating to NetBeans or Eclipse menu Tools -> Java ME -> Java ME SDK Update Center and installing the STM32429I-EVAL SDK Update. After applying this update, you will be able to work with STM32429I-EVAL as with any other ME SDK supported board.

Feel free to ask any questions and provide your feedback at our forum: https://community.oracle.com/community/java/java_embedded/java_me_embedded

Wednesday Feb 04, 2015

January-February Java Magazine issued

Recently the first issue of Java Magazine 2015 have been released. If you are still not a subscriber, blame on you. It is absolutely free and as publisher admitted: "Java Magazine is an essential source of knowledge about Java technology, the Java programming language, and Java-based applications for people who rely on them in their professional careers, or who aspire to.” Subscribe here: http://www.oracle.com/technetwork/java/javamagazine/index.html

This issue contain an article "Embedded: Get Started with Oracle Java ME Embedded 8 on Microcontrollers”, which is giving to readers a detailed explanation on how to develop Java ME applications for micro controllers and connect to peripheral by DIO API. Significant part of the article is describing how to connect to I2C sensor using it’s datasheet.

Happy reading, and just in case you have any question I welcome you to our forum https://community.oracle.com/community/java/java_embedded/java_me_embedded

Wednesday Nov 19, 2014

Java ME Embedded 8.1 brings Java to ARM Cortex M4 and provides Eclipse users with tools for embedded development

A couple days ago, Java ME Embedded 8.1 was released. The new version of the Java ME Embedded platform has two significant enhancements. First, it works on ARM Cortex M4 with very limited RAM size by delivering a port for Freescale K64F. Second, it provides Eclipse IDE support in Java ME SDK. The link to the release page: http://www.oracle.com/technetwork/java/embedded/javame/embed-me/overview/index.html


FRDM-K64F is based on  MK64FN1M0VLL12 MCU (120 MHz, 1 MB flash memory, 256 KB RAM, low-power, crystal-less USB, and 100 Low profile Quad Flat Package (LQFP)). It is has a form-factor of Arduino™ R3 pin layout. The FRDM-K64F goes with a lot of peripherals to enable rapid prototyping. In addition to UART, I2C, SPI, and GPIO interfaces on board, it has 3 LEDs and 2 switches which are accessible from Java Runtime. Another helpful device that is integrated into K64F is accelerometer-magnetometer with I2C interface (FXOS8700Q). You can easily access it from your Java application and create a compass application, for instance. Find the code example below the post..


Java ME SDK 8.1 brings smooth experience of Java Embedded developers to the Eclipse world. Java ME SDK plugin for Eclipse is based on the recently released Mobile Tools for Java TM (MTJ) 2.0 which had been done with significant efforts of Oracle's engineers. Now, all impressive features of Java ME SDK, such as on-device debugging, memory and network monitors, CPU profiling, and memory profiling are available in Eclipse. To install it, you need just to go the OTN web, download and install Java ME SDK with Eclipse plugin http://www.oracle.com/technetwork/java/embedded/javame/javame-sdk/downloads


If you have any questions or suggestions, please speak up at our forum: https://community.oracle.com/community/java/java_embedded/java_me_embedded
The best source of information about Java ME Embedded is Java ME Documentation portal: http://docs.oracle.com/javame


How to get a device ID from FXOS78700Q on K64F:
public class FXOS8700Q extends MIDlet {

    private I2CDevice fxos8700q;

    final int FXOS8700Q_STATUS = 0x00;
    final int FXOS8700Q_OUT_X_MSB = 0x01;
    final int FXOS8700Q_OUT_Y_MSB = 0x03;
    final int FXOS8700Q_OUT_Z_MSB = 0x05;
    final int FXOS8700Q_M_OUT_X_MSB = 0x33;
    final int FXOS8700Q_M_OUT_Y_MSB = 0x35;
    final int FXOS8700Q_M_OUT_Z_MSB = 0x37;
    final int FXOS8700Q_WHOAMI = 0x0D;
    final int FXOS8700Q_XYZ_DATA_CFG = 0x0E;
    final int FXOS8700Q_CTRL_REG1 = 0x2A;
    final int FXOS8700Q_M_CTRL_REG1 = 0x5B;
    final int FXOS8700Q_M_CTRL_REG2 = 0x5C;
    final int FXOS8700Q_WHOAMI_VAL = 0xC7;
    final int UINT14_MAX = 16383;

    @Override
    public void startApp() {
        ByteBuffer buffer = ByteBuffer.allocateDirect(1);
        try {
            fxos8700q = DeviceManager.open(300, I2CDevice.class);
            buffer = read(FXOS8700Q_WHOAMI, 1, 1);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        String id = String.format("%8s", Integer.toBinaryString(buffer.get(0) & 0xFF)).replace(' ', '0');
        System.out.println(id);
    }

    @Override
    public void destroyApp(boolean unconditional) {
    }

    void write(int address, int addressSize, ByteBuffer data) throws IOException {
        fxos8700q.begin();
        fxos8700q.write(address, addressSize, data);
        fxos8700q.end();
    }

    ByteBuffer read(int address, int addressSize, int bytesToRead) throws IOException {
        ByteBuffer buffer = ByteBuffer.allocateDirect(bytesToRead);
        fxos8700q.begin();
        fxos8700q.read(address, addressSize, buffer);
        fxos8700q.end();
        return buffer;
    }
}

Monday Nov 17, 2014

Mobile Tools for Java™ (MTJ) 2.0 plugin for Eclipse IDE released

I proud to announce that a new version of MTJ plugin for Eclipse have recently been released with a significant contribution of Oracle's engineers. Mobile Tools for Java TM (MTJ) 2.0 release is making MTJ plugin IoT ready by supporting Java ME Embedded 8 platform. Oracle Java ME Embedded 8 is Java TM Runtime client optimized for ARM based micro controllers and other constrained devices. Now MTJ 2.0 provides a support for CLDC 1.8 configuration (JSR 360), MEEP 8.0 profile (JSR 361) support, MEEP 8.0 profile (JSR 361), better IMP-NG profile (JSR 228) support. MEEP 8.0 permissions mechanism was significantly changed and looks similar to Java SE, MTJ 2.0 supports MEEP security model. Code Validation Builder provides an ability to perform pre-compilation analysis and generates warnings using 3rd party plugins created on top of MTJ. Also support for Java ME APIs javadocs in zip archives provided by the new version of MTJ. 

 Detailed information and download links can be found at the project page https://projects.eclipse.org/projects/tools.sequoyah.mtj 

Friday Oct 24, 2014

Java ME Embedded is able to run with 256Kb of RAM only

Around a JavaOne conference timeframe we announced Java ME Embedded 8.1 Developer Preview release.  This release is bringing Java ME Embedded to a microcontrollers with ARM Cortex M architecture with mbed RTOS. Java ME Embedded is now capable to run on Freescale K64F board. The FRDM-K64F is an ultra-low-cost development platform for Kinetis K64.  The K64F board has a form-factor which compatible with the Arduino™ R3 pin layout, providing a wide range of expansion board options.

FRDM-K64F based on  MK64FN1M0VLL12 MCU (120 MHz, 1 MB flash memory, 256 KB RAM, low-power, crystal-less USB, and 100 Low profile Quad Flat Package (LQFP)) The FRDM-K64F is feature packed with a lot of peripherals to enable rapid prototyping. 

As always the best way to start with Java ME on any new platform is our Getting Started Guide, which can be found at Java ME Documentation page http://docs.oracle.com/javame/8.0/index.html

What I would like to emphasize is a new Flasher capabilities of Java ME SDK. If you have a new K64 you can make it Java-enabled by just clicking "Flash" button in Device Connection Manager. I will explain you how to do it.

Firstly, if you have not installed mbed Serial Driver and USB Serial it is better do it using detailed instruction from K64 GSG http://docs.oracle.com/javame/8.1/get-started-freescale-k64/toc.htm.

Then obviously you need a Java ME SDK 8.1 EA3 with new NetBeans plugins, which can be downloaded at OTN http://www.oracle.com/technetwork/java/embedded/javame/javame-sdk/downloads/index.html

Now you can check new flashing capabilities.
1. Go to t the Windows tray and click on Device Connection Manager 8.1
2. Click "Flash" button and pick your connected K64 board from the list following.
3. Say: "Wow, how cool it is to enable mbed device with Java capabilities!"



As I said before, K64 is a very convenient platform for prototyping. It has multicolor LED, switches and other peripherals on board. Let's make LEDs blinking.

Do not forget to set API permissions as described in one of my previous post  https://blogs.oracle.com/javame/entry/measuring_temperature_with_raspberry_pi. If you have any question it is my pleasure to answer here or at Javas ME Embedded forum https://community.oracle.com/community/java/java_embedded/java_me_embedded

Create a new MidLet and copy code below instead of generated. Do not forget to rename the class


import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import jdk.dio.DeviceManager;
import jdk.dio.gpio.GPIOPin;
import jdk.dio.gpio.GPIOPinConfig;

/**
 *
 * @author abelokry
 */
public class JavaMEOnK64 extends MIDlet {
    
    @Override
    public void startApp() {
        try {
            String platform = System.getProperty("microedition.platform");  // Get Platform name it might be useful to identify the platform your midlet running and configure accordingly
        String productVersion = System.getProperty("com.oracle.product.version"); // Get product version
        
        System.out.println("platform = " + platform + " version = " + productVersion);
            GPIOPin orangeLED = (GPIOPin)DeviceManager.open(1); //Open Yellow LED see Getting Started Guide for details
            GPIOPin yellowLED = (GPIOPin)DeviceManager.open(2); //Open Green LED, see Getting Started Guide for details
            for (int i = 0; i < 10; i++) {
            orangeLED.setValue(true);
            Thread.sleep(500);
            orangeLED.setValue(false);
            yellowLED.setValue(true);
            Thread.sleep(500);
            yellowLED.setValue(false);
             }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
            notifyDestroyed();
        }

    @Override
    protected void destroyApp(boolean unconditional) throws MIDletStateChangeException {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
    
    
}

Wednesday Oct 01, 2014

Java ME Embedded Documentation survey

Java ME documentation team has put together a short survey (7 questions) which help us understand the best way to improve documentation for Java ME Embedded. Please invest 5 minutes of your time to return your investment in near future https://www.surveymonkey.com/s/javame-docs

Thursday Jul 31, 2014

LIBlets Signing Patch released

LIBlets Signing Patch available for download through Java ME SDK Update Center. This patch fixes JadTool that used incorrect JAD attribute for LIBlets signature. To apply this patch in NetBeans please follow the steps below.

1. Run Java ME SDK Update Center

2. Under "Available" tab you will see the new item (Internet connection required)

3. Click the check box and install the patch

4. Check if it is appeared under "Installed" tab 

Happy embedded coding with Java ME SDK! 

Friday Jul 04, 2014

Measuring temperature with Raspberry Pi, I2C sensor and Java ME 8

Nowadays, developers reveal their growing interest to the microcontrollers, devices based on ARM processors, and other non-traditional hardware. To satisfy the increasing demand, the market introduced  Arduino, Beagle Board, Raspberry Pi, and many other devices.
Oracle provides two Java platforms for ARM-based devices. Whereas Java SE Embedded is aimed for powerful hardware,  Java ME Embedded works better for resource-constrained devices.


Oracle Java ME Embedded is a Java Runtime optimized for constrained ARM based devices. Minimally acceptable requirements for Java ME embedded are 128Kb of RAM and 1Mb of ROM. Using Java ME Embedded in your projects can bring several benefits. First of all,  "write once, run everywhere" principle, now with some restrictions can be applied to embedded world. Second, AMS (Application Management System), integrated into the platform. enables deploying, updating, starting, stopping, and destroying applications. Third, you have an API to access peripheral, such as SPI, I2C, URAT, and GPIO pins (DAAPI - Device Access API). Forth,, you will get a free and powerful developer tools as well as a set of standard services: File I/O (JSR 75), Wireless Messaging (JSR 120), Web Services (JSR 172), Security and Trust Services Subset (SATSA – JSR 177), Location (JSR 179), and XML (JSR 280).


As you can see, Oracle Java ME Embedded is a cross-platform product, which supports a set of ARM based devices. The current version is Oracle Java ME 8. The platform is ported to ARM11/Linux (Raspberry Pi Model B), ARM9/BREW MP (Qualcomm IoE development), and X86/Windows (emulator). These are reference implementations developed by Oracle engineers. If there is customer’s need, the platform can be ported to other devices.

Smart home


Personally, I would really like to see my home automated. It is always a true pleasure to communicate with smart people and a real delight to live in a smart home. The first idea that usually strikes my mind when I’ve got a small piece of hardware is to automate something at my house. A typical task is a temperature monitoring.
To monitor temperature you can use UART, SPI, or I2C sensors. Usually, I2C ones are a bit cheaper, so that I will use Dallas Semiconductor DS1621 in DIP8 form factor to make a digital thermometer with Raspberry Pi and Java ME Embedded.

Raspberry Pi hardware setup

First of all, we need to physically connect the sensor and a RPi
pin1 - SDL
pin2 - SCL
pin4 - GND
pin8 - Vdd


If you read a datasheet of DS1621, you know that the sensor address at the I2C bus can be configured by pins 5-6-7. For our sensor, let's turn them all to 1 by closing contacts to the power.



Setup software at Raspberry Pi

Install Raspbian and update it.
To enable I2C interface on Raspberry Pi it is necessary to upload the relevant module
add 2 lines to /etc/modules

i2c-bcm2708
i2c-dev


Reboot RPi
Install Linux tools to operate with I2C
sudo apt-get install i2c-tools

Detect an address of our sensor

sudo  i2cdetect -y 1

address is 4f (remember it)


Download Oracle Java ME Embedded 8  for Raspberry Pi Model B.
Accept a license agreements http://www.oracle.com/technetwork/java/embedded/javame/embed-me/downloads/index.html
Copy Runtime to Raspberry Pi to your favorite location and unpack it
for instance ~/JavaME/

Start Runtime with AMS (Application Management System) under the root privileges
sudo ~/JavaME/bin/usertest.sh
We have just  finished with the RPi setup

Developer tools setup

If you have not yet played with Oracle Java ME SDK 8, set it up for Netbeans.
http://www.oracle.com/technetwork/java/embedded/javame/javame-sdk/downloads/index.html

Add our RPi as a deploying device
In NetBeans choose: Tools -> Java ME -> Device selector
The most probably your Raspberry already autodetected by Java ME SDK and exists in the list of connected devices. If it is not, you can find the Device Connection Manager in your Windows tray and add RPi manually.  To do it, just click add and write the IP address of your RPi and define a debug level you need.

Create a new project in Netbeans:  New Project -> Java ME -> Embedded application

IDE creates a skeleton of Java ME application, which extends a MIDlet class  and consists of 3 methods: startApp(), pauseApp(), anddestroyApp(boolean unconditional)

Java ME Embedded provides us with an API to communicate with peripherals – DIO API (Device Input/Output API). To operate with I2C, we need to create a configuration of the device, pass it to the factory DeviceManager.open(), and if everything is alright, we will get an instance of the I2CDevice class required to communicate with the sensor.

To allow your application to use a specific API on the device you need to set up API Permissions.

In Netbeans click right button on your project in Project Properties go to tab Application Descriptor and to access I2C device add 2 lines:

Permission Protected Resource Name
Action Requested

jdk.dio.DeviceMgmtPermission

*:*

open

jdk.dio.i2cbus.I2CPinPermission

*:*

open



To run a code below on your RPi, right-click  on your device in Device Selector window, and under "Run project" menu click on the project you would like to run on Raspberry. Alternatively,  you can use the project properties in Platform tab to define a Device. In that’s the case, NetBeans always uses RPi as a target device for deployment.

Now you should know the temperature in room.

The best collection of docs about Java ME Embedded 8 can be found here: http://docs.oracle.com/javame/8.0/
Have fun!

/*
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
 * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

import javax.microedition.midlet.MIDlet;

import java.io.IOException;
import java.nio.ByteBuffer;
import jdk.dio.DeviceManager;
import jdk.dio.i2cbus.I2CDevice;
import jdk.dio.i2cbus.I2CDeviceConfig;

public class JavaMEThermometer extends MIDlet {

    private final int CFG_ADDRESS = 0x4f;  //Sensor address
    private final int FREQ = 100000;  //Bus frequency from Datasheet
    private final int ADDRESS_SIZE = 7; //Address size from Datasheet
    private final int BUS_ID = 1; // Internal bus ID in Java ME Embedded from Getting Started Guide

    // Registers addresses and definitions of configuration parameters of DS1621 from Datasheet
    private final int REG_READ_TEMP = 0xAA;
    private final int RT_ADDR_SIZE = 0x01;
    private final int READ_TEMP_SIZE = 0x02;
    private final int READ_TEMP_VAL = 0x00;
    private final int REG_ACC_CONF = 0xAC;
    private final int ACC_CONF_VAL = 0x00;
    private final int REG_START_CONV = 0xEE;
    private final int REG_STOP_CONV = 0x22;

    public void startApp() {
        // Create a configuration
        I2CDeviceConfig config = new I2CDeviceConfig(BUS_ID, CFG_ADDRESS, ADDRESS_SIZE, FREQ);
        I2CDevice device = null;
        try  {

            // Open device using configuration
            device = (I2CDevice) DeviceManager.open(config);

            // Config sensor to continuous temperature measuring according to Datasheet
            write(device, new byte[]{(byte) REG_ACC_CONF, (byte) ACC_CONF_VAL});
            write(device, new byte[]{(byte) REG_START_CONV});

            // Read temperature
            ByteBuffer tempBuf = ByteBuffer.allocateDirect(READ_TEMP_SIZE);
            device.read(REG_READ_TEMP, RT_ADDR_SIZE,tempBuf);
             // Profit!  
            System.out.println("Temperature is:" + tempBuf.get(0));

        } catch (Exception ex) { // Bad practice. Only for consiceness
            ex.printStackTrace();
        } finally {
            // Close device
            if (device != null) {
                try {
                    device.close();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
                // Destroy application
                notifyDestroyed();
            }

        }
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    private void write(I2CDevice i2c, byte[] buffer) {
        try {
            i2c.begin();
            i2c.write(ByteBuffer.wrap(buffer));
            i2c.end();
        } catch (IOException ex) {
            System.out.println("[I2CThermometerTest] configure exception: " + ex.getMessage());
        } catch (Exception ex) {
            System.out.println("[I2CThermometerTest] Peripherial not available exception: " + ex.getMessage());
        }
    }
}

Tuesday Jun 17, 2014

Oracle Java ME Embedded 8.1 Early Access for Raspberry Pi

Less then two months ago the innovative Java ME 8 have been released. Now you are able to play with  Oracle Java ME Embedded 8.1 Early Access for Raspberry Pi. Download link:  http://www.oracle.com/technetwork/java/embedded/javame/embed-me/downloads/index.html

You are also welcome to Java ME Embedded forum to discuss your thoughts on the new release https://community.oracle.com/community/java/java_embedded/java_me_embedded

About

Topics including Java ME embedded, Java ME SDK, Internet of Things, Edge devices, Java on MCU and more

Search

Archives
« September 2015
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today