17
Java8 on the Raspberry Pi Micro & Mobile 22 Dec 2013, JavaDay, Pance Cavkovski

Micro and moblile: Java on the Raspberry Pi

Embed Size (px)

DESCRIPTION

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

Citation preview

  • 1.Micro & Mobile Java8 on the Raspberry Pi22 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 boardNetcetera | 3 4. The software Browser app- Arduino readings - Java8 SE Embedded server - D3.js animated SVG graphsd3jsJSONJava Java8WebSocketlighttpdpi4j Serial communicationAnalog read + FFTNetcetera | 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 8. The homepageNetcetera | 8 9. The graphsNetcetera | 9 10. The demo DC VoltageNetcetera | 10 11. The demo AC wavelineNetcetera | 11 12. The demo - SpectrumNetcetera | 12 13. The demo - ResistanceNetcetera | 13 14. The mobile reason- Mobile is not just responsive - Mobile browsers are getting lot faster - JavaScript applications can run smoothlyNetcetera | 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 availableNetcetera | 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 availableNetcetera | 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