As far as I can tell, on Habré and not only, there is a surge of interest in microcontrollers - devices based on ARM processors and other not-so-ordinary hardware. The market responds symmetrically. Arduino, Biggle Board, Raspberry Pi, and many other useful things have appeared to meet the demand.
Since the beginning of this year, nothing has passed, and on Habré two articles appeared at once on the use of the Java platform on the Rasprerry Pi
"Raspberry Pi and a cup of Java, please!" It is quite natural that the experiments used the familiar to all Java SE, whose port under ARM appeared about two years ago. Few people know that Java ME did not rest in peace with the era of push-button telephones from Nokia. She lives a full life in the new world - the world of embedded systems. I want to tell you today about the use of Java ME on Raspberry Pi.
Oracle Java ME Embedded is a full-fledged Java runtime optimized for devices with ARM architecture and systems with limited hardware capabilities. Java ME shows itself in all its glory on platforms with low computing power and low memory resources that work with network services. For example, such as wireless modules, positioning modules, “smart” resource meters, environmental monitoring sensors, vending machines, telemedicine, and, of course, “smart” houses.
')
Using Oracle Java ME in your projects provides a number of interesting features. Firstly, the main advantage of Java - “write once, run everywhere” now works in the case of embedded devices. Secondly, the application lifecycle management system and its remote update on the device (AMS - application management system) are integrated into the platform. Third, you get a special API for accessing peripherals (DAAPI - Device Access API). Fourth, free development tools, which is rare for embedded systems (Java ME SDK for NetBeans and Eclipse). As well as a set of standard services integrated into the platform: File I / O (JSR 75), Wireless Messaging (JSR 120), Web Services (JSR 172), Security and Trust Services Subset (SATSA - JSR 177), Location (JSR 179), XML (JSR 280).
Oracle Java ME Embedded Product Stack
As you already understood, Oracle Java ME Embedded is a cross-platform product and supports a number of devices with ARM architecture. The current release version of Oracle Java ME 3.3 is 3.4. The platform is ported to the Cortex-M3 / RTX (KEIL Evaluation Board), ARM11 / Linux (Raspberry Pi Model B), ARM9 / BREW MP (Qualcomm IoE development), X86 / Windows (emulator). The above are reference implementations of the platform released by Oracle. It is possible to port the platform to other devices when such needs arise from end users.
Officially, the minimum possible configuration of Oracle Java ME Embedded requires only 130 KB of RAM, 350 KB of ROM. Although, if you come to the meeting of the Java User Group in Moscow on January 30,
http://jug.msk.ru , you will be surprised how small the platform can be if you work on it with a file. Alexander Mironenko
alexanderVmironenko will tell you how he “stuffed” Java into 32kb! Ram. Full, standard configuration requires more memory: 700kb RAM and 2000kb ROM, which still looks ridiculous by modern standards.
Everyone wants everyone to be smart around. It is pleasant to communicate with smart people, and it is comfortable to live in a smart house. Perhaps that is why most of the projects with Arduido and Raspberry Pi have a pronounced focus on pumping skills of our home. A typical task is temperature monitoring.
To monitor the temperature, we first used sensors with an SPI interface. But later it turned out that sensors with I2C are much cheaper. For the manufacture of the thermometer from the Raspberry Pi and Oracle Java ME Embedded 3.3, we need a digital temperature sensor Dalas Semiconductor DS1621 in the DIP8 package. Here you can buy it for 173 rubles
http://www.electronshik.ru/item/ds1621-232961 .
We connect it to the GPIO pins of our board
DS1621 | Raspberry GPIO pins |
pin1 | SDA (GPIO 2) |
pin2 | SCL (GPIO 3) |
pin4 | GND |
pin8 | 3.3v |
If you read the Datasheet on DS1621, you can find out that the address of the sensor on the bus is configured using pins 5-6-7 in our example, we will install them all in 1 short-circuiting.
We believe that you already have Raspbian and it has been updated.
In order for us to have the opportunity to work with the I2C interface on the Raspberry Pi. You must download the appropriate module.
Add two lines to / etc / modules
i2c-bcm2708 i2c-dev
We overload the board.
Install utilities for working with I2C
sudo apt-get install i2c-tools
Determine the address of our device on the bus I2C
sudo i2cdetect -y 1
The address of our sensor is 4f (remember this number)
Download a stable version of the Oracle Java ME Embedded 3.3 for Raspberry Pi Model B. In version 3.4, only support for the Qualcomm IoE platform was added. Pre-accept the license agreement.
http://www.oracle.com/technetwork/java/embedded/downloads/javame/index.html?ssSourceSiteId=ocomen
We copy runtime on Raspberry and we develop in a convenient place.
For example, in ~ / JavaME /
And from root we start AMS (Application Management System)
sudo ~/JavaME/bin/usertest.sh
C Raspberry Pi finished.
Install Java ME SDK and plugin for NetBeans or Eclipse on your computer.
http://www.oracle.com/technetwork/java/javame/javamobile/download/sdk/default-303768.html
We add our Malinka as a device for deploying a MIDlet.
In the NetBeans menu, select Tools / Java ME / Device selector
In the Device selector window, press Ctrl-D and create a new device. To do this, simply prescribe the address of our board, click Next, and if everything is in order, select the logging level.
Create a Java ME / Embedded application project
The IDE will create for us a skeleton Java ME application that inherits from the MIDlet class and consists of three methods: startApp (), pauseApp () and destroyApp (unconditional boolean). The startApp () method will start when the MIDlet starts, in it, for simplicity, we will write the code of our application.
Java ME Embedded provides us with a high-level interface for communicating with peripherals - DAAPI (Deveice Access API). To work with I2C, we need to create a device configuration, transfer it to the PeripheralManager.open () factory and if all the wires are in order and Java is started from root, we will get an instance of the I2CDevice () class, which will give us the opportunity to communicate with the sensor.
Below is a sample of Java ME application code, if something is not clear, ask questions in the comments, come to the Oracle office in St. Petersburg or January 30th at
http://jug.msk.ru
To run this code on the device, right-click on your project with NetBeans, select Run with ... and in the Quick Project Run window that opens, select your Raspberry. Or in the properties of the project, select in the Platform tab, select your device as the Device, then NetBeans will deploy the application to Rapberry Pi by default when the project starts.
Now you know the temperature in the room :)
Useful links:
Java ME Embedded 3.3 for Raspberry Pi
Java ME SDK 3.4
Java ME Embedded 3.3 Getting Started Guide for the Reference Platform (Raspberry Pi)
Thermal sensor DS1621 Datasheet
import com.oracle.deviceaccess.PeripheralManager; import com.oracle.deviceaccess.i2cbus.I2CDevice; import com.oracle.deviceaccess.i2cbus.I2CDeviceConfig; import java.io.IOException; import javax.microedition.midlet.*; public class IMlet extends MIDlet { private final int CFG_ADDRESS = 0x4f;