SlideShare a Scribd company logo
1 of 17
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 a mobile web
application
Netcetera | 2
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
Java8

WebSocket

lighttpd

pi4j
Serial communication

Analog read + FFT

Netcetera | 4
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
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
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
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 run smoothly

Netcetera | 14
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
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
- 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

More Related Content

What's hot

What's hot (15)

d3 is cool
d3 is coold3 is cool
d3 is cool
 
Accelerometer and Open GL
Accelerometer and Open GLAccelerometer and Open GL
Accelerometer and Open GL
 
Real life XNA
Real life XNAReal life XNA
Real life XNA
 
Ch1 2 (2)
Ch1 2 (2)Ch1 2 (2)
Ch1 2 (2)
 
Landset 8 的雲層去除技巧實作
Landset 8 的雲層去除技巧實作Landset 8 的雲層去除技巧實作
Landset 8 的雲層去除技巧實作
 
Model-based GUI testing using UPPAAL
Model-based GUI testing using UPPAALModel-based GUI testing using UPPAAL
Model-based GUI testing using UPPAAL
 
Computer graphics practical(jainam)
Computer graphics practical(jainam)Computer graphics practical(jainam)
Computer graphics practical(jainam)
 
Sprint - Exciting Insights from Translating a Classic Car Racing Game to Java...
Sprint - Exciting Insights from Translating a Classic Car Racing Game to Java...Sprint - Exciting Insights from Translating a Classic Car Racing Game to Java...
Sprint - Exciting Insights from Translating a Classic Car Racing Game to Java...
 
Introduction to Game Programming Tutorial
Introduction to Game Programming TutorialIntroduction to Game Programming Tutorial
Introduction to Game Programming Tutorial
 
Image Processing TARUS: a FARMBOT
Image Processing TARUS: a FARMBOTImage Processing TARUS: a FARMBOT
Image Processing TARUS: a FARMBOT
 
Introduction of 3D Development
Introduction of 3D DevelopmentIntroduction of 3D Development
Introduction of 3D Development
 
PyData Paris 2015 - Track 1.1 Alexandre Gramfort
PyData Paris 2015 - Track 1.1 Alexandre GramfortPyData Paris 2015 - Track 1.1 Alexandre Gramfort
PyData Paris 2015 - Track 1.1 Alexandre Gramfort
 
To Swift 2...and Beyond!
To Swift 2...and Beyond!To Swift 2...and Beyond!
To Swift 2...and Beyond!
 
Pytorch and Machine Learning for the Math Impaired
Pytorch and Machine Learning for the Math ImpairedPytorch and Machine Learning for the Math Impaired
Pytorch and Machine Learning for the Math Impaired
 
Javascript Arrays
Javascript ArraysJavascript Arrays
Javascript Arrays
 

Similar to Micro and moblile: Java on the Raspberry Pi

Similar to Micro and moblile: Java on the Raspberry Pi (20)

SVGD3Angular2React
SVGD3Angular2ReactSVGD3Angular2React
SVGD3Angular2React
 
Svcc 2013-d3
Svcc 2013-d3Svcc 2013-d3
Svcc 2013-d3
 
SVCC 2013 D3.js Presentation (10/05/2013)
SVCC 2013 D3.js Presentation (10/05/2013)SVCC 2013 D3.js Presentation (10/05/2013)
SVCC 2013 D3.js Presentation (10/05/2013)
 
D3.js 30-minute intro
D3.js   30-minute introD3.js   30-minute intro
D3.js 30-minute intro
 
Professional reports with SVG
Professional reports with SVGProfessional reports with SVG
Professional reports with SVG
 
Visual Exploration of Large Data sets with D3, crossfilter and dc.js
Visual Exploration of Large Data sets with D3, crossfilter and dc.jsVisual Exploration of Large Data sets with D3, crossfilter and dc.js
Visual Exploration of Large Data sets with D3, crossfilter and dc.js
 
Learn D3.js in 90 minutes
Learn D3.js in 90 minutesLearn D3.js in 90 minutes
Learn D3.js in 90 minutes
 
Example R usage for oracle DBA UKOUG 2013
Example R usage for oracle DBA UKOUG 2013Example R usage for oracle DBA UKOUG 2013
Example R usage for oracle DBA UKOUG 2013
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup Edinburgh
 
Analytics with Spark
Analytics with SparkAnalytics with Spark
Analytics with Spark
 
Arduino and the real time web
Arduino and the real time webArduino and the real time web
Arduino and the real time web
 
Visualization of Big Data in Web Apps
Visualization of Big Data in Web AppsVisualization of Big Data in Web Apps
Visualization of Big Data in Web Apps
 
Forge - DevCon 2016: Visual Reporting with Connected Design Data
Forge - DevCon 2016: Visual Reporting with Connected Design DataForge - DevCon 2016: Visual Reporting with Connected Design Data
Forge - DevCon 2016: Visual Reporting with Connected Design Data
 
Scrollytelling
ScrollytellingScrollytelling
Scrollytelling
 
Android Wear 2.0 - Great Changes Upcoming This Fall - GDG DevFest Ukraine 2016
Android Wear 2.0 - Great Changes Upcoming This Fall - GDG DevFest Ukraine 2016Android Wear 2.0 - Great Changes Upcoming This Fall - GDG DevFest Ukraine 2016
Android Wear 2.0 - Great Changes Upcoming This Fall - GDG DevFest Ukraine 2016
 
C++ AMP 실천 및 적용 전략
C++ AMP 실천 및 적용 전략 C++ AMP 실천 및 적용 전략
C++ AMP 실천 및 적용 전략
 
Rust Workshop - NITC FOSSMEET 2017
Rust Workshop - NITC FOSSMEET 2017 Rust Workshop - NITC FOSSMEET 2017
Rust Workshop - NITC FOSSMEET 2017
 
First fare 2010 java-beta-2011
First fare 2010 java-beta-2011First fare 2010 java-beta-2011
First fare 2010 java-beta-2011
 
The Web map stack on Django
The Web map stack on DjangoThe Web map stack on Django
The Web map stack on Django
 
How to Hack a Road Trip with a Webcam, a GSP and Some Fun with Node
How to Hack a Road Trip  with a Webcam, a GSP and Some Fun with NodeHow to Hack a Road Trip  with a Webcam, a GSP and Some Fun with Node
How to Hack a Road Trip with a Webcam, a GSP and Some Fun with Node
 

More from Pance Cavkovski (9)

Jprofessionals co create the future of your city
Jprofessionals co create the future of your cityJprofessionals co create the future of your city
Jprofessionals co create the future of your city
 
Gluing the IoT world with Java and LoRaWAN (Jfokus 2018)
Gluing the IoT world with Java and LoRaWAN (Jfokus 2018)Gluing the IoT world with Java and LoRaWAN (Jfokus 2018)
Gluing the IoT world with Java and LoRaWAN (Jfokus 2018)
 
Gluing the iot world (ICT)
Gluing the iot world (ICT)Gluing the iot world (ICT)
Gluing the iot world (ICT)
 
Gluing the IoT world with Java and LoRaWAN
Gluing the IoT world with Java and LoRaWANGluing the IoT world with Java and LoRaWAN
Gluing the IoT world with Java and LoRaWAN
 
VDB16 - DIY Java & Kubernetes
VDB16 - DIY Java & KubernetesVDB16 - DIY Java & Kubernetes
VDB16 - DIY Java & Kubernetes
 
DIY Java & Kubernetes
DIY Java & KubernetesDIY Java & Kubernetes
DIY Java & Kubernetes
 
Connected hardware for Software Engineers 101
Connected hardware for Software Engineers 101Connected hardware for Software Engineers 101
Connected hardware for Software Engineers 101
 
Hands on Java8 and RaspberryPi
Hands on Java8 and RaspberryPiHands on Java8 and RaspberryPi
Hands on Java8 and RaspberryPi
 
Web sockets in Java
Web sockets in JavaWeb sockets in Java
Web sockets in Java
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 

Micro and moblile: Java on the Raspberry Pi

  • 1. Micro & Mobile Java8 on the Raspberry Pi 22 Dec 2013, JavaDay, Pance Cavkovski
  • 2. The Device - Raspberry Pi + Arduino - Basic multimeter: AC/DC voltage, frequency spectrum, resistance - Results shown in a mobile web application Netcetera | 2
  • 3. The hardware - Raspberry Pi - Arduino Mega 2560 - Custom adapter and interface board Netcetera | 3
  • 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. 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. 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. 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
  • 10. The demo – DC Voltage Netcetera | 10
  • 11. The demo – AC waveline Netcetera | 11
  • 12. The demo - Spectrum Netcetera | 12
  • 13. The demo - Resistance Netcetera | 13
  • 14. The mobile reason - Mobile is not just responsive - Mobile browsers are getting lot faster - JavaScript applications can run smoothly Netcetera | 14
  • 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. 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. - 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