{"id":352,"date":"2011-10-29T21:10:13","date_gmt":"2011-10-29T19:10:13","guid":{"rendered":"http:\/\/blog.herrwolff.org\/?p=352"},"modified":"2011-11-02T20:24:15","modified_gmt":"2011-11-02T18:24:15","slug":"arduino-und-processing","status":"publish","type":"post","link":"http:\/\/blog.herrwolff.org\/?p=352","title":{"rendered":"Arduino und Processing"},"content":{"rendered":"<p>[seriesposts name=&#8220;Arduino&#8220;, orderby=&#8220;user_order&#8220;]<\/p>\n<p>Das Zusammenspiel von Processing und Arduino er\u00f6ffnet viele M\u00f6glichkeiten.<br \/>\nAm Beispiel einer einfachen Wetterstation m\u00f6chte ich das verdeutlichen.<\/p>\n<p>Was ganze soll ungef\u00e4hr so aussehen.<br \/>\n<img data-attachment-id=\"374\" data-permalink=\"http:\/\/blog.herrwolff.org\/wp-content\/uploads\/2011\/10\/TemperaturAnzeige.png\" data-orig-file=\"http:\/\/blog.herrwolff.org\/wp-content\/uploads\/2011\/10\/TemperaturAnzeige.png\" data-orig-size=\"210,231\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"Angezeigte aktuellen Temperatur noch farblich unterlegt \" data-image-description=\"\" data-medium-file=\"http:\/\/blog.herrwolff.org\/wp-content\/uploads\/2011\/10\/TemperaturAnzeige.png\" data-large-file=\"http:\/\/blog.herrwolff.org\/wp-content\/uploads\/2011\/10\/TemperaturAnzeige.png\" loading=\"lazy\" width=\"210\" height=\"231\" class=\"wp-image-374 size-full\" title=\"Temperaturanzeige mit einer Processing App\" src=\"http:\/\/blog.herrwolff.org\/wp-content\/uploads\/2011\/10\/TemperaturAnzeige.png\" alt=\"\" \/><br \/>\nDas zentrale Feld soll je nach Temperatur seine Farbe \u00e4ndern.<\/p>\n<h1>Arduino &#8212; Misst die Temperatur<\/h1>\n<h2>Aufgaben von Arduino (Microkontroller Board)<\/h2>\n<ul>\n<li>Messen der Temperatur<\/li>\n<li>\u00dcbermitteln der Messdaten \u00fcber die serielle Schnittstelle<\/li>\n<\/ul>\n<p>[js_markieren]<\/p>\n<div id=\"code1\" style=\"overflow: auto; height: 200px;\">\n<input onclick=\"fnSelect('code1')\" type=\"button\" value=\"Markiere Code\" \/><\/p>\n<pre>\/*\r\n  Measure the Temperature with the Sensor LM35CZ every 1 second\r\n  and write the value to the serial port (format \"xx C\").\r\n\r\n  Author: Wolfgang Wolff\r\n  Date: 27.10.2011\r\n*\/\r\n\r\nconst unsigned int TEMP_SENSOR_PIN = 0;\r\nconst float SUPPLY_VOLTAGE = 5000;\r\nconst unsigned int BOUD_RATE = 9600;\r\n\r\nvoid setup() {\r\n  Serial.begin(BOUD_RATE);\r\n}\r\n\r\nvoid loop() {\r\n  Serial.print(int(get_temperature()*100));\r\n  Serial.println(\" C\");\r\n  delay(1000);\r\n}\r\n\r\nconst float get_temperature() {\r\n  const int sensor_volate = analogRead(TEMP_SENSOR_PIN);\r\n  const float voltage = sensor_volate *(SUPPLY_VOLTAGE \/ 1024);\r\n  return voltage \/ 10;\r\n}<\/pre>\n<\/div>\n<h1><\/h1>\n<h1>Processing &#8212; liest die Daten und stellt sie dar<\/h1>\n<h2>Aufgaben von Processing (PC)<\/h2>\n<ul>\n<li>Aufbau einer seriellen Verbindung zum Arduino<\/li>\n<li>Lesen und Formatierung der Temperaturdaten<\/li>\n<li>Ausgabe der aktuellen Temperatur in einem Fenster<\/li>\n<\/ul>\n<p>[js_markieren]<\/p>\n<div id=\"code2\" style=\"overflow: auto; height: 200px;\"><input onclick=\"fnSelect('code2')\" type=\"button\" value=\"Markiere Code\" \/><\/p>\n<pre>\/**\r\n   Read the temperature over the serial port (Format: \"int C\")\r\n   and write the Temperature to the Window with changing the backgroundcolor\r\n   of the window center part.\r\n\r\n   Author: Wolfgang Wolff\r\n   Date: 27.10.2011\r\n*\/\r\nimport processing.serial.*;\r\n\r\nfinal int LINE_FEED = 10;\r\nfinal int BAUD_RATE = 9600;\r\nSerial arduinoPort;\r\n\r\nvoid setup() {\r\n  println(Serial.list());\r\n  arduinoPort = new Serial(this, Serial.list()[0], BAUD_RATE);\r\n  arduinoPort.bufferUntil(LINE_FEED);\r\n  PFont font = loadFont(\"Courier-20.vlw\");\r\n  textFont(font,20);\r\n  size(200,200);\r\n  fill(150);\r\n  rect(0, 0, 200, 200);\r\n  colorTempTable();\r\n}\r\n\r\nvoid draw() {\r\n  fill(150);\r\n  rect(40, 10, 120, 30);\r\n  delay(1000);\r\n  fill(50);\r\n  float temperature = readTemperature(arduinoPort);\r\n  text(temperature +\" C\",50,30);\r\n  paintTemperature(temperature);\r\n}\r\n\r\nfloat readTemperature(Serial port) {\r\n  final String arduinoData = port.readStringUntil(LINE_FEED);\r\n  float temp = 0.0;\r\n  if(arduinoData != null) {\r\n    final String[] data = split(trim(arduinoData), ' ');\r\n    temp = int(data[0]);\r\n    println(temp);\r\n  }\r\n  return temp\/100.0;\r\n}\r\n\r\nvoid paintTemperature(float temp) {\r\n  if (temp &lt; 20.0) {\r\n    fill(0,0,255);\r\n    rect(50, 50, 100, 100);\r\n  }\r\n  if (temp &lt; 25.0 &amp;&amp; temp &gt; 20.0) {\r\n    fill(0,255,0);\r\n    rect(50, 50, 100, 100);\r\n  }\r\n  if (temp &lt; 30.0 &amp;&amp; temp &gt; 25.0) {\r\n    fill(255,187,13);\r\n    rect(50, 50, 100, 100);\r\n  }\r\n  if (temp &gt;30.0) {\r\n    fill(255,0,0);\r\n    rect(50, 50, 100, 100);\r\n  }\r\n}\r\n\r\nvoid colorTempTable() {\r\n   \/\/ draw color table\r\n   fill(0,0,255);\r\n   rect(50,175,25,25);\r\n   fill(0,255,0);\r\n   rect(75,175,25,25);\r\n   fill(255,187,13);\r\n   rect(100, 175, 25, 25);\r\n   fill(255,0,0);\r\n   rect(125, 175, 25, 25);\r\n   \/\/ write text\r\n   fill(50);\r\n   text(20,62,195);\r\n   text(25,87,195);\r\n   text(30,112,195);\r\n}<\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>[seriesposts name=&#8220;Arduino&#8220;, orderby=&#8220;user_order&#8220;] Das Zusammenspiel von Processing und Arduino er\u00f6ffnet viele M\u00f6glichkeiten. Am Beispiel einer einfachen Wetterstation m\u00f6chte ich das verdeutlichen. Was ganze soll ungef\u00e4hr so aussehen. Das zentrale Feld soll je nach Temperatur seine Farbe \u00e4ndern. Arduino &#8212; Misst die Temperatur Aufgaben von Arduino (Microkontroller Board) Messen der Temperatur \u00dcbermitteln der Messdaten \u00fcber die &hellip; <a href=\"http:\/\/blog.herrwolff.org\/?p=352\" class=\"more-link\"><span class=\"screen-reader-text\">Arduino und Processing<\/span> weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"spay_email":"","jetpack_publicize_message":""},"categories":[26,8],"tags":[],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/p1ZaWF-5G","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/blog.herrwolff.org\/index.php?rest_route=\/wp\/v2\/posts\/352"}],"collection":[{"href":"http:\/\/blog.herrwolff.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.herrwolff.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.herrwolff.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.herrwolff.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=352"}],"version-history":[{"count":40,"href":"http:\/\/blog.herrwolff.org\/index.php?rest_route=\/wp\/v2\/posts\/352\/revisions"}],"predecessor-version":[{"id":371,"href":"http:\/\/blog.herrwolff.org\/index.php?rest_route=\/wp\/v2\/posts\/352\/revisions\/371"}],"wp:attachment":[{"href":"http:\/\/blog.herrwolff.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=352"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.herrwolff.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=352"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.herrwolff.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=352"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}