SlideShare a Scribd company logo
1 of 103
Raspberry Pi with Java 8 
Intro to Raspberry Pi and Java ME 8 – James Weaver 
Brief demos by student programming contest winners 
Using Pi4J – Robert Savage 
Raspberry Pi Tricks – Stephen Chin 
#DV14 #RPiJava8 @SteveOnJava @SavageAutomate @JavaFXpert
Copyright © 2014, Oracle and/or its affiliates. 2 All rights reserved. 
2 
About the first presenter 
#RPiJava8 
#DV14 
 James Weaver 
– Java Technology Ambassador 
– Oracle Corporation 
– Twitter: @JavaFXpert 
– Email: james.weaver@oracle.com
Presentation based upon freely available MOOC 
Copyright © 2014, Oracle and/or its affiliates. 3 All rights reserved.
MOOC has videos, code, and other resources 
Copyright © 2014, Oracle and/or its affiliates. 4 All rights reserved.
Tweet contains Java Embedded Rasp Pi MOOC 
Copyright © 2014, Oracle and/or its affiliates. 5 All rights reserved.
Raspberry Pi Hardware Components 
Copyright © 2014, Oracle and/or its affiliates. 6 All rights reserved.
Raspberry Pi Hardware Setup 
Copyright © 2014, Oracle and/or its affiliates. 7 All rights reserved.
Java SE vs. Java ME 
Copyright © 2014, Oracle and/or its affiliates. 8 All rights reserved.
Java ME 8 Architecture 
Copyright © 2014, Oracle and/or its affiliates. 9 All rights reserved.
Oracle MOOC: Software Installation Instructions 
On Your Windows PC 
1 
Install Java SE JDK 8 
2 
Install Java ME SDK 8 
3 
Install NetBeans 8 IDE 
4 
Install NetBeans ME SDK Plugins 
Copyright © 2014, Oracle and/or its affiliates. 10 All rights reserved.
Config the Raspberry Pi for Java Development 
Copyright © 2014, Oracle and/or its affiliates. 11 All rights reserved.
Java ME Application Lifecycle Methods 
public class SampleApp extends MIDlet { 
@Override 
public void startApp() { 
System.out.println("Starting..."); 
} 
@Override 
public void destroyApp(boolean unconditional) { 
System.out.println("Destroying..."); 
} 
} 
Copyright © 2014, Oracle and/or its affiliates. 12 All rights reserved.
Door open/close 
... and Some Relevant Concepts Discussed 
In this course, you will build a prototype of an embedded device to 
collect, store, analyze and share data from a shipping container. 
Copyright © 2014, Oracle and/or its affiliates. 13 All rights reserved. 
Pressure/ 
Temperature 
Location/ 
Altitude Storage Client Display 
Our Project 
GPIO 
I2C GPS, UART RMS JavaFX
Lesson 2: 
Using the GPIO and I2C on 
the Raspberry Pi
Door open/close 
In this course, you will build a prototype of an embedded device to 
collect, store, analyze and share data from a shipping container. 
Copyright © 2014, Oracle and/or its affiliates. 15 All rights reserved. 
Pressure/ 
Temperature 
Location/ 
Altitude Storage Client Display 
In This Lesson… 
GPIO I2C
Lesson 2 Agenda 
 Getting started with the hardware 
 Working with GPIO on the Raspberry Pi 
 I2C Overview 
 Enabling I2C on the Raspberry Pi 
 Writing code for I2C 
Copyright © 2014, Oracle and/or its affiliates. 16 All rights reserved.
Lesson 2.1: 
Raspberry Pi Cooking Class: 
Lets see the Ingredients
Hardware 
LED 
 Light Emitting Diode (LED): red, green, blue 
 Two wires: 
– Anode positive, longest, and 
– Cathode negative, shortest 
Copyright © 2014, Oracle and/or its affiliates. 18 All rights reserved.
Hardware 
Resistors 
 Their job is to “resist”, regulate or to set the flow of electrons (current) 
through them. 
 Used with LED to keep the current at specific level: characteristic 
forward current 
 560Ω and 10KΩ 
Copyright © 2014, Oracle and/or its affiliates. 19 All rights reserved.
Hardware 
Switch 
 Switch is a component which controls the open-ness or closed-ness of 
an electric circuit. 
 Two states: 
– Off: looks like an open gap in the circuit (open circuit), preventing current 
from flowing. 
– On: acts just like a piece of wire (closes the circuit), turning the system 
“on” and allowing current to flow 
 Momentary switch: 
– only on when the button is pressed. 
– you release the button, the circuit is broken. 
Copyright © 2014, Oracle and/or its affiliates. 20 All rights reserved.
Hardware 
BMP180 
 Measure barometric pressure and temperature 
 Specifications: 
– Pressure sensing range: 300-1100 hPa (9000m to -500m above sea level) 
– Up to 0.03hPa / 0.25m resolution 
– -40 to +85°C operational range, +-2°C temperature accuracy 
– 2-pin I2C interface on chip 
– Uses 3.3-5V power and logic level for more flexible usage 
Copyright © 2014, Oracle and/or its affiliates. 21 All rights reserved.
Hardware 
Connecting things… 
Breadboard 
Copyright © 2014, Oracle and/or its affiliates. 22 All rights reserved. 
Jumper cables 
Pi Cobbler Breakout 
GPIO ribbon cable
Some hardware connected to the Raspberry Pi 
Copyright © 2014, Oracle and/or its affiliates. 23 All rights reserved.
Lesson 2.2: 
Getting Started with GPIO
General Purpose Input/Output (GPIO) 
 GPIO pin is a generic pin with high or low 
– Its behavior can be programmed through software. 
 GPIO port is a platform-defined grouping of GPIO pins (often 4 or 
more pins). 
GPIOPin pin = DeviceManager.open(1); 
GPIOPort port = DeviceManager.open(0); 
pin.setValue(true); 
port.setValue(0xFF) 
Copyright © 2014, Oracle and/or its affiliates. 25 All rights reserved.
GPIOPin Interface 
 Provides methods for controlling a GPIO pin. 
 A GPIO pin can be configured for output or input. 
– Output pins are both writable and readable 
– Input pins are only readable 
– GPIOPin.INPUT GPIOPin.OUTPUT 
 Get its value by polling, or register a PinListener 
– To register a PinListener: setInputListener(PinListener) 
– To remove the listener: setInputListener(null) 
– Writing a GPIOPin results in UnsupportedOperationException 
Copyright © 2014, Oracle and/or its affiliates. 26 All rights reserved.
GPIO Pins on the Raspberry Pi 
Copyright © 2014, Oracle and/or its affiliates. 27 All rights reserved.
Turning a LED ON and OFF 
The Circuit 
Copyright © 2014, Oracle and/or its affiliates. 28 All rights reserved.
GPIO with Device Access API 
public class GPIOTest implements PinListener { 
... 
private static final int BTN_PIN = 17; 
private static final int BTN_PORT = 0; 
private static final int LED1_ID = 23; 
... 
GPIOPinConfig config1 = new GPIOPinConfig(BTN_PORT, 
Copyright © 2014, Oracle and/or its affiliates. 29 All rights reserved. 
BTN_PIN, 
GPIOPinConfig.DIR_INPUT_ONLY, 
DeviceConfig.DEFAULT, 
GPIOPinConfig.TRIGGER_BOTH_EDGES, 
false); 
GPIOPin button1 = DeviceManager.open(config1); 
GPIOPin led1 = DeviceManager.open(LED1_ID); 
button1.setInputListener(this);
GPIO with Device Access API 
@Override 
public void valueChanged(PinEvent event) { 
GPIOPin pin = event.getDevice(); 
try { 
if (pin == button1) { 
// Toggle the value of the led 
led1.setValue(!led1.getValue()); 
} 
} catch (IOException ex) { 
System.out.println("IOException: " + ex); 
} 
} 
Copyright © 2014, Oracle and/or its affiliates. 30 All rights reserved.
Lets run it… 
Copyright © 2014, Oracle and/or its affiliates. 31 All rights reserved.
Homework: 
Create a Door Sensor 
Ingredients: 
1 Green LED 
1 Red LED 
1 Momentary switch
Door open/close 
In this course, you will build a prototype of an embedded device to 
collect, store, analyze and share data from a shipping container. 
Copyright © 2014, Oracle and/or its affiliates. 33 All rights reserved. 
Pressure/ 
Temperature 
Location/ 
Altitude Storage Client Display 
Door open/close 
GPIO
The Door Sensor 
What we are trying to do 
 The idea is to show the door status via LEDs. 
– If the door is closed, the packages are safe in the truck: green LED is ON 
– If the door is open, we should warn: red LED is ON, or blinking (your 
choice) 
 Pins used in the solution (not required to be the same) 
– Green LED in pin 23 
– Red LED in pin 24 
– Switch in pin 17 
Copyright © 2014, Oracle and/or its affiliates. 34 All rights reserved.
The Wiring 
Copyright © 2014, Oracle and/or its affiliates. 35 All rights reserved. 
GPIO 17 
GPIO 23 
GPIO 24
The Wiring 
Copyright © 2014, Oracle and/or its affiliates. 36 All rights reserved. 
3V 
GND 
3V 
GND
Lesson 2.4: 
I2C Overview
Pressure / Tempurature 
Door open/close 
In this course, you will build a prototype of an embedded device to 
collect, store, analyze and share data from a shipping container. 
Copyright © 2014, Oracle and/or its affiliates. 38 All rights reserved. 
Pressure/ 
Temperature 
Location/ 
Altitude Storage Client Display 
I2C
Hardware 
BMP180 
 Measure barometric pressure and temperature 
 Specifications: 
– Pressure sensing range: 300-1100 hPa (9000m to -500m above sea level) 
– Up to 0.03hPa / 0.25m resolution 
– -40 to +85°C operational range, +-2°C temperature accuracy 
– 2-pin I2C interface on chip 
– Uses 3.3-5V power and logic level for more flexible usage 
Copyright © 2014, Oracle and/or its affiliates. 39 All rights reserved.
I²C Overview 
 Used for moving data simply and quickly from one device to another 
 Serial Interface 
 Synchronous: 
– The data (SDA) is sent along with a clock signal (SCL) 
– The clock signal controls when data is changed and when it should be 
read 
– Clock rate can vary, unlike asynchronous (RS-232 style) 
communications 
 Bidirectional 
Copyright © 2014, Oracle and/or its affiliates. 40 All rights reserved.
I2C In Few Words… 
 Inter-Integrated Circuit, ("two-wire interface") 
 Multi-master serial single-ended computer bus 
 Invented by Philips for attaching low-speed peripherals to a 
motherboard, embedded system, cellphone, or other electronic 
device. 
 Uses two bidirectional open-drain lines 
– Serial Data Line (SDA) and 
– Serial Clock (SCL), 
– pulled up with resistors. 
 Typical voltages used are +5 V or +3.3 V 
Copyright © 2014, Oracle and/or its affiliates. 41 All rights reserved.
I²C Design 
 A bus with a clock (SCL) and 
data (SDA) lines 
 7-bit addressing. 
 Roles: 
– Master: generates the clock and initiates communication with slaves 
– Slave: receives the clock and responds when addressed by the 
master 
 Multi-Master bus 
 Switch between master and slave allowed 
Copyright © 2014, Oracle and/or its affiliates. 42 All rights reserved.
I²C Communication Protocol 
START (S) and STOP (P) Conditions 
 Communication starts when master puts START condition (S) on 
the bus: HIGH-to-LOW transition of the SDA line while SCL line 
is HIGH 
 Bus is busy until master puts a STOP condition (P) on the bus: 
LOW to HIGH transition on the SDA line while SCL is HIGH 
Copyright © 2014, Oracle and/or its affiliates. 43 All rights reserved.
I²C Communication Protocol 
Data Format / Acknowledge 
 I2C data bytes are 8-bits long 
 Each byte transferred must be followed by acknowledge ACK signal 
Copyright © 2014, Oracle and/or its affiliates. 44 All rights reserved.
I²C Communication Protocol 
Communications 
Copyright © 2014, Oracle and/or its affiliates. 45 All rights reserved.
Lesson 2.5: 
Enabling I2C on the Rasperry 
Pi
I2C not enabled by default 
 /etc/modules 
– Add lines: i2c-bcm2708 
i2c-dev 
 Install i2c-tools. Handy for detecting devices 
– sudo apt-get install i2c-tools 
 /etc/modprobe.d/raspi-blacklist.conf comment out the lines 
– # blacklist spi-bcm2708 
– # blacklist i2c-bcm2708 
Copyright © 2014, Oracle and/or its affiliates. 47 All rights reserved.
Verifying that I2C is enabled 
 Can you see your device? 
– sudo i2cdetect -y 1 
Copyright © 2014, Oracle and/or its affiliates. 48 All rights reserved.
Lesson 2.6: 
Using I2C on the Raspberry Pi
Wiring and operating the BMP180 
 Raspberry Pi uses I2C bus 1 
 We’re using device address 0x77 
 I2C uses 7 bits for device address 
 BMP180 uses clock frequency 3.4MHz 
 Control register for BMP180 is 0xF4 
 Temperature value is at register 0xF6. 
Copyright © 2014, Oracle and/or its affiliates. 50 All rights reserved.
The Wiring 
Copyright © 2014, Oracle and/or its affiliates. 51 All rights reserved.
Reading and writing to I2C devices 
I2CDeviceConfig config = 
new I2CDeviceConfig(1, // I2C bus number 
Copyright © 2014, Oracle and/or its affiliates. 52 All rights reserved. 
0x77, // I2C device address 
7, // address size in bits 
3400000); // Clock frequency 
myDevice = DeviceManager.open(config); 
myDevice.write(0xF4, 1, 0x2E); // control register, size, 
// get temperature command 
myDevice.read(0xF6, 1, buf); // temperature register, 
// subaddress size, ByteBuffer
Lesson 3: 
Using the UART, GPS, and 
Storing Data
Door open/close 
GPS, UART RMS 
In this course, you will build a prototype of an embedded device to 
collect, store, analyze and share data from a shipping container. 
Copyright © 2014, Oracle and/or its affiliates. 54 All rights reserved. 
Pressure/ 
Temperature 
Location/ 
Altitude Storage Client Display
Lesson Agenda 
 UART serial protocol overview 
 GPS overview 
 Connecting the GPS sensor using a USB UART cable 
 Connecting the GPS directly to the Raspberry Pi UART 
 Reading GPS data in a Java ME 8 Embedded application 
 Saving GPS data in the Record Management Store 
 Saving GPS data in a file 
Copyright © 2014, Oracle and/or its affiliates. 55 All rights reserved.
Lesson 3-1: 
UART Serial Protocol Overview
UART Serial Protocol 
The Basics 
 UART = Universal Asynchronous Receiver and Transmitter 
 Serial communication 
– Each bit is sent one after the other 
 Both ends must be set to work at the same speed 
– bits per second 
– Standard speeds (9600, 19200, 115200, etc) 
– Some devices use non-standard speeds 
 At idle, with no data the connection is held high (voltage) 
Copyright © 2014, Oracle and/or its affiliates. 57 All rights reserved.
UART Protocol 
Character Frame 
Start Data 0 Data 1 Data 2 Data 3 Data 4 Data 5 Data 6 Data 7 Parity Stop 1 Stop 2 
Copyright © 2014, Oracle and/or its affiliates. 58 All rights reserved. 
Data (5-9 bits) 
LOGIC 
LOW (0) 
LOGIC 
HIGH (1) 
LOGIC 
HIGH (1)
Serial Data Transmission 
 UART does not usually drive transmission of data 
– RS-232, RS-422, RS-485 
 Transmission does not need to be electrical 
– Bluetooth serial port profile 
– Infra red (IRDa) 
– Acoustic modem (telephone line) 
Copyright © 2014, Oracle and/or its affiliates. 59 All rights reserved.
Lesson 3-2: 
GPS Overview
Global Positioning System 
Image courtesy of Wikipedia 
Copyright © 2014, Oracle and/or its affiliates. 61 All rights reserved.
GPS 
Satellite Navigation System 
 Position is calculated using satellites that continually transmit data 
– Time and the position above the earth 
 Minimum of three satellites required to get position 
– latitude and longitude 
 Four satellites required to get 3D position fix 
– latitude/longitude/altitude 
Copyright © 2014, Oracle and/or its affiliates. 62 All rights reserved.
GPS Receiver 
Data Format 
 GPS receivers typically use NMEA 0183 standard 
– National Marine Electronics Association 
 Text based protocol 
– Message starts with a $ sign 
– Next five letters identify the talker (2 letters) and type (3 letters) 
 GPS receiver talker code is GP 
– Data fields are comma separated 
– Message contains optional aterisk * and two digit checksum at the end 
– Message is terminated with carriage return, line feed (13, 10 ASCII) 
Copyright © 2014, Oracle and/or its affiliates. 63 All rights reserved.
GPS Receiver 
Useful Data Packets 
 $GPGGA – GPS fix data 
– Time 
– Latitude, [N/S] 
– Longitude, [E/W] 
– Fix quality 
– Number of satellites being tracked 
– Horizontal dilution 
– Altitude (m) 
– More fields of no direct use 
Copyright © 2014, Oracle and/or its affiliates. 64 All rights reserved.
GPS Receiver 
Useful Data Packets 
 $GPVTG – Velocity made good 
– True track made good (degrees), T 
– Magnetic track made good, M 
– Ground speed (knots), N 
– Ground speed (Km/h), K 
Copyright © 2014, Oracle and/or its affiliates. 65 All rights reserved.
Extracting Data From A Packet 
Using StringTokenizer 
StringTokenizer tokenizer = new StringTokenizer(input, ",", true); 
boolean tokenWasDelimiter = false; 
while (tokenizer.hasMoreTokens()) { 
String token = tokenizer.nextToken(); 
if (!token.equals(",")) { 
fields.add(token); 
tokenWasDelimiter = false; 
} else { 
if (tokenWasDelimiter) 
fields.add(" "); 
tokenWasDelimiter = true; 
} 
} 
Copyright © 2014, Oracle and/or its affiliates. 66 All rights reserved.
Extracting Data From A Packet 
Roll Your Own CSV Extractor 
ArrayList<String> fields = new ArrayList<>(); 
fields.clear(); 
int start = 0; 
int end; 
while ((end = input.indexOf(",", start)) != -1) { 
fields.add(input.substring(start, end); 
start = end + 1; 
} 
fields.add(input.substring(start)); 
Copyright © 2014, Oracle and/or its affiliates. 67 All rights reserved.
Data Encapsulation 
 Position 
– Time stamp 
– Latitude, latitude direction (N or S) 
– Longitude, longitude direction (E or W) 
– Altitude (metres above sea level) 
 Velocity 
– Time stamp 
– Bearing (degrees from north) 
– Velocity (Km/h) 
Copyright © 2014, Oracle and/or its affiliates. 68 All rights reserved.
Output Data 
 Client wants CSV format 
 Override the toString() method 
public String toString() { 
Formatter f = new Formatter(); 
return f.format("%d,%.3f,%c,%.3f,%c,%.2f", 
latitude, latitudeDirection, 
longitude, longitudeDirection, 
altitude); 
} 
Copyright © 2014, Oracle and/or its affiliates. 69 All rights reserved.
Lesson 3-3: 
Connecting the GPS Sensor 
To The Raspberry Pi
Connection Methods 
1. Using a USB to TTL UART adapter 
2. Direct connection to the Raspberry Pi header pins 
Copyright © 2014, Oracle and/or its affiliates. 71 All rights reserved.
Raspberry Pi USB Connectors 
Copyright © 2014, Oracle and/or its affiliates. 72 All rights reserved. 
 2 x USB 2.0 Type A sockets 
– Host USB 
 Differs slightly from USB 
specification 
– Power should be 500mA max 
– Actual is less than 200mA 
 Can power the board through 
 Micro USB socket these 
- Power only
USB UART Cable 
PL2003 UART TTL-USB 
Copyright © 2014, Oracle and/or its affiliates. 73 All rights reserved. 
USB Adapter 
(Vcc can be +3.3V or +5V) 
GND (Black) 
Vcc +5V (Red) 
TX (Green) 
RX (White)
USB UART Adapter Connections 
Copyright © 2014, Oracle and/or its affiliates. 74 All rights reserved. 
USB Green connects to GPS RX 
USB White connects to GPS TX
USB UART Raspberry Pi Configuration 
 Plug in USB UART adapter to Raspberry Pi 
 Device to use is /dev/ttyUSB0 
Copyright © 2014, Oracle and/or its affiliates. 75 All rights reserved.
Raspberry Pi Headers 
Connections (P1) 
- GPIO 
- I2C 
- SPI 
- UART 
Display (Not supported) 
Copyright © 2014, Oracle and/or its affiliates. 76 All rights reserved. 
JTAG 
P2 = Processor 
P3 = LAN 
Camera
Header Pin Layout 
P1-01 
5 
V 
GND 
0 (SDA) 
1 (SCL) 
{UART 
14 (TXD) 
Copyright © 2014, Oracle and/or its affiliates. 77 All rights reserved. 
15 (RXD) 
Power 
GPIO 
UART 
I2C 
SPI 
18 23 24 25 8 7 
10 
(MOSI) 
9 (MISO) 
11 (SCLK) 
4 17 27 22 
3.3V 
5V GND GND 
GND GND GND
UART Connections 
P1-01 
Copyright © 2014, Oracle and/or its affiliates. 78 All rights reserved. 
TX 
RX 
NOTE: RX TX 
TX RX
Raspberry Pi UART Configuration 
 Device to use is /dev/ttyAMA0 
 This is also used as the console 
– Boot messages 
– Login prompt 
 Edit /etc/inittab 
– Comment out line for console 
– # T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100 
 Edit /boot/cmdline.txt 
– Delete console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 
 Reboot 
Copyright © 2014, Oracle and/or its affiliates. 79 All rights reserved.
Lesson 3-4: 
Reading GPS Data in a Java 
ME 8 Embedded Application
Using The UART 
Getting a BufferedReader 
UART uart = DeviceManager.open(40); //UART ID # 
uart.setBaudRate(9600); 
InputStream is = Channels.newInputStream(uart); 
InputStreamreader isr = new InputStreamReader(is); 
BufferedReader reader = new BufferedReader(isr); 
Copyright © 2014, Oracle and/or its affiliates. 81 All rights reserved.
UART Device Security 
 Need to add API permission 
– Application Descriptor 
– Permission 
 jdk.dio.DeviceMgmtPermission 
– Protected resource name 
 *:* 
– Actions requested 
 open 
Copyright © 2014, Oracle and/or its affiliates. 82 All rights reserved.
Reading GPS Data 
 All data lines start with $ 
– Read lines until we get one with the right start character 
 Check the talker is GP 
 Test for the correct type (GGA or VTG) 
 Decode comma separated values 
 Data appears to be easily corrupted 
– Short reads, $ in middle of line, not enough fields 
– Repeat reads until valid data extracted 
Copyright © 2014, Oracle and/or its affiliates. 83 All rights reserved.
Lesson 3-5: 
Saving GPS Data in the 
Record Management System
Door open/close 
GPS, UART RMS 
In this course, you will build a prototype of an embedded device to 
collect, store, analyze and share data from a shipping container. 
Copyright © 2014, Oracle and/or its affiliates. 85 All rights reserved. 
Pressure/ 
Temperature 
Location/ 
Altitude Storage Client Display
Our Midlet suite 
Stores and retrieves sensor data 
DataRecorder 
Suite 
RecorderMidlet 
ReaderMidlet 
ServerMidlet 
Copyright © 2014, Oracle and/or its affiliates. 86 All rights reserved. 
Sensor data in 
RMS RecordStore
Record Management System (RMS) Overview 
Defined in Java ME Embedded Profile 8.0 
 Java ME does not rely on being able to store data in files 
– Some small and embedded devices do not have file systems 
 Java ME stores application data in non-volatile memory 
– How this happens is abstracted away by the RMS 
 RMS can be thought of as a very simple database 
– Two columns 
 Record ID 
 Data (array of bytes) 
Copyright © 2014, Oracle and/or its affiliates. 87 All rights reserved.
RecordStore 
Storing Data 
RecordStore store = RecordStore.openRecordStore("gps-data", true); 
String data = position.toString() + "^" + velocity.toString(); 
byte[] dataBytes = data.getBytes(); 
int recordNum = store.addRecord(dataBytes, 0, dataBytes.length); 
Copyright © 2014, Oracle and/or its affiliates. 88 All rights reserved.
RecordStore 
Retrieving Data 
 Create a new Midlet in the same Midlet suite as the data recorder 
 Records are retrieved as byte arrays 
RecordStore store = RecordStore.openRecordStore("gps-data", false); 
recordCount = store.getNumRecords(); 
for (int i = 1; i < recordCount; i++) // record index is 1 based 
System.out.println("Record " + i + " = " + 
new String(store.getRecord(i)); 
Copyright © 2014, Oracle and/or its affiliates. 89 All rights reserved.
Record Store Persistence 
 The persistence of the Record Store is tied to the MIDlet suite 
 When the MIDlet suite is removed from the device (destroyed) 
– The Record Store for that suite is deleted 
Copyright © 2014, Oracle and/or its affiliates. 90 All rights reserved.
Lesson 3-6: 
Saving GPS Data in a File
Java ME And Files Overview 
 Raspberry Pi has conventional filesystem 
– So data can be stored there 
– Java ME supports this through the Generic Connection Framework 
 Be careful with file URI 
– Format is file://[root]/[file-path] 
– Example file, /tmp/gps-data.txt 
– URI is file://rootfs/tmp/gps-data.txt 
Copyright © 2014, Oracle and/or its affiliates. 92 All rights reserved.
Java ME File IO 
Generic Connection Framework: FileConnection 
private final FileConnection connection; 
private final PrintStream fileWriter; 
connection = 
(FileConnection)Connector.open( 
"file://rootfs/tmp/gps-data.txt", 
Connector.READ_WRITE); 
if (!connection.exists()) 
connection.create(); 
Copyright © 2014, Oracle and/or its affiliates. 93 All rights reserved.
Java ME File IO 
Use Generic Connection Framework 
fileWriter = new PrintStream( 
connection.openOutputStream()); 
fileWriter.println(position + "^" + velocity); 
Copyright © 2014, Oracle and/or its affiliates. 94 All rights reserved.
File Access 
API Permissions 
 To allow file access from the Midlet/Imlet add API permissions 
– javax.microedition.io.Connector.file.read 
– javax.microedition.io.Connector.file.write 
 No protected resource name or action requests are required 
Copyright © 2014, Oracle and/or its affiliates. 95 All rights reserved.
Lesson 4: 
Communicating the Data to 
the Outside World
In the grand scheme of this course … 
Door open/close 
You are here 
JavaFX 
In this course, you are building a prototype of an embedded device to 
collect, store, analyze and share data from a shipping container. 
Copyright © 2014, Oracle and/or its affiliates. 97 All rights reserved. 
Pressure/ 
Temperature 
Location/ 
Altitude Storage Client Display
Lesson 4-1: 
Demo a MIDlet that serves 
sensor data, and a client app 
that communicates with it
Two more pieces of the prototype puzzle … 
An app named VisualClient that communicates with ServerMidlet 
DataRecorder 
Suite 
RecorderMidlet 
ReaderMidlet 
ServerMidlet 
Copyright © 2014, Oracle and/or its affiliates. 99 All rights reserved. 
Sensor data in 
RMS RecordStore
Taking ServerMidlet and VisualClient for a spin 
Copyright © 2014, Oracle and/or its affiliates. 100 All rights reserved. 
VisualClient is created 
with Java/JavaFX and 
the SceneBuilder tool
VisualClient and ServerMidlet 
Copyright © 2014, Oracle and/or its affiliates. 101 All rights reserved.
Safe Harbor Statement 
The preceding is intended to outline our general product direction. It is intended for 
information purposes only, and may not be incorporated into any contract. It is not 
a commitment to deliver any material, code, or functionality, and should not be 
relied upon in making purchasing decisions. The development, release, and timing 
of any features or functionality described for Oracle’s products remains at the sole 
discretion of Oracle. 
Copyright © 2014, Oracle and/or its affiliates. 102 All rights reserved.
Raspberry Pi with Java 8 
Intro to Pi and Java ME 8 – James Weaver 
Brief demos by student programming contest winners 
Using Pi4J – Robert Savage 
Raspberry Pi Tricks – Stephen Chin 
#DV14 #RPiJava8 @SteveOnJava @SavageAutomate @JavaFXpert

More Related Content

What's hot

20081114 Friday Food iLabt Bart Joris
20081114 Friday Food iLabt Bart Joris20081114 Friday Food iLabt Bart Joris
20081114 Friday Food iLabt Bart Jorisimec.archive
 
Processor Verification Using Open Source Tools and the GCC Regression Test Suite
Processor Verification Using Open Source Tools and the GCC Regression Test SuiteProcessor Verification Using Open Source Tools and the GCC Regression Test Suite
Processor Verification Using Open Source Tools and the GCC Regression Test SuiteDVClub
 
Running TFLite on Your Mobile Devices, 2020
Running TFLite on Your Mobile Devices, 2020Running TFLite on Your Mobile Devices, 2020
Running TFLite on Your Mobile Devices, 2020Koan-Sin Tan
 
Vlsi lab manual exp:1
Vlsi lab manual exp:1Vlsi lab manual exp:1
Vlsi lab manual exp:1komala vani
 
VHDL Practical Exam Guide
VHDL Practical Exam GuideVHDL Practical Exam Guide
VHDL Practical Exam GuideEslam Mohammed
 
Virtual platform
Virtual platformVirtual platform
Virtual platformsean chen
 
Exploring Thermal Related Stuff in iDevices using Open-Source Tool
Exploring Thermal Related Stuff in iDevices using Open-Source ToolExploring Thermal Related Stuff in iDevices using Open-Source Tool
Exploring Thermal Related Stuff in iDevices using Open-Source ToolKoan-Sin Tan
 
Artificial Neural Networks on a Tic Tac Toe console application
Artificial Neural Networks on a Tic Tac Toe console applicationArtificial Neural Networks on a Tic Tac Toe console application
Artificial Neural Networks on a Tic Tac Toe console applicationEduardo Gulias Davis
 
Introduction to FPGA, VHDL
Introduction to FPGA, VHDL  Introduction to FPGA, VHDL
Introduction to FPGA, VHDL Amr Rashed
 
Wireless Temperature Measurement with LabVIEW and Spartan3E
Wireless Temperature Measurement with LabVIEW and Spartan3EWireless Temperature Measurement with LabVIEW and Spartan3E
Wireless Temperature Measurement with LabVIEW and Spartan3EVincent Claes
 
Micrcontroller iv sem lab manual
Micrcontroller iv sem lab manualMicrcontroller iv sem lab manual
Micrcontroller iv sem lab manualRohiniHM2
 
Introduction to Arduino Microcontroller
Introduction to Arduino MicrocontrollerIntroduction to Arduino Microcontroller
Introduction to Arduino MicrocontrollerMujahid Hussain
 
Glow user review
Glow user reviewGlow user review
Glow user review冠旭 陳
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?Doug Hawkins
 
Vlsi lab manual exp:2
Vlsi lab manual exp:2Vlsi lab manual exp:2
Vlsi lab manual exp:2komala vani
 
Intro to Arduino
Intro to ArduinoIntro to Arduino
Intro to ArduinoQtechknow
 
One bite and all your dreams will come true: Analyzing and Attacking Apple Ke...
One bite and all your dreams will come true: Analyzing and Attacking Apple Ke...One bite and all your dreams will come true: Analyzing and Attacking Apple Ke...
One bite and all your dreams will come true: Analyzing and Attacking Apple Ke...Priyanka Aash
 
Hackathon Taiwan 5th : Arduino 101
Hackathon Taiwan  5th : Arduino 101 Hackathon Taiwan  5th : Arduino 101
Hackathon Taiwan 5th : Arduino 101 twunishen
 

What's hot (20)

20081114 Friday Food iLabt Bart Joris
20081114 Friday Food iLabt Bart Joris20081114 Friday Food iLabt Bart Joris
20081114 Friday Food iLabt Bart Joris
 
Processor Verification Using Open Source Tools and the GCC Regression Test Suite
Processor Verification Using Open Source Tools and the GCC Regression Test SuiteProcessor Verification Using Open Source Tools and the GCC Regression Test Suite
Processor Verification Using Open Source Tools and the GCC Regression Test Suite
 
Running TFLite on Your Mobile Devices, 2020
Running TFLite on Your Mobile Devices, 2020Running TFLite on Your Mobile Devices, 2020
Running TFLite on Your Mobile Devices, 2020
 
Vlsi lab manual exp:1
Vlsi lab manual exp:1Vlsi lab manual exp:1
Vlsi lab manual exp:1
 
VHDL Practical Exam Guide
VHDL Practical Exam GuideVHDL Practical Exam Guide
VHDL Practical Exam Guide
 
Virtual platform
Virtual platformVirtual platform
Virtual platform
 
Exploring Thermal Related Stuff in iDevices using Open-Source Tool
Exploring Thermal Related Stuff in iDevices using Open-Source ToolExploring Thermal Related Stuff in iDevices using Open-Source Tool
Exploring Thermal Related Stuff in iDevices using Open-Source Tool
 
Artificial Neural Networks on a Tic Tac Toe console application
Artificial Neural Networks on a Tic Tac Toe console applicationArtificial Neural Networks on a Tic Tac Toe console application
Artificial Neural Networks on a Tic Tac Toe console application
 
Introduction to FPGA, VHDL
Introduction to FPGA, VHDL  Introduction to FPGA, VHDL
Introduction to FPGA, VHDL
 
Wireless Temperature Measurement with LabVIEW and Spartan3E
Wireless Temperature Measurement with LabVIEW and Spartan3EWireless Temperature Measurement with LabVIEW and Spartan3E
Wireless Temperature Measurement with LabVIEW and Spartan3E
 
Micrcontroller iv sem lab manual
Micrcontroller iv sem lab manualMicrcontroller iv sem lab manual
Micrcontroller iv sem lab manual
 
FPGA workshop
FPGA workshopFPGA workshop
FPGA workshop
 
Introduction to Arduino Microcontroller
Introduction to Arduino MicrocontrollerIntroduction to Arduino Microcontroller
Introduction to Arduino Microcontroller
 
Glow user review
Glow user reviewGlow user review
Glow user review
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?
 
Vlsi lab manual exp:2
Vlsi lab manual exp:2Vlsi lab manual exp:2
Vlsi lab manual exp:2
 
Intro to Arduino
Intro to ArduinoIntro to Arduino
Intro to Arduino
 
Vlsi lab
Vlsi labVlsi lab
Vlsi lab
 
One bite and all your dreams will come true: Analyzing and Attacking Apple Ke...
One bite and all your dreams will come true: Analyzing and Attacking Apple Ke...One bite and all your dreams will come true: Analyzing and Attacking Apple Ke...
One bite and all your dreams will come true: Analyzing and Attacking Apple Ke...
 
Hackathon Taiwan 5th : Arduino 101
Hackathon Taiwan  5th : Arduino 101 Hackathon Taiwan  5th : Arduino 101
Hackathon Taiwan 5th : Arduino 101
 

Viewers also liked

Raspberry pi on java at Java8 Launching Event in Japan
Raspberry pi on java at Java8 Launching Event in JapanRaspberry pi on java at Java8 Launching Event in Japan
Raspberry pi on java at Java8 Launching Event in JapanMasafumi Ohta
 
徹底解説!Project Lambdaのすべて リターンズ[祝Java8Launch #jjug]
徹底解説!Project Lambdaのすべて リターンズ[祝Java8Launch #jjug]徹底解説!Project Lambdaのすべて リターンズ[祝Java8Launch #jjug]
徹底解説!Project Lambdaのすべて リターンズ[祝Java8Launch #jjug]bitter_fox
 
What’s new in Java SE, EE, ME, Embedded world & new Strategy
What’s new in Java SE, EE, ME, Embedded world & new StrategyWhat’s new in Java SE, EE, ME, Embedded world & new Strategy
What’s new in Java SE, EE, ME, Embedded world & new StrategyMohamed Taman
 
Rightbrain - UX trend report - July, 2014
Rightbrain - UX trend report - July, 2014Rightbrain - UX trend report - July, 2014
Rightbrain - UX trend report - July, 2014RightBrain
 
Raspberry pi weather storey
Raspberry pi weather storey Raspberry pi weather storey
Raspberry pi weather storey Dominic Storey
 
Build a Java and Raspberry Pi weather station
Build a Java and Raspberry Pi weather station Build a Java and Raspberry Pi weather station
Build a Java and Raspberry Pi weather station Marco Pirruccio
 
The Raspberry Pi JavaFX Carputer
The Raspberry Pi JavaFX CarputerThe Raspberry Pi JavaFX Carputer
The Raspberry Pi JavaFX CarputerSimon Ritter
 
JAX 2014 - M2M for Java Developers with MQTT
JAX 2014 - M2M for Java Developers with MQTTJAX 2014 - M2M for Java Developers with MQTT
JAX 2014 - M2M for Java Developers with MQTTDominik Obermaier
 
04강 라즈베리-개발환경구축-실습
04강 라즈베리-개발환경구축-실습04강 라즈베리-개발환경구축-실습
04강 라즈베리-개발환경구축-실습봉조 김
 
Autonomous Drone Development with Java and IoT
Autonomous Drone Development with Java and IoTAutonomous Drone Development with Java and IoT
Autonomous Drone Development with Java and IoTjavafxpert
 
Oracle IoT Kids Workshop
Oracle IoT Kids WorkshopOracle IoT Kids Workshop
Oracle IoT Kids WorkshopStephen Chin
 
JavaFX 8 - GUI by Illusion
JavaFX 8 - GUI by IllusionJavaFX 8 - GUI by Illusion
JavaFX 8 - GUI by IllusionYuichi Sakuraba
 
Java 8 for Tablets, Pis, and Legos
Java 8 for Tablets, Pis, and LegosJava 8 for Tablets, Pis, and Legos
Java 8 for Tablets, Pis, and LegosStephen Chin
 
Raspberry Pi (Introduction)
Raspberry Pi (Introduction)Raspberry Pi (Introduction)
Raspberry Pi (Introduction)Mandeesh Singh
 
A seminar report on Raspberry Pi
A seminar report on Raspberry PiA seminar report on Raspberry Pi
A seminar report on Raspberry Pinipunmaster
 
Smart Wireless Surveillance Monitoring using RASPBERRY PI
Smart Wireless Surveillance Monitoring using RASPBERRY PISmart Wireless Surveillance Monitoring using RASPBERRY PI
Smart Wireless Surveillance Monitoring using RASPBERRY PIKrishna Kumar
 
Eclipse Kura Shoot a-pi
Eclipse Kura Shoot a-piEclipse Kura Shoot a-pi
Eclipse Kura Shoot a-piEclipse Kura
 

Viewers also liked (20)

UART
UARTUART
UART
 
Raspberry pi on java at Java8 Launching Event in Japan
Raspberry pi on java at Java8 Launching Event in JapanRaspberry pi on java at Java8 Launching Event in Japan
Raspberry pi on java at Java8 Launching Event in Japan
 
徹底解説!Project Lambdaのすべて リターンズ[祝Java8Launch #jjug]
徹底解説!Project Lambdaのすべて リターンズ[祝Java8Launch #jjug]徹底解説!Project Lambdaのすべて リターンズ[祝Java8Launch #jjug]
徹底解説!Project Lambdaのすべて リターンズ[祝Java8Launch #jjug]
 
What’s new in Java SE, EE, ME, Embedded world & new Strategy
What’s new in Java SE, EE, ME, Embedded world & new StrategyWhat’s new in Java SE, EE, ME, Embedded world & new Strategy
What’s new in Java SE, EE, ME, Embedded world & new Strategy
 
Rightbrain - UX trend report - July, 2014
Rightbrain - UX trend report - July, 2014Rightbrain - UX trend report - July, 2014
Rightbrain - UX trend report - July, 2014
 
Raspberry pi weather storey
Raspberry pi weather storey Raspberry pi weather storey
Raspberry pi weather storey
 
Build a Java and Raspberry Pi weather station
Build a Java and Raspberry Pi weather station Build a Java and Raspberry Pi weather station
Build a Java and Raspberry Pi weather station
 
The Raspberry Pi JavaFX Carputer
The Raspberry Pi JavaFX CarputerThe Raspberry Pi JavaFX Carputer
The Raspberry Pi JavaFX Carputer
 
JAX 2014 - M2M for Java Developers with MQTT
JAX 2014 - M2M for Java Developers with MQTTJAX 2014 - M2M for Java Developers with MQTT
JAX 2014 - M2M for Java Developers with MQTT
 
UX trend report 2014 lite version (by UX1)
UX trend report 2014 lite version (by UX1)UX trend report 2014 lite version (by UX1)
UX trend report 2014 lite version (by UX1)
 
The Java Carputer
The Java CarputerThe Java Carputer
The Java Carputer
 
04강 라즈베리-개발환경구축-실습
04강 라즈베리-개발환경구축-실습04강 라즈베리-개발환경구축-실습
04강 라즈베리-개발환경구축-실습
 
Autonomous Drone Development with Java and IoT
Autonomous Drone Development with Java and IoTAutonomous Drone Development with Java and IoT
Autonomous Drone Development with Java and IoT
 
Oracle IoT Kids Workshop
Oracle IoT Kids WorkshopOracle IoT Kids Workshop
Oracle IoT Kids Workshop
 
JavaFX 8 - GUI by Illusion
JavaFX 8 - GUI by IllusionJavaFX 8 - GUI by Illusion
JavaFX 8 - GUI by Illusion
 
Java 8 for Tablets, Pis, and Legos
Java 8 for Tablets, Pis, and LegosJava 8 for Tablets, Pis, and Legos
Java 8 for Tablets, Pis, and Legos
 
Raspberry Pi (Introduction)
Raspberry Pi (Introduction)Raspberry Pi (Introduction)
Raspberry Pi (Introduction)
 
A seminar report on Raspberry Pi
A seminar report on Raspberry PiA seminar report on Raspberry Pi
A seminar report on Raspberry Pi
 
Smart Wireless Surveillance Monitoring using RASPBERRY PI
Smart Wireless Surveillance Monitoring using RASPBERRY PISmart Wireless Surveillance Monitoring using RASPBERRY PI
Smart Wireless Surveillance Monitoring using RASPBERRY PI
 
Eclipse Kura Shoot a-pi
Eclipse Kura Shoot a-piEclipse Kura Shoot a-pi
Eclipse Kura Shoot a-pi
 

Similar to Raspberry Pi with Java 8

Syed IoT - module 5
Syed  IoT - module 5Syed  IoT - module 5
Syed IoT - module 5Syed Mustafa
 
Scripting Things - Creating the Internet of Things with Perl
Scripting Things - Creating the Internet of Things with PerlScripting Things - Creating the Internet of Things with Perl
Scripting Things - Creating the Internet of Things with PerlHans Scharler
 
Arduino Slides With Neopixels
Arduino Slides With NeopixelsArduino Slides With Neopixels
Arduino Slides With Neopixelssdcharle
 
Interface stepper motor through Arduino using LABVIEW.
Interface stepper motor through Arduino using LABVIEW.Interface stepper motor through Arduino using LABVIEW.
Interface stepper motor through Arduino using LABVIEW.Ankita Tiwari
 
Arduino Workshop Slides
Arduino Workshop SlidesArduino Workshop Slides
Arduino Workshop Slidesmkarlin14
 
Arduino slides
Arduino slidesArduino slides
Arduino slidessdcharle
 
Arduino programming
Arduino programmingArduino programming
Arduino programmingSiji Sunny
 
Pushing Java EE outside of the Enterprise - Home Automation
Pushing Java EE outside of the Enterprise - Home AutomationPushing Java EE outside of the Enterprise - Home Automation
Pushing Java EE outside of the Enterprise - Home AutomationDavid Delabassee
 
Pushing Java EE outside of the Enterprise: Home Automation and IoT - David De...
Pushing Java EE outside of the Enterprise: Home Automation and IoT - David De...Pushing Java EE outside of the Enterprise: Home Automation and IoT - David De...
Pushing Java EE outside of the Enterprise: Home Automation and IoT - David De...JAXLondon2014
 
IoT Arduino UNO, RaspberryPi with Python, RaspberryPi Programming using Pytho...
IoT Arduino UNO, RaspberryPi with Python, RaspberryPi Programming using Pytho...IoT Arduino UNO, RaspberryPi with Python, RaspberryPi Programming using Pytho...
IoT Arduino UNO, RaspberryPi with Python, RaspberryPi Programming using Pytho...Jayanthi Kannan MK
 
Programable logic controller.pdf
Programable logic controller.pdfProgramable logic controller.pdf
Programable logic controller.pdfsravan66
 
Summer Internship Report on PLC
Summer Internship Report on PLCSummer Internship Report on PLC
Summer Internship Report on PLCSudeep Giri
 
Workshop on IoT and Basic Home Automation_BAIUST.pptx
Workshop on IoT and Basic Home Automation_BAIUST.pptxWorkshop on IoT and Basic Home Automation_BAIUST.pptx
Workshop on IoT and Basic Home Automation_BAIUST.pptxRedwan Ferdous
 
Summer Internship Report For PLC Programming of Traffic light through Ladder ...
Summer Internship Report For PLC Programming of Traffic light through Ladder ...Summer Internship Report For PLC Programming of Traffic light through Ladder ...
Summer Internship Report For PLC Programming of Traffic light through Ladder ...Aman Gupta
 
NSTA 2013 Denver - ArduBlock and Arduino
NSTA 2013 Denver - ArduBlock and ArduinoNSTA 2013 Denver - ArduBlock and Arduino
NSTA 2013 Denver - ArduBlock and ArduinoBrian Huang
 
Not so hard hardware
Not so hard hardwareNot so hard hardware
Not so hard hardwarerichardgault
 
Door_Control_Unit_User_Manual_2.pdf
Door_Control_Unit_User_Manual_2.pdfDoor_Control_Unit_User_Manual_2.pdf
Door_Control_Unit_User_Manual_2.pdfnyakmutia2
 

Similar to Raspberry Pi with Java 8 (20)

Syed IoT - module 5
Syed  IoT - module 5Syed  IoT - module 5
Syed IoT - module 5
 
Scripting Things - Creating the Internet of Things with Perl
Scripting Things - Creating the Internet of Things with PerlScripting Things - Creating the Internet of Things with Perl
Scripting Things - Creating the Internet of Things with Perl
 
IoT with Arduino
IoT with ArduinoIoT with Arduino
IoT with Arduino
 
Arduino Slides With Neopixels
Arduino Slides With NeopixelsArduino Slides With Neopixels
Arduino Slides With Neopixels
 
Interface stepper motor through Arduino using LABVIEW.
Interface stepper motor through Arduino using LABVIEW.Interface stepper motor through Arduino using LABVIEW.
Interface stepper motor through Arduino using LABVIEW.
 
Arduino Workshop Slides
Arduino Workshop SlidesArduino Workshop Slides
Arduino Workshop Slides
 
Arduino slides
Arduino slidesArduino slides
Arduino slides
 
Arduino programming
Arduino programmingArduino programming
Arduino programming
 
Pushing Java EE outside of the Enterprise - Home Automation
Pushing Java EE outside of the Enterprise - Home AutomationPushing Java EE outside of the Enterprise - Home Automation
Pushing Java EE outside of the Enterprise - Home Automation
 
Pushing Java EE outside of the Enterprise: Home Automation and IoT - David De...
Pushing Java EE outside of the Enterprise: Home Automation and IoT - David De...Pushing Java EE outside of the Enterprise: Home Automation and IoT - David De...
Pushing Java EE outside of the Enterprise: Home Automation and IoT - David De...
 
IoT Arduino UNO, RaspberryPi with Python, RaspberryPi Programming using Pytho...
IoT Arduino UNO, RaspberryPi with Python, RaspberryPi Programming using Pytho...IoT Arduino UNO, RaspberryPi with Python, RaspberryPi Programming using Pytho...
IoT Arduino UNO, RaspberryPi with Python, RaspberryPi Programming using Pytho...
 
Programable logic controller.pdf
Programable logic controller.pdfProgramable logic controller.pdf
Programable logic controller.pdf
 
Summer Internship Report on PLC
Summer Internship Report on PLCSummer Internship Report on PLC
Summer Internship Report on PLC
 
Workshop on IoT and Basic Home Automation_BAIUST.pptx
Workshop on IoT and Basic Home Automation_BAIUST.pptxWorkshop on IoT and Basic Home Automation_BAIUST.pptx
Workshop on IoT and Basic Home Automation_BAIUST.pptx
 
Summer Internship Report For PLC Programming of Traffic light through Ladder ...
Summer Internship Report For PLC Programming of Traffic light through Ladder ...Summer Internship Report For PLC Programming of Traffic light through Ladder ...
Summer Internship Report For PLC Programming of Traffic light through Ladder ...
 
NSTA 2013 Denver - ArduBlock and Arduino
NSTA 2013 Denver - ArduBlock and ArduinoNSTA 2013 Denver - ArduBlock and Arduino
NSTA 2013 Denver - ArduBlock and Arduino
 
Uvais
Uvais Uvais
Uvais
 
What is a PLC ?
What is a PLC ?What is a PLC ?
What is a PLC ?
 
Not so hard hardware
Not so hard hardwareNot so hard hardware
Not so hard hardware
 
Door_Control_Unit_User_Manual_2.pdf
Door_Control_Unit_User_Manual_2.pdfDoor_Control_Unit_User_Manual_2.pdf
Door_Control_Unit_User_Manual_2.pdf
 

More from javafxpert

Machine Learning Exposed!
Machine Learning Exposed!Machine Learning Exposed!
Machine Learning Exposed!javafxpert
 
J-Fall 2014 Community Keynote by Oracle
J-Fall 2014 Community Keynote by OracleJ-Fall 2014 Community Keynote by Oracle
J-Fall 2014 Community Keynote by Oraclejavafxpert
 
What's New in Java 8
What's New in Java 8What's New in Java 8
What's New in Java 8javafxpert
 
Scratching the Surface with JavaFX
Scratching the Surface with JavaFXScratching the Surface with JavaFX
Scratching the Surface with JavaFXjavafxpert
 
Asean dev-days-slides
Asean dev-days-slidesAsean dev-days-slides
Asean dev-days-slidesjavafxpert
 

More from javafxpert (6)

Machine Learning Exposed!
Machine Learning Exposed!Machine Learning Exposed!
Machine Learning Exposed!
 
Java 101
Java 101Java 101
Java 101
 
J-Fall 2014 Community Keynote by Oracle
J-Fall 2014 Community Keynote by OracleJ-Fall 2014 Community Keynote by Oracle
J-Fall 2014 Community Keynote by Oracle
 
What's New in Java 8
What's New in Java 8What's New in Java 8
What's New in Java 8
 
Scratching the Surface with JavaFX
Scratching the Surface with JavaFXScratching the Surface with JavaFX
Scratching the Surface with JavaFX
 
Asean dev-days-slides
Asean dev-days-slidesAsean dev-days-slides
Asean dev-days-slides
 

Recently uploaded

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 

Recently uploaded (20)

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 

Raspberry Pi with Java 8

  • 1. Raspberry Pi with Java 8 Intro to Raspberry Pi and Java ME 8 – James Weaver Brief demos by student programming contest winners Using Pi4J – Robert Savage Raspberry Pi Tricks – Stephen Chin #DV14 #RPiJava8 @SteveOnJava @SavageAutomate @JavaFXpert
  • 2. Copyright © 2014, Oracle and/or its affiliates. 2 All rights reserved. 2 About the first presenter #RPiJava8 #DV14  James Weaver – Java Technology Ambassador – Oracle Corporation – Twitter: @JavaFXpert – Email: james.weaver@oracle.com
  • 3. Presentation based upon freely available MOOC Copyright © 2014, Oracle and/or its affiliates. 3 All rights reserved.
  • 4. MOOC has videos, code, and other resources Copyright © 2014, Oracle and/or its affiliates. 4 All rights reserved.
  • 5. Tweet contains Java Embedded Rasp Pi MOOC Copyright © 2014, Oracle and/or its affiliates. 5 All rights reserved.
  • 6. Raspberry Pi Hardware Components Copyright © 2014, Oracle and/or its affiliates. 6 All rights reserved.
  • 7. Raspberry Pi Hardware Setup Copyright © 2014, Oracle and/or its affiliates. 7 All rights reserved.
  • 8. Java SE vs. Java ME Copyright © 2014, Oracle and/or its affiliates. 8 All rights reserved.
  • 9. Java ME 8 Architecture Copyright © 2014, Oracle and/or its affiliates. 9 All rights reserved.
  • 10. Oracle MOOC: Software Installation Instructions On Your Windows PC 1 Install Java SE JDK 8 2 Install Java ME SDK 8 3 Install NetBeans 8 IDE 4 Install NetBeans ME SDK Plugins Copyright © 2014, Oracle and/or its affiliates. 10 All rights reserved.
  • 11. Config the Raspberry Pi for Java Development Copyright © 2014, Oracle and/or its affiliates. 11 All rights reserved.
  • 12. Java ME Application Lifecycle Methods public class SampleApp extends MIDlet { @Override public void startApp() { System.out.println("Starting..."); } @Override public void destroyApp(boolean unconditional) { System.out.println("Destroying..."); } } Copyright © 2014, Oracle and/or its affiliates. 12 All rights reserved.
  • 13. Door open/close ... and Some Relevant Concepts Discussed In this course, you will build a prototype of an embedded device to collect, store, analyze and share data from a shipping container. Copyright © 2014, Oracle and/or its affiliates. 13 All rights reserved. Pressure/ Temperature Location/ Altitude Storage Client Display Our Project GPIO I2C GPS, UART RMS JavaFX
  • 14. Lesson 2: Using the GPIO and I2C on the Raspberry Pi
  • 15. Door open/close In this course, you will build a prototype of an embedded device to collect, store, analyze and share data from a shipping container. Copyright © 2014, Oracle and/or its affiliates. 15 All rights reserved. Pressure/ Temperature Location/ Altitude Storage Client Display In This Lesson… GPIO I2C
  • 16. Lesson 2 Agenda  Getting started with the hardware  Working with GPIO on the Raspberry Pi  I2C Overview  Enabling I2C on the Raspberry Pi  Writing code for I2C Copyright © 2014, Oracle and/or its affiliates. 16 All rights reserved.
  • 17. Lesson 2.1: Raspberry Pi Cooking Class: Lets see the Ingredients
  • 18. Hardware LED  Light Emitting Diode (LED): red, green, blue  Two wires: – Anode positive, longest, and – Cathode negative, shortest Copyright © 2014, Oracle and/or its affiliates. 18 All rights reserved.
  • 19. Hardware Resistors  Their job is to “resist”, regulate or to set the flow of electrons (current) through them.  Used with LED to keep the current at specific level: characteristic forward current  560Ω and 10KΩ Copyright © 2014, Oracle and/or its affiliates. 19 All rights reserved.
  • 20. Hardware Switch  Switch is a component which controls the open-ness or closed-ness of an electric circuit.  Two states: – Off: looks like an open gap in the circuit (open circuit), preventing current from flowing. – On: acts just like a piece of wire (closes the circuit), turning the system “on” and allowing current to flow  Momentary switch: – only on when the button is pressed. – you release the button, the circuit is broken. Copyright © 2014, Oracle and/or its affiliates. 20 All rights reserved.
  • 21. Hardware BMP180  Measure barometric pressure and temperature  Specifications: – Pressure sensing range: 300-1100 hPa (9000m to -500m above sea level) – Up to 0.03hPa / 0.25m resolution – -40 to +85°C operational range, +-2°C temperature accuracy – 2-pin I2C interface on chip – Uses 3.3-5V power and logic level for more flexible usage Copyright © 2014, Oracle and/or its affiliates. 21 All rights reserved.
  • 22. Hardware Connecting things… Breadboard Copyright © 2014, Oracle and/or its affiliates. 22 All rights reserved. Jumper cables Pi Cobbler Breakout GPIO ribbon cable
  • 23. Some hardware connected to the Raspberry Pi Copyright © 2014, Oracle and/or its affiliates. 23 All rights reserved.
  • 24. Lesson 2.2: Getting Started with GPIO
  • 25. General Purpose Input/Output (GPIO)  GPIO pin is a generic pin with high or low – Its behavior can be programmed through software.  GPIO port is a platform-defined grouping of GPIO pins (often 4 or more pins). GPIOPin pin = DeviceManager.open(1); GPIOPort port = DeviceManager.open(0); pin.setValue(true); port.setValue(0xFF) Copyright © 2014, Oracle and/or its affiliates. 25 All rights reserved.
  • 26. GPIOPin Interface  Provides methods for controlling a GPIO pin.  A GPIO pin can be configured for output or input. – Output pins are both writable and readable – Input pins are only readable – GPIOPin.INPUT GPIOPin.OUTPUT  Get its value by polling, or register a PinListener – To register a PinListener: setInputListener(PinListener) – To remove the listener: setInputListener(null) – Writing a GPIOPin results in UnsupportedOperationException Copyright © 2014, Oracle and/or its affiliates. 26 All rights reserved.
  • 27. GPIO Pins on the Raspberry Pi Copyright © 2014, Oracle and/or its affiliates. 27 All rights reserved.
  • 28. Turning a LED ON and OFF The Circuit Copyright © 2014, Oracle and/or its affiliates. 28 All rights reserved.
  • 29. GPIO with Device Access API public class GPIOTest implements PinListener { ... private static final int BTN_PIN = 17; private static final int BTN_PORT = 0; private static final int LED1_ID = 23; ... GPIOPinConfig config1 = new GPIOPinConfig(BTN_PORT, Copyright © 2014, Oracle and/or its affiliates. 29 All rights reserved. BTN_PIN, GPIOPinConfig.DIR_INPUT_ONLY, DeviceConfig.DEFAULT, GPIOPinConfig.TRIGGER_BOTH_EDGES, false); GPIOPin button1 = DeviceManager.open(config1); GPIOPin led1 = DeviceManager.open(LED1_ID); button1.setInputListener(this);
  • 30. GPIO with Device Access API @Override public void valueChanged(PinEvent event) { GPIOPin pin = event.getDevice(); try { if (pin == button1) { // Toggle the value of the led led1.setValue(!led1.getValue()); } } catch (IOException ex) { System.out.println("IOException: " + ex); } } Copyright © 2014, Oracle and/or its affiliates. 30 All rights reserved.
  • 31. Lets run it… Copyright © 2014, Oracle and/or its affiliates. 31 All rights reserved.
  • 32. Homework: Create a Door Sensor Ingredients: 1 Green LED 1 Red LED 1 Momentary switch
  • 33. Door open/close In this course, you will build a prototype of an embedded device to collect, store, analyze and share data from a shipping container. Copyright © 2014, Oracle and/or its affiliates. 33 All rights reserved. Pressure/ Temperature Location/ Altitude Storage Client Display Door open/close GPIO
  • 34. The Door Sensor What we are trying to do  The idea is to show the door status via LEDs. – If the door is closed, the packages are safe in the truck: green LED is ON – If the door is open, we should warn: red LED is ON, or blinking (your choice)  Pins used in the solution (not required to be the same) – Green LED in pin 23 – Red LED in pin 24 – Switch in pin 17 Copyright © 2014, Oracle and/or its affiliates. 34 All rights reserved.
  • 35. The Wiring Copyright © 2014, Oracle and/or its affiliates. 35 All rights reserved. GPIO 17 GPIO 23 GPIO 24
  • 36. The Wiring Copyright © 2014, Oracle and/or its affiliates. 36 All rights reserved. 3V GND 3V GND
  • 37. Lesson 2.4: I2C Overview
  • 38. Pressure / Tempurature Door open/close In this course, you will build a prototype of an embedded device to collect, store, analyze and share data from a shipping container. Copyright © 2014, Oracle and/or its affiliates. 38 All rights reserved. Pressure/ Temperature Location/ Altitude Storage Client Display I2C
  • 39. Hardware BMP180  Measure barometric pressure and temperature  Specifications: – Pressure sensing range: 300-1100 hPa (9000m to -500m above sea level) – Up to 0.03hPa / 0.25m resolution – -40 to +85°C operational range, +-2°C temperature accuracy – 2-pin I2C interface on chip – Uses 3.3-5V power and logic level for more flexible usage Copyright © 2014, Oracle and/or its affiliates. 39 All rights reserved.
  • 40. I²C Overview  Used for moving data simply and quickly from one device to another  Serial Interface  Synchronous: – The data (SDA) is sent along with a clock signal (SCL) – The clock signal controls when data is changed and when it should be read – Clock rate can vary, unlike asynchronous (RS-232 style) communications  Bidirectional Copyright © 2014, Oracle and/or its affiliates. 40 All rights reserved.
  • 41. I2C In Few Words…  Inter-Integrated Circuit, ("two-wire interface")  Multi-master serial single-ended computer bus  Invented by Philips for attaching low-speed peripherals to a motherboard, embedded system, cellphone, or other electronic device.  Uses two bidirectional open-drain lines – Serial Data Line (SDA) and – Serial Clock (SCL), – pulled up with resistors.  Typical voltages used are +5 V or +3.3 V Copyright © 2014, Oracle and/or its affiliates. 41 All rights reserved.
  • 42. I²C Design  A bus with a clock (SCL) and data (SDA) lines  7-bit addressing.  Roles: – Master: generates the clock and initiates communication with slaves – Slave: receives the clock and responds when addressed by the master  Multi-Master bus  Switch between master and slave allowed Copyright © 2014, Oracle and/or its affiliates. 42 All rights reserved.
  • 43. I²C Communication Protocol START (S) and STOP (P) Conditions  Communication starts when master puts START condition (S) on the bus: HIGH-to-LOW transition of the SDA line while SCL line is HIGH  Bus is busy until master puts a STOP condition (P) on the bus: LOW to HIGH transition on the SDA line while SCL is HIGH Copyright © 2014, Oracle and/or its affiliates. 43 All rights reserved.
  • 44. I²C Communication Protocol Data Format / Acknowledge  I2C data bytes are 8-bits long  Each byte transferred must be followed by acknowledge ACK signal Copyright © 2014, Oracle and/or its affiliates. 44 All rights reserved.
  • 45. I²C Communication Protocol Communications Copyright © 2014, Oracle and/or its affiliates. 45 All rights reserved.
  • 46. Lesson 2.5: Enabling I2C on the Rasperry Pi
  • 47. I2C not enabled by default  /etc/modules – Add lines: i2c-bcm2708 i2c-dev  Install i2c-tools. Handy for detecting devices – sudo apt-get install i2c-tools  /etc/modprobe.d/raspi-blacklist.conf comment out the lines – # blacklist spi-bcm2708 – # blacklist i2c-bcm2708 Copyright © 2014, Oracle and/or its affiliates. 47 All rights reserved.
  • 48. Verifying that I2C is enabled  Can you see your device? – sudo i2cdetect -y 1 Copyright © 2014, Oracle and/or its affiliates. 48 All rights reserved.
  • 49. Lesson 2.6: Using I2C on the Raspberry Pi
  • 50. Wiring and operating the BMP180  Raspberry Pi uses I2C bus 1  We’re using device address 0x77  I2C uses 7 bits for device address  BMP180 uses clock frequency 3.4MHz  Control register for BMP180 is 0xF4  Temperature value is at register 0xF6. Copyright © 2014, Oracle and/or its affiliates. 50 All rights reserved.
  • 51. The Wiring Copyright © 2014, Oracle and/or its affiliates. 51 All rights reserved.
  • 52. Reading and writing to I2C devices I2CDeviceConfig config = new I2CDeviceConfig(1, // I2C bus number Copyright © 2014, Oracle and/or its affiliates. 52 All rights reserved. 0x77, // I2C device address 7, // address size in bits 3400000); // Clock frequency myDevice = DeviceManager.open(config); myDevice.write(0xF4, 1, 0x2E); // control register, size, // get temperature command myDevice.read(0xF6, 1, buf); // temperature register, // subaddress size, ByteBuffer
  • 53. Lesson 3: Using the UART, GPS, and Storing Data
  • 54. Door open/close GPS, UART RMS In this course, you will build a prototype of an embedded device to collect, store, analyze and share data from a shipping container. Copyright © 2014, Oracle and/or its affiliates. 54 All rights reserved. Pressure/ Temperature Location/ Altitude Storage Client Display
  • 55. Lesson Agenda  UART serial protocol overview  GPS overview  Connecting the GPS sensor using a USB UART cable  Connecting the GPS directly to the Raspberry Pi UART  Reading GPS data in a Java ME 8 Embedded application  Saving GPS data in the Record Management Store  Saving GPS data in a file Copyright © 2014, Oracle and/or its affiliates. 55 All rights reserved.
  • 56. Lesson 3-1: UART Serial Protocol Overview
  • 57. UART Serial Protocol The Basics  UART = Universal Asynchronous Receiver and Transmitter  Serial communication – Each bit is sent one after the other  Both ends must be set to work at the same speed – bits per second – Standard speeds (9600, 19200, 115200, etc) – Some devices use non-standard speeds  At idle, with no data the connection is held high (voltage) Copyright © 2014, Oracle and/or its affiliates. 57 All rights reserved.
  • 58. UART Protocol Character Frame Start Data 0 Data 1 Data 2 Data 3 Data 4 Data 5 Data 6 Data 7 Parity Stop 1 Stop 2 Copyright © 2014, Oracle and/or its affiliates. 58 All rights reserved. Data (5-9 bits) LOGIC LOW (0) LOGIC HIGH (1) LOGIC HIGH (1)
  • 59. Serial Data Transmission  UART does not usually drive transmission of data – RS-232, RS-422, RS-485  Transmission does not need to be electrical – Bluetooth serial port profile – Infra red (IRDa) – Acoustic modem (telephone line) Copyright © 2014, Oracle and/or its affiliates. 59 All rights reserved.
  • 60. Lesson 3-2: GPS Overview
  • 61. Global Positioning System Image courtesy of Wikipedia Copyright © 2014, Oracle and/or its affiliates. 61 All rights reserved.
  • 62. GPS Satellite Navigation System  Position is calculated using satellites that continually transmit data – Time and the position above the earth  Minimum of three satellites required to get position – latitude and longitude  Four satellites required to get 3D position fix – latitude/longitude/altitude Copyright © 2014, Oracle and/or its affiliates. 62 All rights reserved.
  • 63. GPS Receiver Data Format  GPS receivers typically use NMEA 0183 standard – National Marine Electronics Association  Text based protocol – Message starts with a $ sign – Next five letters identify the talker (2 letters) and type (3 letters)  GPS receiver talker code is GP – Data fields are comma separated – Message contains optional aterisk * and two digit checksum at the end – Message is terminated with carriage return, line feed (13, 10 ASCII) Copyright © 2014, Oracle and/or its affiliates. 63 All rights reserved.
  • 64. GPS Receiver Useful Data Packets  $GPGGA – GPS fix data – Time – Latitude, [N/S] – Longitude, [E/W] – Fix quality – Number of satellites being tracked – Horizontal dilution – Altitude (m) – More fields of no direct use Copyright © 2014, Oracle and/or its affiliates. 64 All rights reserved.
  • 65. GPS Receiver Useful Data Packets  $GPVTG – Velocity made good – True track made good (degrees), T – Magnetic track made good, M – Ground speed (knots), N – Ground speed (Km/h), K Copyright © 2014, Oracle and/or its affiliates. 65 All rights reserved.
  • 66. Extracting Data From A Packet Using StringTokenizer StringTokenizer tokenizer = new StringTokenizer(input, ",", true); boolean tokenWasDelimiter = false; while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); if (!token.equals(",")) { fields.add(token); tokenWasDelimiter = false; } else { if (tokenWasDelimiter) fields.add(" "); tokenWasDelimiter = true; } } Copyright © 2014, Oracle and/or its affiliates. 66 All rights reserved.
  • 67. Extracting Data From A Packet Roll Your Own CSV Extractor ArrayList<String> fields = new ArrayList<>(); fields.clear(); int start = 0; int end; while ((end = input.indexOf(",", start)) != -1) { fields.add(input.substring(start, end); start = end + 1; } fields.add(input.substring(start)); Copyright © 2014, Oracle and/or its affiliates. 67 All rights reserved.
  • 68. Data Encapsulation  Position – Time stamp – Latitude, latitude direction (N or S) – Longitude, longitude direction (E or W) – Altitude (metres above sea level)  Velocity – Time stamp – Bearing (degrees from north) – Velocity (Km/h) Copyright © 2014, Oracle and/or its affiliates. 68 All rights reserved.
  • 69. Output Data  Client wants CSV format  Override the toString() method public String toString() { Formatter f = new Formatter(); return f.format("%d,%.3f,%c,%.3f,%c,%.2f", latitude, latitudeDirection, longitude, longitudeDirection, altitude); } Copyright © 2014, Oracle and/or its affiliates. 69 All rights reserved.
  • 70. Lesson 3-3: Connecting the GPS Sensor To The Raspberry Pi
  • 71. Connection Methods 1. Using a USB to TTL UART adapter 2. Direct connection to the Raspberry Pi header pins Copyright © 2014, Oracle and/or its affiliates. 71 All rights reserved.
  • 72. Raspberry Pi USB Connectors Copyright © 2014, Oracle and/or its affiliates. 72 All rights reserved.  2 x USB 2.0 Type A sockets – Host USB  Differs slightly from USB specification – Power should be 500mA max – Actual is less than 200mA  Can power the board through  Micro USB socket these - Power only
  • 73. USB UART Cable PL2003 UART TTL-USB Copyright © 2014, Oracle and/or its affiliates. 73 All rights reserved. USB Adapter (Vcc can be +3.3V or +5V) GND (Black) Vcc +5V (Red) TX (Green) RX (White)
  • 74. USB UART Adapter Connections Copyright © 2014, Oracle and/or its affiliates. 74 All rights reserved. USB Green connects to GPS RX USB White connects to GPS TX
  • 75. USB UART Raspberry Pi Configuration  Plug in USB UART adapter to Raspberry Pi  Device to use is /dev/ttyUSB0 Copyright © 2014, Oracle and/or its affiliates. 75 All rights reserved.
  • 76. Raspberry Pi Headers Connections (P1) - GPIO - I2C - SPI - UART Display (Not supported) Copyright © 2014, Oracle and/or its affiliates. 76 All rights reserved. JTAG P2 = Processor P3 = LAN Camera
  • 77. Header Pin Layout P1-01 5 V GND 0 (SDA) 1 (SCL) {UART 14 (TXD) Copyright © 2014, Oracle and/or its affiliates. 77 All rights reserved. 15 (RXD) Power GPIO UART I2C SPI 18 23 24 25 8 7 10 (MOSI) 9 (MISO) 11 (SCLK) 4 17 27 22 3.3V 5V GND GND GND GND GND
  • 78. UART Connections P1-01 Copyright © 2014, Oracle and/or its affiliates. 78 All rights reserved. TX RX NOTE: RX TX TX RX
  • 79. Raspberry Pi UART Configuration  Device to use is /dev/ttyAMA0  This is also used as the console – Boot messages – Login prompt  Edit /etc/inittab – Comment out line for console – # T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100  Edit /boot/cmdline.txt – Delete console=ttyAMA0,115200 kgdboc=ttyAMA0,115200  Reboot Copyright © 2014, Oracle and/or its affiliates. 79 All rights reserved.
  • 80. Lesson 3-4: Reading GPS Data in a Java ME 8 Embedded Application
  • 81. Using The UART Getting a BufferedReader UART uart = DeviceManager.open(40); //UART ID # uart.setBaudRate(9600); InputStream is = Channels.newInputStream(uart); InputStreamreader isr = new InputStreamReader(is); BufferedReader reader = new BufferedReader(isr); Copyright © 2014, Oracle and/or its affiliates. 81 All rights reserved.
  • 82. UART Device Security  Need to add API permission – Application Descriptor – Permission  jdk.dio.DeviceMgmtPermission – Protected resource name  *:* – Actions requested  open Copyright © 2014, Oracle and/or its affiliates. 82 All rights reserved.
  • 83. Reading GPS Data  All data lines start with $ – Read lines until we get one with the right start character  Check the talker is GP  Test for the correct type (GGA or VTG)  Decode comma separated values  Data appears to be easily corrupted – Short reads, $ in middle of line, not enough fields – Repeat reads until valid data extracted Copyright © 2014, Oracle and/or its affiliates. 83 All rights reserved.
  • 84. Lesson 3-5: Saving GPS Data in the Record Management System
  • 85. Door open/close GPS, UART RMS In this course, you will build a prototype of an embedded device to collect, store, analyze and share data from a shipping container. Copyright © 2014, Oracle and/or its affiliates. 85 All rights reserved. Pressure/ Temperature Location/ Altitude Storage Client Display
  • 86. Our Midlet suite Stores and retrieves sensor data DataRecorder Suite RecorderMidlet ReaderMidlet ServerMidlet Copyright © 2014, Oracle and/or its affiliates. 86 All rights reserved. Sensor data in RMS RecordStore
  • 87. Record Management System (RMS) Overview Defined in Java ME Embedded Profile 8.0  Java ME does not rely on being able to store data in files – Some small and embedded devices do not have file systems  Java ME stores application data in non-volatile memory – How this happens is abstracted away by the RMS  RMS can be thought of as a very simple database – Two columns  Record ID  Data (array of bytes) Copyright © 2014, Oracle and/or its affiliates. 87 All rights reserved.
  • 88. RecordStore Storing Data RecordStore store = RecordStore.openRecordStore("gps-data", true); String data = position.toString() + "^" + velocity.toString(); byte[] dataBytes = data.getBytes(); int recordNum = store.addRecord(dataBytes, 0, dataBytes.length); Copyright © 2014, Oracle and/or its affiliates. 88 All rights reserved.
  • 89. RecordStore Retrieving Data  Create a new Midlet in the same Midlet suite as the data recorder  Records are retrieved as byte arrays RecordStore store = RecordStore.openRecordStore("gps-data", false); recordCount = store.getNumRecords(); for (int i = 1; i < recordCount; i++) // record index is 1 based System.out.println("Record " + i + " = " + new String(store.getRecord(i)); Copyright © 2014, Oracle and/or its affiliates. 89 All rights reserved.
  • 90. Record Store Persistence  The persistence of the Record Store is tied to the MIDlet suite  When the MIDlet suite is removed from the device (destroyed) – The Record Store for that suite is deleted Copyright © 2014, Oracle and/or its affiliates. 90 All rights reserved.
  • 91. Lesson 3-6: Saving GPS Data in a File
  • 92. Java ME And Files Overview  Raspberry Pi has conventional filesystem – So data can be stored there – Java ME supports this through the Generic Connection Framework  Be careful with file URI – Format is file://[root]/[file-path] – Example file, /tmp/gps-data.txt – URI is file://rootfs/tmp/gps-data.txt Copyright © 2014, Oracle and/or its affiliates. 92 All rights reserved.
  • 93. Java ME File IO Generic Connection Framework: FileConnection private final FileConnection connection; private final PrintStream fileWriter; connection = (FileConnection)Connector.open( "file://rootfs/tmp/gps-data.txt", Connector.READ_WRITE); if (!connection.exists()) connection.create(); Copyright © 2014, Oracle and/or its affiliates. 93 All rights reserved.
  • 94. Java ME File IO Use Generic Connection Framework fileWriter = new PrintStream( connection.openOutputStream()); fileWriter.println(position + "^" + velocity); Copyright © 2014, Oracle and/or its affiliates. 94 All rights reserved.
  • 95. File Access API Permissions  To allow file access from the Midlet/Imlet add API permissions – javax.microedition.io.Connector.file.read – javax.microedition.io.Connector.file.write  No protected resource name or action requests are required Copyright © 2014, Oracle and/or its affiliates. 95 All rights reserved.
  • 96. Lesson 4: Communicating the Data to the Outside World
  • 97. In the grand scheme of this course … Door open/close You are here JavaFX In this course, you are building a prototype of an embedded device to collect, store, analyze and share data from a shipping container. Copyright © 2014, Oracle and/or its affiliates. 97 All rights reserved. Pressure/ Temperature Location/ Altitude Storage Client Display
  • 98. Lesson 4-1: Demo a MIDlet that serves sensor data, and a client app that communicates with it
  • 99. Two more pieces of the prototype puzzle … An app named VisualClient that communicates with ServerMidlet DataRecorder Suite RecorderMidlet ReaderMidlet ServerMidlet Copyright © 2014, Oracle and/or its affiliates. 99 All rights reserved. Sensor data in RMS RecordStore
  • 100. Taking ServerMidlet and VisualClient for a spin Copyright © 2014, Oracle and/or its affiliates. 100 All rights reserved. VisualClient is created with Java/JavaFX and the SceneBuilder tool
  • 101. VisualClient and ServerMidlet Copyright © 2014, Oracle and/or its affiliates. 101 All rights reserved.
  • 102. Safe Harbor Statement The preceding is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle. Copyright © 2014, Oracle and/or its affiliates. 102 All rights reserved.
  • 103. Raspberry Pi with Java 8 Intro to Pi and Java ME 8 – James Weaver Brief demos by student programming contest winners Using Pi4J – Robert Savage Raspberry Pi Tricks – Stephen Chin #DV14 #RPiJava8 @SteveOnJava @SavageAutomate @JavaFXpert

Editor's Notes

  1. The problem: Farmers are placing their fresh crops into a shipping container, and some of those shipments arrive at the distribution center spoiled or damaged. The shipping company has hired you to develop an inexpensive embedded device to collect information from the containers. The goals for the device include:     * Completely stand-alone operation and low-power (Raspberry Pi and Java ME Embedded 8)     * Record the number of times and when the shipping container door is opened (switches)     * Record the temperature in the container at regular intervals (Barometric Pressure/Temperature sensor)     * Record the location of the container at regular intervals (Adafruit GPS Breakout) * Store the data collected locally on the device     * Respond to a request to download the information wirelessly (WiFi module)
  2. The problem: Farmers are placing their fresh crops into a shipping container, and some of those shipments arrive at the distribution center spoiled or damaged. The shipping company has hired you to develop an inexpensive embedded device to collect information from the containers. The goals for the device include:     * Completely stand-alone operation and low-power (Raspberry Pi and Java ME Embedded 8)     * Record the number of times and when the shipping container door is opened (switches)     * Record the temperature in the container at regular intervals (Barometric Pressure/Temperature sensor)     * Record the location of the container at regular intervals (Adafruit GPS Breakout) * Store the data collected locally on the device     * Respond to a request to download the information wirelessly (WiFi module)
  3. In any 'loop' of a circuit, the voltages must balance: the amount generated = the amount used This "Voltage Loop" law was discovered by a fellow named Kirchhoff (thus it is called Kirchhoff's Voltage Law = KVL).
  4. there is a specification for diodes called the characteristic (or recommended) forward voltage (usually between 1.5-4V for LEDs). You must reach the characteristic forward voltage to turn 'on' the diode or LED, but as you exceed the characteristic forward voltage, the LED's resistance quickly drops off. Therefore, the LED will begin to draw a bunch of current and in some cases, burn out. A resistor is used in series with the LED to keep the current at a specific level called the characteristic (or recommended) forward current.
  5. The problem: Farmers are placing their fresh crops into a shipping container, and some of those shipments arrive at the distribution center spoiled or damaged. The shipping company has hired you to develop an inexpensive embedded device to collect information from the containers. The goals for the device include:     * Completely stand-alone operation and low-power (Raspberry Pi and Java ME Embedded 8)     * Record the number of times and when the shipping container door is opened (switches)     * Record the temperature in the container at regular intervals (Barometric Pressure/Temperature sensor)     * Record the location of the container at regular intervals (Adafruit GPS Breakout) * Store the data collected locally on the device     * Respond to a request to download the information wirelessly (WiFi module)
  6. The problem: Farmers are placing their fresh crops into a shipping container, and some of those shipments arrive at the distribution center spoiled or damaged. The shipping company has hired you to develop an inexpensive embedded device to collect information from the containers. The goals for the device include:     * Completely stand-alone operation and low-power (Raspberry Pi and Java ME Embedded 8)     * Record the number of times and when the shipping container door is opened (switches)     * Record the temperature in the container at regular intervals (Barometric Pressure/Temperature sensor)     * Record the location of the container at regular intervals (Adafruit GPS Breakout) * Store the data collected locally on the device     * Respond to a request to download the information wirelessly (WiFi module)
  7. with a slave device. Data is exchanged between these devices. Since I2C is synchronous, it has a clock pulse along with the data. RS232 and other asynchronous protocols do not use a clock pulse, but the data must be timed very accurately. Since I2C has a clock signal, the clock can vary without disrupting the data. The data rate will simply change along with the changes in the clock rate. This makes I2C ideal when the micro is being clocked imprecisely, such as by a RC oscillator.
  8. IÇC uses only two bidirectional open-drain lines, Serial Data Line (SDA) and Serial Clock (SCL), pulled up with resistors. Typical voltages used are +5 V or +3.3 V although systems with other voltages are permitted. The IÇC reference design has a 7-bit or a 10-bit (depending on the device used) address space. [5] Common IÇC bus speeds are the 100 kbit/s standard mode and the 10 kbit/s low-speed mode, but arbitrarily low clock frequencies are also allowed. Recent revisions of IÇC can host more nodes and run at faster speeds (400 kbit/s Fast mode, 1 Mbit/s Fast mode plus or Fm+, and 3.4 Mbit/s High Speed mode). These speeds are more widely used on embedded systems than on PCs. There are also other features, such as 16-bit addressing.
  9. The aforementioned reference design is a bus with a clock (SCL) and data (SDA) lines with 7-bit addressing. The bus has two roles for nodes: master and slave: Master node — node that generates the clock and initiates communication with slaves Slave node — node that receives the clock and responds when addressed by the master The bus is a multi-master bus which means any number of master nodes can be present. Additionally, master and slave roles may be changed between messages (after a STOP is sent). There are four potential modes of operation for a given bus device, although most devices only use a single role and its two modes: master transmit — master 1. node is sending data to a slave 2. master receive — master node is receiving data from a slave 3. slave transmit — slave node is sending data to the master 4. slave receive — slave node is receiving data from the master
  10. START (S) and STOP (P) Conditions Communication on the I2C bus starts when the master puts the START condition (S) on the bus, which is defined as a HIGH-to-LOW transition of the SDA line while SCL line is HIGH (see figure below). The bus is considered to be busy until the master puts a STOP condition (P) on the bus, which is defined as a LOW to HIGH transition on the SDA line while SCL is HIGH (see figure below). Additionally, the bus remains busy if a repeated START (Sr) is generated instead of a STOP condition.
  11. Data Format / Acknowledge I2C data bytes are defined to be 8-bits long. There is no restriction to the number of bytes transmitted per data transfer. Each byte transferred must be followed by an acknowledge (ACK) signal. The clock for the acknowledge signal is generated by the master, while the receiver generates the actual acknowledge signal by pulling down SDA and holding it low during the HIGH portion of the acknowledge clock pulse. If a slave is busy and cannot transmit or receive another byte of data until some other task has been performed, it can hold SCL LOW, thus forcing the master into a wait state. Normal data transfer resumes when the slave is ready, and releases the clock line (refer to the following figure).
  12. After beginning communications with the START condition (S), the master sends a 7-bit slave address followed by an 8th bit, the read/write bit. The read/write bit indicates whether the master is receiving data from or is writing to the slave device. Then, the master releases the SDA line and waits for the acknowledge signal (ACK) from the slave device. Each byte transferred must be followed by an acknowledge bit. To acknowledge, the slave device pulls the SDA line LOW and keeps it LOW for the high period of the SCL line. Data transmission is always terminated by the master with a STOP condition (P), thus freeing the communications line. However, the master can generate a repeated START condition (Sr), and address another slave without first generating a STOP condition (P). A LOW to HIGH transition on the SDA line while SCL is HIGH defines the stop condition. All SDA changes should take place when SCL is low, with the exception of start and stop conditions.
  13. The problem: Farmers are placing their fresh crops into a shipping container, and some of those shipments arrive at the distribution center spoiled or damaged. The shipping company has hired you to develop an inexpensive embedded device to collect information from the containers. The goals for the device include:     * Completely stand-alone operation and low-power (Raspberry Pi and Java ME Embedded 8)     * Record the number of times and when the shipping container door is opened (switches)     * Record the temperature in the container at regular intervals (Barometric Pressure/Temperature sensor)     * Record the location of the container at regular intervals (Adafruit GPS Breakout) * Store the data collected locally on the device     * Respond to a request to download the information wirelessly (WiFi module)
  14. The problem: Farmers are placing their fresh crops into a shipping container, and some of those shipments arrive at the distribution center spoiled or damaged. The shipping company has hired you to develop an inexpensive embedded device to collect information from the containers. The goals for the device include:     * Completely stand-alone operation and low-power (Raspberry Pi and Java ME Embedded 8)     * Record the number of times and when the shipping container door is opened (switches)     * Record the temperature in the container at regular intervals (Barometric Pressure/Temperature sensor)     * Record the location of the container at regular intervals (Adafruit GPS Breakout) * Store the data collected locally on the device     * Respond to a request to download the information wirelessly (WiFi module)
  15. The problem: Farmers are placing their fresh crops into a shipping container, and some of those shipments arrive at the distribution center spoiled or damaged. The shipping company has hired you to develop an inexpensive embedded device to collect information from the containers. The goals for the device include:     * Completely stand-alone operation and low-power (Raspberry Pi and Java ME Embedded 8)     * Record the number of times and when the shipping container door is opened (switches)     * Record the temperature in the container at regular intervals (Barometric Pressure/Temperature sensor)     * Record the location of the container at regular intervals (Adafruit GPS Breakout) * Store the data collected locally on the device     * Respond to a request to download the information wirelessly (WiFi module)
  16. This is a Safe Harbor Front slide, one of two Safe Harbor Statement slides included in this template. One of the Safe Harbor slides must be used if your presentation covers material affected by Oracle’s Revenue Recognition Policy To learn more about this policy, e-mail: Revrec-americasiebc_us@oracle.com For internal communication, Safe Harbor Statements are not required. However, there is an applicable disclaimer (Exhibit E) that should be used, found in the Oracle Revenue Recognition Policy for Future Product Communications. Copy and paste this link into a web browser, to find out more information. http://my.oracle.com/site/fin/gfo/GlobalProcesses/cnt452504.pdf For all external communications such as press release, roadmaps, PowerPoint presentations, Safe Harbor Statements are required. You can refer to the link mentioned above to find out additional information/disclaimers required depending on your audience.