{"id":10312,"date":"2014-01-07T21:31:33","date_gmt":"2014-01-08T02:31:33","guid":{"rendered":"http:\/\/scruss.com\/blog\/?p=10312"},"modified":"2015-11-01T08:55:12","modified_gmt":"2015-11-01T13:55:12","slug":"processing-2-1-oracle-java-raspberry-pi-serial-arduino-%e2%98%ba","status":"publish","type":"post","link":"https:\/\/scruss.com\/blog\/2014\/01\/07\/processing-2-1-oracle-java-raspberry-pi-serial-arduino-%e2%98%ba\/","title":{"rendered":"Processing 2.1 + Oracle Java + Raspberry Pi + Serial + Arduino = \u00e2\u02dc\u00ba"},"content":{"rendered":"<p style=\"padding-left: 60px;\"><span style=\"color: #ff0000;\"><strong>Hey! This is very old and there&#8217;s an <a href=\"https:\/\/github.com\/processing\/processing\/wiki\/Raspberry-Pi\">officially supported<\/a> version <a href=\"https:\/\/processing.org\/download\/?processing\">out<\/a> <span style=\"text-decoration: underline;\">now<\/span> <del>coming out very soon<\/del>.<\/strong><\/span><\/p>\n<p style=\"padding-left: 30px;\"><strong>Update for Raspberry Pi 2\/Processing 2.2.1\/Processing 3.0.5<\/strong>: Raspbian now ships with Java 8, and Processing only likes Java 7. <tt>oracle-java7-jdk<\/tt> is still in the repos, so install that, and follow the instructions below. It&#8217;s a bit flakey, but when it runs, runs quite fast on the Raspberry Pi 2. You might have more luck running <a href=\"http:\/\/processingjs.org\/\">Processing.js<\/a> or <a href=\"http:\/\/p5js.org\/\">p5.js<\/a> in the browser.<\/p>\n<p>With <del>Sun<\/del> Oracle hardfloat Java now available, Processing now runs at a decent clip on the Raspberry Pi. My <a href=\"http:\/\/scruss.com\/blog\/2012\/08\/12\/controlling-an-arduino-from-raspberry-pi-using-processing\/\">old instructions<\/a> are now very obsolete. Here are current, tested instructions for installing it under <a href=\"http:\/\/raspbian.org\/\">Raspbian<\/a>.<\/p>\n<p>[<em>This is a particular solution to installing a Serial\/Firmata-enabled <a href=\"http:\/\/processing.org\/\">Processing<\/a> 2.1 distribution on a Raspberry Pi. Processing still has issues with other aspects of visual programming (particularly video) that I&#8217;m not addressing here.<\/em>]<\/p>\n<p>A lot of software is installed here, and much of it depends on previous steps. Don&#8217;t jump in mid-way and expect it to work.<\/p>\n<h2>Update the system<\/h2>\n<p>Always a good plan if you&#8217;re doing major upgrades:<\/p>\n<pre>sudo apt-get update\r\nsudo apt-get dist-upgrade<\/pre>\n<h2>Install <del>Sun<\/del> Oracle Java<\/h2>\n<pre>sudo apt-get install oracle-java7-jdk<\/pre>\n<p>Check if the right version is installed as default: <span style=\"font-family: andale mono,times;\">java -version<\/span> should give<\/p>\n<pre>java version \"1.7.0_40\"\r\nJava(TM) SE Runtime Environment (build 1.7.0_40-b43)\r\nJava HotSpot(TM) Client VM (build 24.0-b56, mixed mode)<\/pre>\n<p>If you get anything else, you need to make <del>Sun<\/del> Oracle&#8217;s version the default:<\/p>\n<pre>sudo update-alternatives --config java<\/pre>\n<h2>Download &amp; Install Processing<\/h2>\n<p>Go to <a href=\"http:\/\/processing.org\/download\/?processing\">Download \\ Processing.org<\/a> and get the Linux 32-bit version.\u00c2\u00a0 It&#8217;s big; about 100 MB. I&#8217;m going to install it in my home directory, so the base path will be <span style=\"font-family: andale mono,times;\">~\/processing-2.1<\/span>. Extract it:<\/p>\n<pre>tar xvzf processing-2.1-linux32.tgz<\/pre>\n<p>Now you have to remove the included <em>x86<\/em> Java runtime, and replace it with the Raspberry Pi&#8217;s <em>armhf<\/em> one:<\/p>\n<pre>rm -rf ~\/processing-2.1\/java \r\nln -s \/usr\/lib\/jvm\/jdk-7-oracle-armhf ~\/processing-2.1\/java<\/pre>\n<p>You should now have a Processing installation that will run, but there&#8217;s some more we need to get serial and Arduino support.<\/p>\n<h2>Install the\u00c2\u00a0 java Simple Serial connector<\/h2>\n<p>Download <a href=\"http:\/\/code.google.com\/p\/java-simple-serial-connector\/downloads\/detail?name=jSSC-2.6.0-Release.zip&amp;can=2&amp;q=\">jSSC-2.6.0-Release.zip<\/a> and extract it:<\/p>\n<pre>unzip jSSC-2.6.0-Release.zip<\/pre>\n<p>Now overwrite the jssc.jar that ships with Processing with the one you just downloaded:<\/p>\n<pre>mv jSSC-2.6.0-Release\/jssc.jar ~\/processing-2.1\/modes\/java\/libraries\/serial\/library\/<\/pre>\n<p>(You can remove the jSSC folder now: <span style=\"font-family: andale mono,times;\">rm -r jSSC-2.6.0-Release<\/span>)<\/p>\n<h2>Test Processing&#8217;s serial support<\/h2>\n<p>You&#8217;re almost there! Fire up Processing:<\/p>\n<pre>~\/processing-2.1\/processing<\/pre>\n<p>and try <a href=\"http:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2014\/01\/sertest-140107a.zip\"><em>Perhaps the World&#8217;s Most Boring Processing Sketch<\/em>\u00e2\u201e\u00a2<\/a>:<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n\/\/ Example by Tom Igoe\r\n\r\nimport processing.serial.*;\r\n\r\n\/\/ The serial port\r\nSerial myPort;\r\n\r\n\/\/ List all the available serial ports\r\nprintln(Serial.list());\r\n<\/pre>\n<p><a href=\"http:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2014\/01\/Screenshot-from-2014-01-07-200832.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-10313\" src=\"http:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2014\/01\/Screenshot-from-2014-01-07-200832.png\" alt=\"Screenshot from 2014-01-07 20:08:32\" width=\"500\" height=\"600\" srcset=\"https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2014\/01\/Screenshot-from-2014-01-07-200832.png 500w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2014\/01\/Screenshot-from-2014-01-07-200832-133x160.png 133w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2014\/01\/Screenshot-from-2014-01-07-200832-266x320.png 266w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/a>When this runs (it&#8217;s a little slow), you should get a single line of output, which should start <span style=\"font-family: andale mono,times;\">\/dev\/tty<\/span>___:<\/p>\n<pre>\/dev\/ttyACM0<\/pre>\n<p>(I have an <a href=\"http:\/\/arduino.cc\/en\/Main\/arduinoBoardLeonardo\">Arduino Leonardo<\/a> attached, which usually appears as an ACM device.)<\/p>\n<h2>Installing Arduino\/Firmata support<\/h2>\n<p>(<em>I&#8217;m not going to go into uploading <a href=\"http:\/\/firmata.org\/wiki\/Main_Page\">Firmata<\/a> onto your <a href=\"http:\/\/arduino.cc\/\">Arduino<\/a> here. All I can recommend is that you use the newest version at <a href=\"https:\/\/github.com\/firmata\/arduino\">firmata\/arduino<\/a>, rather than the old code bundled with your Arduino distribution.<\/em>)<\/p>\n<p>Exit Processing, and download processing-arduino.zip from <a href=\"https:\/\/github.com\/firmata\/processing\">firmata\/processing<\/a>. Extract it into your Processing sketchbook:<\/p>\n<pre>unzip processing-arduino.zip -d ~\/sketchbook\/libraries\/<\/pre>\n<p>For tedious reasons, you also have to rename one of the files:<\/p>\n<pre>mv\u00c2\u00a0 ~\/sketchbook\/libraries\/arduino\/library\/Arduino.jar\u00c2\u00a0 ~\/sketchbook\/libraries\/arduino\/library\/arduino.jar<\/pre>\n<p>Start up Processing again, and\u00c2\u00a0 save <a href=\"http:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2014\/01\/FakeBlink-140107a.zip\"><em>Most Probably the World&#8217;s Second Least Interesting Processing Program\u00e2\u201e\u00a2<\/em><\/a>:<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nimport processing.serial.*;\r\nimport cc.arduino.*;\r\nArduino arduino;\r\nint ledPin = 13;\r\n\r\nvoid setup()\r\n{\r\n  println(Arduino.list());\r\n  arduino = new Arduino(this, Arduino.list()&#x5B;0], 57600);\r\n  arduino.pinMode(ledPin, Arduino.OUTPUT);\r\n}\r\n\r\nvoid draw()\r\n{\r\n  arduino.digitalWrite(ledPin, Arduino.HIGH);\r\n  delay(1000);\r\n  arduino.digitalWrite(ledPin, Arduino.LOW);\r\n  delay(1000);\r\n}\r\n<\/pre>\n<p><a href=\"http:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2014\/01\/Screenshot-from-2014-01-07-211354.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-10318\" src=\"http:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2014\/01\/Screenshot-from-2014-01-07-211354.png\" alt=\"Screenshot from 2014-01-07 21:13:54\" width=\"500\" height=\"600\" srcset=\"https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2014\/01\/Screenshot-from-2014-01-07-211354.png 500w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2014\/01\/Screenshot-from-2014-01-07-211354-133x160.png 133w, https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2014\/01\/Screenshot-from-2014-01-07-211354-266x320.png 266w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/a><br \/>\nWhat this sketch does is emulate the \u00c2\u00b5C&#8217;s \u00e2\u20ac\u0153Hello World\u00e2\u20ac\u009d program, <a href=\"http:\/\/wiring.org.co\/learning\/basics\/blink.html\">Blink<\/a>. It flashes the board&#8217;s LED once per second. Boring? Yes. But if it worked, you have a working Processing 2.1 installation on your Raspberry Pi. Go forth and make more interesting things.<br \/>\n(<em>Props to <a href=\"https:\/\/github.com\/bitcraftlab\/wolfing#install-processing\">bitcraftlab\/wolfing<\/a> for the basic outline for installing Processing, and for <a href=\"http:\/\/www.raspberrypi.org\/phpBB3\/viewtopic.php?f=44&amp;t=64294\">samaygoenka<\/a> for the prodding needed to update and test the Processing installation process. If you&#8217;re still stuck, the <a href=\"http:\/\/forum.processing.org\/two\/\">Processing 2.0 Forum<\/a> and the <a href=\"http:\/\/www.raspberrypi.org\/phpBB3\/index.php?sid=714b8f22b15f3dd4f243409b43dd09ed\">Raspberry Pi Forum<\/a> are good places to ask.<\/em>)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey! This is very old and there&#8217;s an officially supported version out now coming out very soon. Update for Raspberry Pi 2\/Processing 2.2.1\/Processing 3.0.5: Raspbian now ships with Java 8, and Processing only likes Java 7. oracle-java7-jdk is still in the repos, so install that, and follow the instructions below. It&#8217;s a bit flakey, but [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[7],"tags":[2207,2543,1334,2765,2541,2510,2536,2542,1539],"class_list":["post-10312","post","type-post","status-publish","format-standard","hentry","category-computers-suck","tag-arduino","tag-firmata","tag-java","tag-oracle","tag-processing","tag-raspberrypi","tag-raspbian","tag-serial","tag-sun"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pQNZZ-2Gk","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/10312","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/comments?post=10312"}],"version-history":[{"count":8,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/10312\/revisions"}],"predecessor-version":[{"id":12431,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/10312\/revisions\/12431"}],"wp:attachment":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/media?parent=10312"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/categories?post=10312"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/tags?post=10312"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}