Micro & Mobile
Java8 on the Raspberry Pi

22 Dec 2013, JavaDay, Pance Cavkovski
The Device

- Raspberry Pi + Arduino
- Basic multimeter: AC/DC
voltage, frequency spectrum,
resistance
- Results shown in ...
The hardware

- Raspberry Pi
- Arduino Mega 2560
- Custom adapter and
interface board

Netcetera | 3
The software
Browser app

- Arduino readings
- Java8 SE Embedded
server
- D3.js animated SVG
graphs

d3js

JSON

Java
Java...
The software
Arduino read
void loop() {
val1 = analogRead(A1); //AC input
val2 = analogRead(A2); //DC input
val3 = analogR...
The software
Java server
final Serial serial = SerialFactory.
createInstance();
Serial.addListener(new SerialDataListener(...
The software
D3 graphs
//Define the scale and axis
x = d3.scale.linear().range([0, width]);
y = d3.scale.linear().range([0...
The homepage

Netcetera | 8
The graphs

Netcetera | 9
The demo – DC Voltage

Netcetera | 10
The demo – AC waveline

Netcetera | 11
The demo - Spectrum

Netcetera | 12
The demo - Resistance

Netcetera | 13
The mobile reason

- Mobile is not just responsive
- Mobile browsers are getting lot faster
- JavaScript applications can ...
The micro reason

- Micro devices are catching on and improving
- Raspberry Pi B 2: 700MHz ARM, 512MB SDRAM
Rumored Model ...
The Java reason

- Java8 improves the embedded editions
- Java8 SE Embedded:
mid-high range, Full OS, general functions, l...
- Source code at https://github.com/hsilomedus/pi4jmultimeter
- Blog post / instructions at http://hsilomedus.me/index.php...
Upcoming SlideShare
Loading in …5
×

Micro and moblile: Java on the Raspberry Pi

712 views
562 views

Published on

Using Java8 on the Raspberry Pi, coupled with an Arduino and a mobile web application.

Published in: Technology, Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
712
On SlideShare
0
From Embeds
0
Number of Embeds
22
Actions
Shares
0
Downloads
6
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Micro and moblile: Java on the Raspberry Pi

  1. 1. Micro & Mobile Java8 on the Raspberry Pi 22 Dec 2013, JavaDay, Pance Cavkovski
  2. 2. The Device - Raspberry Pi + Arduino - Basic multimeter: AC/DC voltage, frequency spectrum, resistance - Results shown in a mobile web application Netcetera | 2
  3. 3. The hardware - Raspberry Pi - Arduino Mega 2560 - Custom adapter and interface board Netcetera | 3
  4. 4. The software Browser app - Arduino readings - Java8 SE Embedded server - D3.js animated SVG graphs d3js JSON Java Java8 WebSocket lighttpd pi4j Serial communication Analog read + FFT Netcetera | 4
  5. 5. The software Arduino read void loop() { val1 = analogRead(A1); //AC input val2 = analogRead(A2); //DC input val3 = analogRead(A3); //Resistance input for (i = 0; i < 128; i++) { val1 = analogRead(A1); data[i] = val1/2 - 256; im[0] = 0; } //Fast Forward Fourier Transformation fix_fft(data, im, 7, 0); for (i = 0; i < 64; i++) { data[i]= sqrt(data[i]*data[i]+im[i]*im[i]); lastpass[i] = ylim – data[i]; } Serial1.print(“ S “); Serial1.print(val1, HEX); Serial1.print(“ “); Serial1.print(val2, HEX); Serial1.print(“ “); Serial1.print(val3, HEX); Serial1.print(“ “); for (i = 1; i < 21; i++) { Serial1.print(“ “); //take the max out of 4 readings Serial1.print(max(max(max(data[i*4], data[i*4 + 1]), data[i*4 + 2]), data[i*4 + 3]),HEX); } Serial1.flush(); } Netcetera | 5
  6. 6. The software Java server final Serial serial = SerialFactory. createInstance(); Serial.addListener(new SerialDataListener() { private ReadValues readValue = new ReadValues(); @Override public void dataReceived( SerialDataEvent event) { String received = event.getData(); String[] parts = received.split(“s+”); //parse the output here. //reset on each „S‟ received } } serial.open(Serial.DEFAULT_COM_PORT, 115200); while (true) { Thread.sleep(10); if (currentData != null) { //ReadValues has overriden toString method //which renders JSON object String toSend = currentData.toString(); webSocket.send(toSend); } } Netcetera | 6
  7. 7. The software D3 graphs //Define the scale and axis x = d3.scale.linear().range([0, width]); y = d3.scale.linear().range([0, height]); yAxis = d3.svg.axis().scale(y).orient("left"); ... //init the svg svg = d3.select("body").append("svg")... ... //define d3 enter sequence selector = svg.selectAll(".bar").data(data); selector.enter().append("rect") .attr("class", "bar") .attr("x", function(d) { return d.x; }) .attr("width", width/50 - 1); ... //Define d3 update sequence on 100ms interval selector .attr("x", function(d) { return d.x; }) .attr("height", function(d) { return height - y(d.y); }) .attr("y", function(d) { return y(d.y);}) ... //Start the WebSocket var socket = new WebSocket("ws://" + document.domain + ":8887/"); socket.onmessage = function(a) { lastReceivedValue = a.data; } Netcetera | 7
  8. 8. The homepage Netcetera | 8
  9. 9. The graphs Netcetera | 9
  10. 10. The demo – DC Voltage Netcetera | 10
  11. 11. The demo – AC waveline Netcetera | 11
  12. 12. The demo - Spectrum Netcetera | 12
  13. 13. The demo - Resistance Netcetera | 13
  14. 14. The mobile reason - Mobile is not just responsive - Mobile browsers are getting lot faster - JavaScript applications can run smoothly Netcetera | 14
  15. 15. The micro reason - Micro devices are catching on and improving - Raspberry Pi B 2: 700MHz ARM, 512MB SDRAM Rumored Model C: Dual Core, 1GB RAM? - Arduino TRE: Intel 1GHz ARM, 512GB DDR3l RAM - Lots of sensors and shields available Netcetera | 15
  16. 16. The Java reason - Java8 improves the embedded editions - Java8 SE Embedded: mid-high range, Full OS, general functions, limited I/O integration - Java8 ME Embedded (v.3.3): low-mid range, Full/min OS, I/O integrated, optimized, available tools - Developer versions available Netcetera | 16
  17. 17. - Source code at https://github.com/hsilomedus/pi4jmultimeter - Blog post / instructions at http://hsilomedus.me/index.php/pi4jmultimete/ - Questions? - https://twitter.com/hsilomedus, http://hsilomedus.me/ Netcetera | 17

×