{"id":6390,"date":"2021-04-14T11:27:35","date_gmt":"2021-04-14T10:27:35","guid":{"rendered":"https:\/\/blog.fh-kaernten.at\/ingmarsretro\/2021\/04\/14\/data-node-with-arduino\/"},"modified":"2021-04-14T11:27:35","modified_gmt":"2021-04-14T10:27:35","slug":"data-node-with-arduino","status":"publish","type":"post","link":"https:\/\/blog.fh-kaernten.at\/ingmarsretro\/2021\/04\/14\/data-node-with-arduino\/?lang=en","title":{"rendered":"Data Node with Arduino"},"content":{"rendered":"<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_6390\" class=\"pvc_stats all  \" data-element-id=\"6390\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/blog.fh-kaernten.at\/ingmarsretro\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n<p style=\"text-align: justify\">Unfortunately, the intervals in which I find some time to write a new post for the blog have not gotten shorter. But post a post per month, I think &#8230; \ud83d\ude42<\/p>\n<p style=\"text-align: justify\"><a href=\"http:\/\/blog.fh-kaernten.at\/ingmarsretro\/files\/2018\/06\/IMG_20180530_194226.jpg\"><img fetchpriority=\"high\" decoding=\"async\" class=\"wp-image-3370 alignleft\" src=\"http:\/\/blog.fh-kaernten.at\/ingmarsretro\/files\/2018\/06\/IMG_20180530_194226-300x225.jpg\" alt=\"\" width=\"271\" height=\"203\" srcset=\"https:\/\/blog.fh-kaernten.at\/ingmarsretro\/files\/2018\/06\/IMG_20180530_194226-300x225.jpg 300w, https:\/\/blog.fh-kaernten.at\/ingmarsretro\/files\/2018\/06\/IMG_20180530_194226-768x576.jpg 768w, https:\/\/blog.fh-kaernten.at\/ingmarsretro\/files\/2018\/06\/IMG_20180530_194226-1024x768.jpg 1024w\" sizes=\"(max-width: 271px) 100vw, 271px\" \/><\/a>This time it&#8217;s not a retro craft project from the local Gefielden or a restoration of an old device, but again something about Arduino. The idea &#8211; to build a sensor that, as always, transforms a physical quantity into an electrical signal. This is nothing special and what kind of sensor it will be, I will not describe for the time being. But there should not be a sensor board, but many. And these sensor boards short &#8222;sensors&#8220; are to be networked together in a two-dimensional matrix. You can imagine it as a chessboard, with each of the chessboard panels representing a sensor. This network of sensors &#8211; ie sensor nodes &#8211; should then be connected via a transfer point to a computer and output the sensor data of the respective field. It should then also be possible to remove individual fields from the network without the remaining network losing its function.<\/p>\n<p style=\"text-align: justify\">The whole system should be as simple and cheap as possible. And so a system concept was quickly developed in which the nodes communicate via the I\u00b2C bus and send their data to a master. The following diagram is intended to illustrate this.<\/p>\n<p><a href=\"http:\/\/blog.fh-kaernten.at\/ingmarsretro\/files\/2018\/06\/systemkonzept.jpg\"><img decoding=\"async\" class=\"aligncenter wp-image-6391 size-full\" src=\"http:\/\/blog.fh-kaernten.at\/ingmarsretro\/files\/2018\/06\/systemkonzept.jpg\" alt=\"\" width=\"633\" height=\"818\" srcset=\"https:\/\/blog.fh-kaernten.at\/ingmarsretro\/files\/2018\/06\/systemkonzept.jpg 633w, https:\/\/blog.fh-kaernten.at\/ingmarsretro\/files\/2018\/06\/systemkonzept-232x300.jpg 232w\" sizes=\"(max-width: 633px) 100vw, 633px\" \/><\/a><\/p>\n<p style=\"text-align: justify\">This concept, I thought, is easiest to implement with an ATmega microcontroller. The has enough IO&#8217;s, an I\u00b2C bus and UART onboard, as well as analog inputs and requires little component peripherals to bring it to life in its own layout. And there is nothing faster to do such a test setup of such a node network than to use the well-known Arduino development boards. I have chosen the cheapest version for a test setup -&gt; the Chinanachbau of the ArduinoUno (Joy-IT UNO) with the Atmga328 in the capped DIL housing.<\/p>\n<div id=\"attachment_3376\" style=\"width: 235px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/blog.fh-kaernten.at\/ingmarsretro\/files\/2018\/06\/IMG_20180516_142337.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-3376\" class=\"size-medium wp-image-3376\" src=\"http:\/\/blog.fh-kaernten.at\/ingmarsretro\/files\/2018\/06\/IMG_20180516_142337-225x300.jpg\" alt=\"\" width=\"225\" height=\"300\" srcset=\"https:\/\/blog.fh-kaernten.at\/ingmarsretro\/files\/2018\/06\/IMG_20180516_142337-225x300.jpg 225w, https:\/\/blog.fh-kaernten.at\/ingmarsretro\/files\/2018\/06\/IMG_20180516_142337-768x1024.jpg 768w\" sizes=\"(max-width: 225px) 100vw, 225px\" \/><\/a><p id=\"caption-attachment-3376\" class=\"wp-caption-text\">Joy-It Uno Boards<\/p><\/div>\n<p style=\"text-align: justify\">The picture shows ten of these microcontroller boards. Of these, one should be used as a bus master and nine as slaves. Of course, each of these slaves has a unique bus address, which only occurs once in the system. In the test setup, this bus address is permanently assigned via the program code, since anyway each Arduino must be connected to the computer in order to carry out the program upload. Of course, that should look different later. Because the Arduino is on the Atmega328 chip, its quartz and the few resistors reduced on the sensor board with gelayoutet. The chip should then be programmed via the ISP pins. Of course, as many boards do not always customize the program code and they all have the same Flash file, I want to set the sensor address with a 7-bit DIP switch. A 4021 Cmos Static Shift Register is supposed to read the bits after the controller is powered on and push them serially into the controller. The resulting value is then available as a bus address in a variable.<\/p>\n<p style=\"text-align: justify\">Each of these slaves with their individual bus address is now queried in sequence by the master node, which state it has and whether it should switch an output or not. That is, the node has only one DO (digital output) with which it can, for example, turn an LED off and on and interrogate one or more DIs (digital input) which polls a state, for example a simple switch. These functions are stored in 2 bits of a byte. Another byte is used to transfer the bus address. So two bytes are sent over the bus. The picture below shows the test setup with the &#8222;UNO boards&#8220;<\/p>\n<div id=\"attachment_3375\" style=\"width: 235px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/blog.fh-kaernten.at\/ingmarsretro\/files\/2018\/06\/IMG_20180516_150742.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-3375\" class=\"size-medium wp-image-3375\" src=\"http:\/\/blog.fh-kaernten.at\/ingmarsretro\/files\/2018\/06\/IMG_20180516_150742-225x300.jpg\" alt=\"\" width=\"225\" height=\"300\" srcset=\"https:\/\/blog.fh-kaernten.at\/ingmarsretro\/files\/2018\/06\/IMG_20180516_150742-225x300.jpg 225w, https:\/\/blog.fh-kaernten.at\/ingmarsretro\/files\/2018\/06\/IMG_20180516_150742-768x1024.jpg 768w\" sizes=\"(max-width: 225px) 100vw, 225px\" \/><\/a><p id=\"caption-attachment-3375\" class=\"wp-caption-text\">All Arduinos are connected to I\u00b2C data bus and power supply<\/p><\/div>\n<p style=\"text-align: justify\">The process is as follows:<\/p>\n<p style=\"text-align: justify\"><strong>MASTER:<br \/>\n<\/strong>The master node sends a request after the series to all slave addresses and a switch command (which comes from all nodes of a TEST push button input on the master) for the LED output of the node and sees if a response comes back or not. If no answer comes, the node is not in the network or is defective. If there is an answer, this consists of the address of the node and its status byte. This information is transmitted via an RS232 terminal to the computer connected to the master. Thus, for example, the switching status of each individual node can be displayed on the screen via a visualization using (NI LabView, or Matlab or similar). By adapting the master program, it is also possible to switch the LED outputs of the slaves via the computer.<\/p>\n<p style=\"text-align: justify\"><strong>SLAVE:<\/strong><br \/>\nWhen the master node requests data from the slave, the slave sends back two bytes. Where byte0 again is the slave ID (ie bus address) and byte1 is the data. Byte1 actually consists of only two bits encoded as follows (in decimal representation):<br \/>\n&nbsp;0 = LED off| Sensor not triggered<br \/>\n&nbsp;1 = LED on | Sensor not triggered<br \/>\n&nbsp;2 = LED off | Sensor triggered<br \/>\n&nbsp;3 = LED on | Sensor triggered<\/p>\n<p>The program code as an example:<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #f8f8f8;overflow: auto;width: auto;border: solid gray;border-width: .1em .1em .1em .8em;padding: .2em .6em\">\n<table>\n<tbody>\n<tr>\n<td>\n<pre style=\"margin: 0;line-height: 125%\"> 1\r\n 2\r\n 3\r\n 4\r\n 5\r\n 6\r\n 7\r\n 8\r\n 9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n18\r\n19\r\n20\r\n21\r\n22\r\n23\r\n24\r\n25\r\n26\r\n27\r\n28\r\n29\r\n30\r\n31\r\n32\r\n33\r\n34\r\n35\r\n36\r\n37\r\n38\r\n39\r\n40\r\n41\r\n42\r\n43\r\n44\r\n45\r\n46\r\n47\r\n48\r\n49\r\n50\r\n51\r\n52\r\n53\r\n54\r\n55\r\n56\r\n57\r\n58\r\n59\r\n60\r\n61\r\n62\r\n63\r\n64\r\n65\r\n66\r\n67\r\n68\r\n69\r\n70\r\n71\r\n72\r\n73\r\n74\r\n75\r\n76\r\n77\r\n78<\/pre>\n<\/td>\n<td>\n<pre style=\"margin: 0;line-height: 125%\"><span style=\"color: #408080;font-style: italic\">\/\/ I2C Slave Code<\/span>\r\n<span style=\"color: #408080;font-style: italic\">\/\/ 16.05.2018 <\/span>\r\n<span style=\"color: #408080;font-style: italic\">\/\/ ver 1.3<\/span>\r\n<span style=\"color: #bc7a00\">#include &lt;Wire.h&gt;<\/span>\r\n<span style=\"color: #bc7a00\">#define ADDRESS 2     <\/span><span style=\"color: #408080;font-style: italic\">\/\/ adresse des slave knotens<\/span>\r\n<span style=\"color: #bc7a00\">#define PAYLOAD_SIZE 2 <\/span><span style=\"color: #408080;font-style: italic\">\/\/ anzahl der bytes  die vom masterknoten zu erwarten sind<\/span>\r\n<span style=\"color: #b00040\">int<\/span> LED<span style=\"color: #666666\">=12<\/span>;            <span style=\"color: #408080;font-style: italic\">\/\/ indicator led an pin D12<\/span>\r\n<span style=\"color: #b00040\">int<\/span> SENSOR <span style=\"color: #666666\">=<\/span> <span style=\"color: #666666\">8<\/span>;        <span style=\"color: #408080;font-style: italic\">\/\/ sensor input an pin D8<\/span>\r\n<span style=\"color: #b00040\">bool<\/span> actionState<span style=\"color: #666666\">=0<\/span>;      <span style=\"color: #408080;font-style: italic\">\/\/ sensor zustand<\/span>\r\n<span style=\"color: #b00040\">int<\/span> busstatus;  <span style=\"color: #408080;font-style: italic\">\/\/ statusvariable <\/span>\r\n                       <span style=\"color: #408080;font-style: italic\">\/\/ 0 = LED aus | sensor nicht belegt<\/span>\r\n                       <span style=\"color: #408080;font-style: italic\">\/\/ 1 = LED ein | sensor nicht belegt<\/span>\r\n                       <span style=\"color: #408080;font-style: italic\">\/\/ 2 = LED aus | sensor belegt<\/span>\r\n                       <span style=\"color: #408080;font-style: italic\">\/\/ 3 = LED ein | sensor belegt<\/span>\r\n \r\n<span style=\"color: #b00040\">bool<\/span> sensled<span style=\"color: #666666\">=0<\/span>;          <span style=\"color: #408080;font-style: italic\">\/\/ sensor LED<\/span>\r\nbyte nodePayload[PAYLOAD_SIZE];\r\n\r\n<span style=\"color: #b00040\">void<\/span> <span style=\"color: #0000ff\">setup<\/span>()\r\n{\r\n  pinMode(LED, OUTPUT);         <span style=\"color: #408080;font-style: italic\">\/\/sensorLED<\/span>\r\n  pinMode(SENSOR, INPUT);       <span style=\"color: #408080;font-style: italic\">\/\/Sensor <\/span>\r\n  Wire.begin(ADDRESS);          <span style=\"color: #408080;font-style: italic\">\/\/ Activate I2C network<\/span>\r\n  Wire.onReceive(receiveEvent);\r\n  Wire.onRequest(requestEvent); <span style=\"color: #408080;font-style: italic\">\/\/ auf master anforderung warten<\/span>\r\n                      <span style=\"color: #408080;font-style: italic\">\/\/  \/\/ debug interface<\/span>\r\n                      <span style=\"color: #408080;font-style: italic\">\/\/  Serial.begin(9600); <\/span>\r\n}\r\n\r\n<span style=\"color: #408080;font-style: italic\">\/\/ *********************************mainloop****************************************************<\/span>\r\n<span style=\"color: #b00040\">void<\/span> <span style=\"color: #0000ff\">loop<\/span>()\r\n{ \r\n  delay(<span style=\"color: #666666\">5<\/span>);\r\n  \r\n   <span style=\"color: #008000;font-weight: bold\">if<\/span>(sensled){digitalWrite(LED, HIGH);}\r\n         <span style=\"color: #008000;font-weight: bold\">else<\/span>{digitalWrite(LED, LOW);}\r\n\r\n  actionState <span style=\"color: #666666\">=<\/span> digitalRead(SENSOR);  <span style=\"color: #408080;font-style: italic\">\/\/Sensoreingang abfragen        <\/span>\r\n   <span style=\"color: #008000;font-weight: bold\">if<\/span>((actionState<span style=\"color: #666666\">==1<\/span>)<span style=\"color: #666666\">&amp;&amp;<\/span>(sensled<span style=\"color: #666666\">==1<\/span>)) {busstatus<span style=\"color: #666666\">=3<\/span>;}\r\n   <span style=\"color: #008000;font-weight: bold\">else<\/span> <span style=\"color: #008000;font-weight: bold\">if<\/span> ((actionState<span style=\"color: #666666\">==0<\/span>)<span style=\"color: #666666\">&amp;&amp;<\/span>(sensled<span style=\"color: #666666\">==1<\/span>)) {busstatus<span style=\"color: #666666\">=1<\/span>;}\r\n   <span style=\"color: #008000;font-weight: bold\">else<\/span> <span style=\"color: #008000;font-weight: bold\">if<\/span> ((actionState<span style=\"color: #666666\">==1<\/span>)<span style=\"color: #666666\">&amp;&amp;<\/span>(sensled<span style=\"color: #666666\">==0<\/span>)) {busstatus<span style=\"color: #666666\">=2<\/span>;}\r\n   <span style=\"color: #008000;font-weight: bold\">else<\/span> <span style=\"color: #008000;font-weight: bold\">if<\/span> ((actionState<span style=\"color: #666666\">==0<\/span>)<span style=\"color: #666666\">&amp;&amp;<\/span>(sensled<span style=\"color: #666666\">==0<\/span>)) {busstatus<span style=\"color: #666666\">=0<\/span>;}\r\n\r\n                      <span style=\"color: #408080;font-style: italic\">\/\/  Serial.println(\"######################\");<\/span>\r\n                      <span style=\"color: #408080;font-style: italic\">\/\/  Serial.print(\"busstatus neu setzen \");<\/span>\r\n                      <span style=\"color: #408080;font-style: italic\">\/\/  Serial.println(busstatus);<\/span>\r\n                      <span style=\"color: #408080;font-style: italic\">\/\/  Serial.print(\"sensled LED            \");<\/span>\r\n                      <span style=\"color: #408080;font-style: italic\">\/\/  Serial.println(sensled);<\/span>\r\n                      <span style=\"color: #408080;font-style: italic\">\/\/  Serial.print(\"actionState           \");<\/span>\r\n                      <span style=\"color: #408080;font-style: italic\">\/\/  Serial.println(actionState);<\/span>\r\n                      <span style=\"color: #408080;font-style: italic\">\/\/  Serial.println(\"######################\");<\/span>\r\n  nodePayload[<span style=\"color: #666666\">0<\/span>] <span style=\"color: #666666\">=<\/span> ADDRESS;                  <span style=\"color: #408080;font-style: italic\">\/\/ Adresse in byte0 zur\u00fccksenden.  <\/span>\r\n  nodePayload[<span style=\"color: #666666\">1<\/span>] <span style=\"color: #666666\">=<\/span> busstatus;                <span style=\"color: #408080;font-style: italic\">\/\/byte 1 ist die statusinfo der LED<\/span>\r\n}\r\n\r\n\r\n\r\n<span style=\"color: #408080;font-style: italic\">\/\/ *********************************************************************************************<\/span>\r\n<span style=\"color: #b00040\">void<\/span> <span style=\"color: #0000ff\">requestEvent<\/span>()\r\n{ Wire.write(nodePayload,PAYLOAD_SIZE);  \r\n  Serial.println(<span style=\"color: #ba2121\">\"bytes status schreiben\"<\/span>);\r\n  Serial.println(nodePayload[<span style=\"color: #666666\">0<\/span>]);\r\n  Serial.println(nodePayload[<span style=\"color: #666666\">1<\/span>]);\r\n  delay(<span style=\"color: #666666\">5<\/span>);\r\n}\r\n\r\n<span style=\"color: #408080;font-style: italic\">\/\/ *********************************************************************************************<\/span>\r\n<span style=\"color: #b00040\">void<\/span> <span style=\"color: #0000ff\">receiveEvent<\/span>(<span style=\"color: #b00040\">int<\/span> bytes)  <span style=\"color: #408080;font-style: italic\">\/\/einen wert vom I2C lesen<\/span>\r\n      \r\n{\r\n  \r\n  busstatus <span style=\"color: #666666\">=<\/span> Wire.read(); <span style=\"color: #408080;font-style: italic\">\/\/If the value received was true turn the led on, otherwise turn it off  <\/span>\r\n                              <span style=\"color: #408080;font-style: italic\">\/\/  Serial.println(\"status empfangen\");<\/span>\r\n                              <span style=\"color: #408080;font-style: italic\">\/\/  Serial.println(busstatus);<\/span>\r\n  <span style=\"color: #008000;font-weight: bold\">if<\/span>((busstatus<span style=\"color: #666666\">==1<\/span>)<span style=\"color: #666666\">||<\/span>(busstatus<span style=\"color: #666666\">==3<\/span>)){sensled <span style=\"color: #666666\">=<\/span> <span style=\"color: #666666\">1<\/span>;}\r\n                                <span style=\"color: #008000;font-weight: bold\">else<\/span>{sensled <span style=\"color: #666666\">=<\/span> <span style=\"color: #666666\">0<\/span>;}\r\n                                              \r\n}\r\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The bus address must still be entered individually in this slave code. In the next version, the previously described &#8222;serializer&#8220; of the parallel dip-switch variant will be implemented. The following code example is from the master node, which reads out the slaves and sends a LED pattern to the sensor slaves using the test button:<\/p>\n<p>&nbsp;<br \/>\n<!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #f8f8f8;overflow: auto;width: auto;border: solid gray;border-width: .1em .1em .1em .8em;padding: .2em .6em\">\n<table>\n<tbody>\n<tr>\n<td>\n<pre style=\"margin: 0;line-height: 125%\">  1\r\n  2\r\n  3\r\n  4\r\n  5\r\n  6\r\n  7\r\n  8\r\n  9\r\n 10\r\n 11\r\n 12\r\n 13\r\n 14\r\n 15\r\n 16\r\n 17\r\n 18\r\n 19\r\n 20\r\n 21\r\n 22\r\n 23\r\n 24\r\n 25\r\n 26\r\n 27\r\n 28\r\n 29\r\n 30\r\n 31\r\n 32\r\n 33\r\n 34\r\n 35\r\n 36\r\n 37\r\n 38\r\n 39\r\n 40\r\n 41\r\n 42\r\n 43\r\n 44\r\n 45\r\n 46\r\n 47\r\n 48\r\n 49\r\n 50\r\n 51\r\n 52\r\n 53\r\n 54\r\n 55\r\n 56\r\n 57\r\n 58\r\n 59\r\n 60\r\n 61\r\n 62\r\n 63\r\n 64\r\n 65\r\n 66\r\n 67\r\n 68\r\n 69\r\n 70\r\n 71\r\n 72\r\n 73\r\n 74\r\n 75\r\n 76\r\n 77\r\n 78\r\n 79\r\n 80\r\n 81\r\n 82\r\n 83\r\n 84\r\n 85\r\n 86\r\n 87\r\n 88\r\n 89\r\n 90\r\n 91\r\n 92\r\n 93\r\n 94\r\n 95\r\n 96\r\n 97\r\n 98\r\n 99\r\n100\r\n101\r\n102\r\n103\r\n104\r\n105\r\n106\r\n107\r\n108\r\n109\r\n110\r\n111\r\n112\r\n113\r\n114\r\n115\r\n116\r\n117\r\n118\r\n119<\/pre>\n<\/td>\n<td>\n<pre style=\"margin: 0;line-height: 125%\"><span style=\"color: #408080;font-style: italic\">\/\/ I2C masterknoten <\/span>\r\n<span style=\"color: #408080;font-style: italic\">\/\/ 16.05.2018 <\/span>\r\n<span style=\"color: #408080;font-style: italic\">\/\/ ver 1.2<\/span>\r\n<span style=\"color: #408080;font-style: italic\">\/\/ changes abfrage wenn kein knoten am bus dann 255 ausgeben<\/span>\r\n<span style=\"color: #bc7a00\">#include &lt;Wire.h&gt;<\/span>\r\n\r\n<span style=\"color: #bc7a00\">#define busbytes 2          <\/span><span style=\"color: #408080;font-style: italic\">\/\/ wievele byte vom I2C knoten zu erwarten sind<\/span>\r\n<span style=\"color: #bc7a00\">#define maxKNOTEN  10       <\/span><span style=\"color: #408080;font-style: italic\">\/\/ anzahl der zu scannenden slaves<\/span>\r\n<span style=\"color: #bc7a00\">#define startKNOTEN 2       <\/span><span style=\"color: #408080;font-style: italic\">\/\/ startadresse der slaves<\/span>\r\n<span style=\"color: #bc7a00\">#define DELAY 5             <\/span><span style=\"color: #408080;font-style: italic\">\/\/ einfach ein delay ....<\/span>\r\n\r\n<span style=\"color: #b00040\">int<\/span> i; <span style=\"color: #b00040\">int<\/span> j<span style=\"color: #666666\">=0<\/span>;\r\n<span style=\"color: #b00040\">int<\/span> buttonPin <span style=\"color: #666666\">=<\/span> <span style=\"color: #666666\">12<\/span>;\r\n<span style=\"color: #b00040\">int<\/span> testbut <span style=\"color: #666666\">=<\/span> <span style=\"color: #666666\">0<\/span>; <span style=\"color: #b00040\">int<\/span> anim <span style=\"color: #666666\">=<\/span> <span style=\"color: #666666\">0<\/span>;\r\n<span style=\"color: #b00040\">int<\/span> buttonState <span style=\"color: #666666\">=<\/span> <span style=\"color: #666666\">0<\/span>;\r\n<span style=\"color: #b00040\">int<\/span> DATEN[busbytes];\r\n<span style=\"color: #b00040\">int<\/span> adresse; <span style=\"color: #b00040\">int<\/span> busstatus;  \r\nbyte sensorbelegt; byte ledsensoron;\r\n\r\n                       <span style=\"color: #408080;font-style: italic\">\/\/ 0 = LED aus | Sensor nicht belegt<\/span>\r\n                       <span style=\"color: #408080;font-style: italic\">\/\/ 1 = LED ein | Sensor nicht belegt<\/span>\r\n                       <span style=\"color: #408080;font-style: italic\">\/\/ 2 = LED aus | Sensor belegt<\/span>\r\n                       <span style=\"color: #408080;font-style: italic\">\/\/ 3 = LED ein | Sensor belegt<\/span>\r\n\r\n<span style=\"color: #b00040\">int<\/span> leddat1[] <span style=\"color: #666666\">=<\/span> {<span style=\"color: #666666\">1<\/span>,<span style=\"color: #666666\">1<\/span>,<span style=\"color: #666666\">1<\/span>,<span style=\"color: #666666\">1<\/span>,<span style=\"color: #666666\">0<\/span>,<span style=\"color: #666666\">1<\/span>,<span style=\"color: #666666\">1<\/span>,<span style=\"color: #666666\">1<\/span>,<span style=\"color: #666666\">1<\/span>}; <span style=\"color: #408080;font-style: italic\">\/\/ -<\/span>\r\n<span style=\"color: #b00040\">int<\/span> leddat2[] <span style=\"color: #666666\">=<\/span> {<span style=\"color: #666666\">0<\/span>,<span style=\"color: #666666\">0<\/span>,<span style=\"color: #666666\">0<\/span>,<span style=\"color: #666666\">0<\/span>,<span style=\"color: #666666\">1<\/span>,<span style=\"color: #666666\">0<\/span>,<span style=\"color: #666666\">0<\/span>,<span style=\"color: #666666\">0<\/span>,<span style=\"color: #666666\">0<\/span>}; <span style=\"color: #408080;font-style: italic\">\/\/ |<\/span>\r\n\r\n<span style=\"color: #b00040\">void<\/span> <span style=\"color: #0000ff\">setup<\/span>()\r\n{\r\n  Serial.begin(<span style=\"color: #666666\">9600<\/span>);  \r\n  Serial.println(<span style=\"color: #ba2121\">\"MASTER-KNOTEN\"<\/span>);\r\n  Serial.print(<span style=\"color: #ba2121\">\"Maximum Slaveknoten: \"<\/span>);\r\n  Serial.println(maxKNOTEN);\r\n  Serial.print(<span style=\"color: #ba2121\">\"Datengroesse in byte: \"<\/span>);\r\n  Serial.println(busbytes);\r\n  Serial.println(<span style=\"color: #ba2121\">\"***********************\"<\/span>);\r\n  \r\n  Wire.begin();                 <span style=\"color: #408080;font-style: italic\">\/\/ Activate I2C link<\/span>\r\n  pinMode(buttonPin, INPUT);    <span style=\"color: #408080;font-style: italic\">\/\/ test-tastereingang festlegen<\/span>\r\n}\r\n\r\n\r\n<span style=\"color: #408080;font-style: italic\">\/\/#####################################################################################################<\/span>\r\n<span style=\"color: #b00040\">void<\/span> <span style=\"color: #0000ff\">loop<\/span>()\r\n    \r\n{\r\n  <span style=\"color: #008000;font-weight: bold\">for<\/span> (<span style=\"color: #b00040\">int<\/span> Knotenadresse <span style=\"color: #666666\">=<\/span> startKNOTEN;         <span style=\"color: #408080;font-style: italic\">\/\/alle knoten scannen<\/span>\r\n           Knotenadresse <span style=\"color: #666666\">&lt;=<\/span> maxKNOTEN; \r\n           Knotenadresse<span style=\"color: #666666\">++<\/span>) \r\n\r\n        \r\n    <span style=\"color: #408080;font-style: italic\">\/\/################################################################################################       <\/span>\r\n    { \r\n     <span style=\"color: #408080;font-style: italic\">\/\/ testbut = 0;  <\/span>\r\n     anim <span style=\"color: #666666\">=<\/span> <span style=\"color: #666666\">0<\/span>;   \r\n    Wire.requestFrom(Knotenadresse, busbytes);        <span style=\"color: #408080;font-style: italic\">\/\/ daten vom jeweiligen knoten anfordern<\/span>\r\n                                                 \r\n           DATEN[<span style=\"color: #666666\">0<\/span>]<span style=\"color: #666666\">=255<\/span>; DATEN[<span style=\"color: #666666\">1<\/span>]<span style=\"color: #666666\">=255<\/span>;   <span style=\"color: #408080;font-style: italic\">\/\/ wenn kein knoten dann auf 255 setzen    <\/span>\r\n          <span style=\"color: #008000;font-weight: bold\">if<\/span>(Wire.available() <span style=\"color: #666666\">==<\/span> busbytes) {                                    <span style=\"color: #408080;font-style: italic\">\/\/ wenn knoten und daten dann<\/span>\r\n            <span style=\"color: #008000;font-weight: bold\">for<\/span> (i <span style=\"color: #666666\">=<\/span> <span style=\"color: #666666\">0<\/span>; i <span style=\"color: #666666\">&lt;<\/span> busbytes; i<span style=\"color: #666666\">++<\/span>) DATEN[i] <span style=\"color: #666666\">=<\/span> Wire.read();          <span style=\"color: #408080;font-style: italic\">\/\/ daten holen (zuerst busID, dann daten)<\/span>\r\n           <span style=\"color: #408080;font-style: italic\">\/\/ for (j = 0; j &lt; busbytes; j++) Serial.println(DATEN[j]);        \/\/ daten an rs232 ausgeben   <\/span>\r\n          }            \r\n\r\n<span style=\"color: #408080;font-style: italic\">\/\/            Serial.println(Knotenadresse);<\/span>\r\n<span style=\"color: #408080;font-style: italic\">\/\/            Serial.println(DATEN[0]);<\/span>\r\n<span style=\"color: #408080;font-style: italic\">\/\/            Serial.println(DATEN[1]);<\/span>\r\n<span style=\"color: #408080;font-style: italic\">\/\/            Serial.println(\" \");<\/span>\r\n           \r\n            adresse<span style=\"color: #666666\">=<\/span>DATEN[<span style=\"color: #666666\">0<\/span>]; \r\n            busstatus<span style=\"color: #666666\">=<\/span>DATEN[<span style=\"color: #666666\">1<\/span>];\r\n           \r\n            <span style=\"color: #008000;font-weight: bold\">if<\/span>(busstatus <span style=\"color: #666666\">==<\/span> <span style=\"color: #666666\">0<\/span>)       {sensorbelegt<span style=\"color: #666666\">=<\/span><span style=\"color: #008000\">false<\/span>;  ledsensoron<span style=\"color: #666666\">=<\/span><span style=\"color: #008000\">false<\/span>;}\r\n            <span style=\"color: #008000;font-weight: bold\">else<\/span> <span style=\"color: #008000;font-weight: bold\">if<\/span> (busstatus <span style=\"color: #666666\">==<\/span> <span style=\"color: #666666\">1<\/span>) {sensorbelegt<span style=\"color: #666666\">=<\/span><span style=\"color: #008000\">false<\/span>;  ledsensoron<span style=\"color: #666666\">=<\/span><span style=\"color: #008000\">true<\/span>;}\r\n            <span style=\"color: #008000;font-weight: bold\">else<\/span> <span style=\"color: #008000;font-weight: bold\">if<\/span> (busstatus <span style=\"color: #666666\">==<\/span> <span style=\"color: #666666\">2<\/span>) {sensorbelegt<span style=\"color: #666666\">=<\/span><span style=\"color: #008000\">true<\/span>;  ledsensoron<span style=\"color: #666666\">=<\/span><span style=\"color: #008000\">false<\/span>;}\r\n            <span style=\"color: #008000;font-weight: bold\">else<\/span> <span style=\"color: #008000;font-weight: bold\">if<\/span> (busstatus <span style=\"color: #666666\">==<\/span> <span style=\"color: #666666\">3<\/span>) {sensorbelegt<span style=\"color: #666666\">=<\/span><span style=\"color: #008000\">true<\/span>;  ledsensoron<span style=\"color: #666666\">=<\/span><span style=\"color: #008000\">true<\/span>;}\r\n      \r\n         <span style=\"color: #408080;font-style: italic\">\/\/################################################################################################<\/span>\r\n         <span style=\"color: #408080;font-style: italic\">\/\/Testbutton Status lesen und variable testbut entsprechend setzen<\/span>\r\n       \r\n          buttonState <span style=\"color: #666666\">=<\/span> digitalRead(buttonPin);               <span style=\"color: #408080;font-style: italic\">\/\/tastereingang einlesen<\/span>\r\n          <span style=\"color: #008000;font-weight: bold\">if<\/span>(buttonState <span style=\"color: #666666\">==<\/span> HIGH){                            <span style=\"color: #408080;font-style: italic\">\/\/wenn taster aktiv dann variable anim setzen<\/span>\r\n          anim <span style=\"color: #666666\">=<\/span> <span style=\"color: #666666\">1<\/span>;\r\n          <span style=\"color: #408080;font-style: italic\">\/\/delay(5); <\/span>\r\n          }\r\n            \r\n<span style=\"color: #408080;font-style: italic\">\/\/            \/\/debug debuginfo tasterstatus auf rs232 ausgeben<\/span>\r\n<span style=\"color: #408080;font-style: italic\">\/\/            Serial.println(\"#######################\");<\/span>\r\n<span style=\"color: #408080;font-style: italic\">\/\/            Serial.print(\"Knoten Adresse    :\");<\/span>\r\n<span style=\"color: #408080;font-style: italic\">\/\/            Serial.println(adresse);<\/span>\r\n<span style=\"color: #408080;font-style: italic\">\/\/            Serial.print(\"Busstatus         :\");<\/span>\r\n<span style=\"color: #408080;font-style: italic\">\/\/            Serial.println(busstatus);<\/span>\r\n<span style=\"color: #408080;font-style: italic\">\/\/            <\/span>\r\n<span style=\"color: #408080;font-style: italic\">\/\/            Serial.println(\"----------------\");<\/span>\r\n<span style=\"color: #408080;font-style: italic\">\/\/            Serial.print(\"Fliese belegt    :\");<\/span>\r\n<span style=\"color: #408080;font-style: italic\">\/\/            Serial.println(sensorbelegt);<\/span>\r\n<span style=\"color: #408080;font-style: italic\">\/\/            Serial.print(\"LED Fliese       :\");<\/span>\r\n<span style=\"color: #408080;font-style: italic\">\/\/            Serial.println(ledsensoron);<\/span>\r\n<span style=\"color: #408080;font-style: italic\">\/\/            Serial.print(\"#######################\");<\/span>\r\n<span style=\"color: #408080;font-style: italic\">\/\/            Serial.println(\" \");<\/span>\r\n      \r\n          <span style=\"color: #408080;font-style: italic\">\/\/################################################################################################<\/span>\r\n          <span style=\"color: #408080;font-style: italic\">\/\/Testbutton Status an jeweiligen knoten senden<\/span>\r\n      \r\n          Wire.beginTransmission(Knotenadresse);           <span style=\"color: #408080;font-style: italic\">\/\/ transmit to device actual in for loop<\/span>\r\n          <span style=\"color: #408080;font-style: italic\">\/\/anim schreiben<\/span>\r\n                    \r\n           <span style=\"color: #008000;font-weight: bold\">if<\/span> (anim<span style=\"color: #666666\">==0<\/span>) {testbut<span style=\"color: #666666\">=<\/span>leddat1[j]; j<span style=\"color: #666666\">++<\/span>;}\r\n                   <span style=\"color: #008000;font-weight: bold\">else<\/span> {testbut<span style=\"color: #666666\">=<\/span>leddat2[j]; j<span style=\"color: #666666\">++<\/span>;}\r\n           <span style=\"color: #008000;font-weight: bold\">if<\/span> (j<span style=\"color: #666666\">&gt;8<\/span>){j<span style=\"color: #666666\">=0<\/span>;}\r\n          \r\n          Wire.write(testbut);                             <span style=\"color: #408080;font-style: italic\">\/\/ senden des tasterstatus<\/span>\r\n          Wire.endTransmission();                          <span style=\"color: #408080;font-style: italic\">\/\/ ende gel\u00e4nde mit uerbertragung<\/span>\r\n       \r\n          delay(DELAY);\r\n          \r\n\r\n    }\r\n   \r\n}\r\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">With this arrangement, it is now possible to read all Arduinos and their input or to control the LED via the bus. In the next step, a &#8222;sensor&#8220; is built, a board is laid out and the ArduinoUno reduced to its microcontroller. I&#8217;ll talk about that in one of the next posts &#8230;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_6390\" class=\"pvc_stats all  \" data-element-id=\"6390\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/blog.fh-kaernten.at\/ingmarsretro\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n<p>Unfortunately, the intervals in which I find some time to write a new post for the blog have not gotten shorter. But post a post per month, I think &#8230; \ud83d\ude42 This time it&#8217;s not a retro craft project from the local Gefielden or a restoration of an old device, but again something about Arduino.&hellip; <br \/> <a class=\"read-more\" href=\"https:\/\/blog.fh-kaernten.at\/ingmarsretro\/2021\/04\/14\/data-node-with-arduino\/?lang=en\">Weiterlesen<\/a><\/p>\n","protected":false},"author":86,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"ngg_post_thumbnail":0,"footnotes":""},"categories":[1592,1506],"tags":[1914,1925,1911,1913,1918,1921,1923,1924,1928,1920,1927,1926,1919,1912,1828,1922,1916,1917,1915],"class_list":["post-6390","post","type-post","status-publish","format-standard","hentry","category-arduino-en","category-electronics-hobbyist","tag-arduino-en","tag-arduino-projects","tag-arduino-uno-en","tag-atmega-en","tag-atmel-en","tag-databus","tag-development-environment","tag-electronicsprojects","tag-grid-en","tag-ic-en","tag-industry5-0","tag-iot-en","tag-joy-it-uno-en","tag-labview-en","tag-matlab-en","tag-microcontroller-en","tag-sensor-network","tag-sensor-node","tag-sensors"],"a3_pvc":{"activated":true,"total_views":64,"today_views":1},"_links":{"self":[{"href":"https:\/\/blog.fh-kaernten.at\/ingmarsretro\/wp-json\/wp\/v2\/posts\/6390","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.fh-kaernten.at\/ingmarsretro\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.fh-kaernten.at\/ingmarsretro\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.fh-kaernten.at\/ingmarsretro\/wp-json\/wp\/v2\/users\/86"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.fh-kaernten.at\/ingmarsretro\/wp-json\/wp\/v2\/comments?post=6390"}],"version-history":[{"count":0,"href":"https:\/\/blog.fh-kaernten.at\/ingmarsretro\/wp-json\/wp\/v2\/posts\/6390\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.fh-kaernten.at\/ingmarsretro\/wp-json\/wp\/v2\/media?parent=6390"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.fh-kaernten.at\/ingmarsretro\/wp-json\/wp\/v2\/categories?post=6390"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.fh-kaernten.at\/ingmarsretro\/wp-json\/wp\/v2\/tags?post=6390"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}