{"id":1294,"date":"2016-10-04T16:33:10","date_gmt":"2016-10-04T16:33:10","guid":{"rendered":"http:\/\/www.horter.de\/blog\/?p=1294"},"modified":"2023-01-13T15:32:03","modified_gmt":"2023-01-13T15:32:03","slug":"code-fuer-c-i2c-di-und-i2c-do","status":"publish","type":"post","link":"https:\/\/www.horter.de\/blog\/code-fuer-c-i2c-di-und-i2c-do\/","title":{"rendered":"C++ Code f\u00fcr digitale I2C-Baugruppen"},"content":{"rendered":"<p>den Code hat Andreas P. freundlicherweise zur Verf\u00fcgung gestellt.<\/p>\n<blockquote><p>Ich habe zur Ansteuerung der Bausteine Digital Input und Digital Output ein kleine Demo in C++ f\u00fcr den PI geschrieben.<\/p>\n<p>Auf <a href=\"http:\/\/www.netzmafia.de\/skripten\/hardware\/RasPi\/RasPi_I2C.html\">http:\/\/www.netzmafia.de\/skripten\/hardware\/RasPi\/RasPi_I2C.html<\/a> gibt es eine gute Beschreibung zur Installation der Device Treiber und der Development Header f\u00fcr i2c.<\/p>\n<p>Danach m\u00fcssen nur mehr die Adressen f\u00fcr die Bausteine (Zeile 21 und 22 in ft.cxx im Anhang)<\/p>\n<p>const int DEF_IN = 0x38;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ addr digital Input device<\/p>\n<p>const int DEF_OUT = 0x23;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ addr digital Output device<\/p>\n<p>angepasst und das Programm mit g++ -Wall -O -o ft ft.cxx Compiliert werden.<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<p>Download ft.cxx als zip-Datei<br \/>\n<a  data-e-Disable-Page-Transition=\"true\" class=\"download-link\" title=\"\" href=\"https:\/\/www.horter.de\/blog\/download\/1302\/?tmstv=1777575833\" rel=\"nofollow\" id=\"download-link-1302\" data-redirect=\"false\" >\n\tC++ Code f\u00fcr I2C-DI und I2C-DO Baugruppen\t(2774 Downloads\t)\n<\/a>\n<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"cpp\" style=\"font-family: monospace;\"><span style=\"color: #339900;\">#include &lt;bitset&gt;<\/span>\r\n<span style=\"color: #339900;\">#include &lt;errno.h&gt;<\/span>\r\n<span style=\"color: #339900;\">#include &lt;stdio.h&gt;<\/span>\r\n<span style=\"color: #339900;\">#include &lt;iostream&gt;<\/span>\r\n<span style=\"color: #339900;\">#include &lt;stdlib.h&gt;<\/span>\r\n<span style=\"color: #339900;\">#include &lt;unistd.h&gt;<\/span>\r\n<span style=\"color: #339900;\">#include &lt;fcntl.h&gt;<\/span>\r\n<span style=\"color: #339900;\">#include &lt;string.h&gt;<\/span>\r\n<span style=\"color: #339900;\">#include &lt;sys\/stat.h&gt;<\/span>\r\n<span style=\"color: #339900;\">#include &lt;sys\/ioctl.h&gt;<\/span>\r\n<span style=\"color: #339900;\">#include &lt;sys\/types.h&gt;<\/span>\r\n<span style=\"color: #339900;\">#include &lt;linux\/i2c-dev.h&gt;<\/span>\r\n\u00a0\r\n<span style=\"color: #666666;\">\/\/ ------------------------------------------------------------------<\/span>\r\n<span style=\"color: #666666;\">\/\/ I2C-Userspace Driver:<\/span>\r\n<span style=\"color: #666666;\">\/\/ Compile: g++ -Wall -O -o ft ft.cxx<\/span>\r\n<span style=\"color: #666666;\">\/\/ ------------------------------------------------------------------<\/span>\r\n<span style=\"color: #0000ff;\">const<\/span> <span style=\"color: #0000ff;\">int<\/span> SET <span style=\"color: #000080;\">=<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #008080;\">;<\/span>\r\n<span style=\"color: #0000ff;\">const<\/span> <span style=\"color: #0000ff;\">int<\/span> CLEAR <span style=\"color: #000080;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #008080;\">;<\/span>\r\n\u00a0\r\n<span style=\"color: #0000ff;\">const<\/span> <span style=\"color: #0000ff;\">int<\/span> DEF_IN <span style=\"color: #000080;\">=<\/span> <span style=\"color: #208080;\">0x38<\/span><span style=\"color: #008080;\">;<\/span>            <span style=\"color: #666666;\">\/\/ addr digital Input device<\/span>\r\n<span style=\"color: #0000ff;\">const<\/span> <span style=\"color: #0000ff;\">int<\/span> DEF_OUT <span style=\"color: #000080;\">=<\/span> <span style=\"color: #208080;\">0x23<\/span><span style=\"color: #008080;\">;<\/span>           <span style=\"color: #666666;\">\/\/ addr digital Output device<\/span>\r\n<span style=\"color: #0000ff;\">const<\/span> <span style=\"color: #0000ff;\">size_t<\/span> BUFSIZE  <span style=\"color: #000080;\">=<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #008080;\">;<\/span>          <span style=\"color: #666666;\">\/\/ data buffer size for both 8bit<\/span>\r\n<span style=\"color: #0000ff;\">const<\/span> <span style=\"color: #0000ff;\">char<\/span> <span style=\"color: #000040;\">*<\/span>I2CADDR <span style=\"color: #000080;\">=<\/span> <span style=\"color: #ff0000;\">\"\/dev\/i2c-1\"<\/span><span style=\"color: #008080;\">;<\/span> <span style=\"color: #666666;\">\/\/ I2C device<\/span>\r\n\u00a0\r\n<span style=\"color: #666666;\">\/\/ ------------------------------------------------------------------<\/span>\r\n<span style=\"color: #666666;\">\/\/ -- C++ Wrapper to communicate with a I2C device.<\/span>\r\n<span style=\"color: #666666;\">\/\/ -- In case of errors messages are witten to stderr<\/span>\r\n<span style=\"color: #666666;\">\/\/ ------------------------------------------------------------------<\/span>\r\n<span style=\"color: #0000ff;\">class<\/span> I2cDevice\r\n<span style=\"color: #008000;\">{<\/span>\r\n<span style=\"color: #0000ff;\">public<\/span><span style=\"color: #008080;\">:<\/span>\r\n  <span style=\"color: #ff0000; font-style: italic;\">\/** opens a channel to the device and initiates communication\r\n    * with a device at the given addr.\r\n    * @param name... a user friendly name only used in log output\r\n    * @param addr... the addr of the I2C device\r\n    *\/<\/span>\r\n  I2cDevice<span style=\"color: #008000;\">(<\/span><span style=\"color: #0000ff;\">const<\/span> <span style=\"color: #0000ff;\">char<\/span> <span style=\"color: #000040;\">*<\/span>name, <span style=\"color: #0000ff;\">int<\/span> addr<span style=\"color: #008000;\">)<\/span><span style=\"color: #008080;\">;<\/span>\r\n\u00a0\r\n  <span style=\"color: #666666;\">\/\/\/closes the channel to the device<\/span>\r\n  ~I2cDevice<span style=\"color: #008000;\">(<\/span><span style=\"color: #008000;\">)<\/span><span style=\"color: #008080;\">;<\/span>\r\n\u00a0\r\n<span style=\"color: #0000ff;\">public<\/span><span style=\"color: #008080;\">:<\/span>\r\n  <span style=\"color: #666666;\">\/\/\/ @returns true if the device was initialized succesfully, else false<\/span>\r\n  <span style=\"color: #0000ff;\">bool<\/span> ok<span style=\"color: #008000;\">(<\/span><span style=\"color: #008000;\">)<\/span> <span style=\"color: #008000;\">{<\/span> <span style=\"color: #0000ff;\">return<\/span><span style=\"color: #008000;\">(<\/span>dev_ <span style=\"color: #000080;\">&gt;<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #008000;\">)<\/span><span style=\"color: #008080;\">;<\/span> <span style=\"color: #008000;\">}<\/span>\r\n\u00a0\r\n  <span style=\"color: #ff0000; font-style: italic;\">\/** reads a byte from the device and writes the result to stdout.\r\n    * @param label... a text printed in front of the value.\r\n    *                 e.g. old value\r\n    *\/<\/span>\r\n  <span style=\"color: #0000ff;\">unsigned<\/span> <span style=\"color: #0000ff;\">char<\/span> read<span style=\"color: #008000;\">(<\/span><span style=\"color: #0000ff;\">const<\/span> <span style=\"color: #0000ff;\">char<\/span> <span style=\"color: #000040;\">*<\/span>label<span style=\"color: #008000;\">)<\/span><span style=\"color: #008080;\">;<\/span>\r\n\u00a0\r\n  <span style=\"color: #ff0000; font-style: italic;\">\/** writes a byte to the device.\r\n    * @param data... the value.\r\n    *\/<\/span>\r\n  <span style=\"color: #0000ff;\">unsigned<\/span> <span style=\"color: #0000ff;\">char<\/span> write<span style=\"color: #008000;\">(<\/span><span style=\"color: #0000ff;\">unsigned<\/span> <span style=\"color: #0000ff;\">char<\/span> data<span style=\"color: #008000;\">)<\/span><span style=\"color: #008080;\">;<\/span>\r\n\u00a0\r\n  <span style=\"color: #ff0000; font-style: italic;\">\/** set \/ clear a bit on the device.\r\n    * this operation writes two lines to stdout\r\n    *      old value: &lt;value&gt;\r\n    *      new value: &lt;value&gt;\r\n    * @param op   ... SET \/ CLEAR.\r\n    * @param bitNo... the number ot the bit (1..8) to set \/ clear\r\n    *\/<\/span>\r\n  <span style=\"color: #0000ff;\">unsigned<\/span> <span style=\"color: #0000ff;\">char<\/span> write<span style=\"color: #008000;\">(<\/span><span style=\"color: #0000ff;\">int<\/span> op, <span style=\"color: #0000ff;\">unsigned<\/span> <span style=\"color: #0000ff;\">int<\/span> bitNo<span style=\"color: #008000;\">)<\/span><span style=\"color: #008080;\">;<\/span>\r\n\u00a0\r\n<span style=\"color: #0000ff;\">private<\/span><span style=\"color: #008080;\">:<\/span>\r\n  <span style=\"color: #0000ff;\">int<\/span> dev_<span style=\"color: #008080;\">;<\/span>\r\n  std<span style=\"color: #008080;\">::<\/span><span style=\"color: #007788;\">string<\/span> name_<span style=\"color: #008080;\">;<\/span>\r\n<span style=\"color: #008000;\">}<\/span><span style=\"color: #008080;\">;<\/span>\r\n\u00a0\r\n<span style=\"color: #666666;\">\/\/ ------------------------------------------------------------------<\/span>\r\n<span style=\"color: #666666;\">\/\/ --<\/span>\r\n<span style=\"color: #666666;\">\/\/ ------------------------------------------------------------------<\/span>\r\nI2cDevice<span style=\"color: #008080;\">::<\/span><span style=\"color: #007788;\">I2cDevice<\/span><span style=\"color: #008000;\">(<\/span><span style=\"color: #0000ff;\">const<\/span> <span style=\"color: #0000ff;\">char<\/span> <span style=\"color: #000040;\">*<\/span>name, <span style=\"color: #0000ff;\">int<\/span> addr<span style=\"color: #008000;\">)<\/span>\r\n<span style=\"color: #008080;\">:<\/span> name_<span style=\"color: #008000;\">(<\/span>name<span style=\"color: #008000;\">)<\/span>\r\n<span style=\"color: #008000;\">{<\/span>\r\n  <span style=\"color: #666666;\">\/\/ open a channel to the I2C device<\/span>\r\n  dev_ <span style=\"color: #000080;\">=<\/span> open<span style=\"color: #008000;\">(<\/span>I2CADDR, O_RDWR<span style=\"color: #008000;\">)<\/span><span style=\"color: #008080;\">;<\/span>\r\n\u00a0\r\n  <span style=\"color: #0000ff;\">if<\/span> <span style=\"color: #008000;\">(<\/span>dev_ <span style=\"color: #000080;\">&lt;<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #008000;\">)<\/span>\r\n  <span style=\"color: #008000;\">{<\/span>\r\n    std<span style=\"color: #008080;\">::<\/span><span style=\"color: #0000dd;\">cerr<\/span> <span style=\"color: #000080;\">&lt;&lt;<\/span> <span style=\"color: #ff0000;\">\"Could not load I2C-Module! \"<\/span>\r\n      <span style=\"color: #000080;\">&lt;&lt;<\/span> I2CADDR <span style=\"color: #000080;\">&lt;&lt;<\/span> <span style=\"color: #ff0000;\">\" \"<\/span>\r\n      <span style=\"color: #000080;\">&lt;&lt;<\/span> <span style=\"color: #0000dd;\">strerror<\/span><span style=\"color: #008000;\">(<\/span><span style=\"color: #0000ff;\">errno<\/span><span style=\"color: #008000;\">)<\/span> <span style=\"color: #000080;\">&lt;&lt;<\/span> std<span style=\"color: #008080;\">::<\/span><span style=\"color: #007788;\">endl<\/span><span style=\"color: #008080;\">;<\/span>\r\n  <span style=\"color: #008000;\">}<\/span>\r\n  <span style=\"color: #0000ff;\">else<\/span>\r\n  <span style=\"color: #008000;\">{<\/span>\r\n    <span style=\"color: #666666;\">\/\/ bind channel to the given addr<\/span>\r\n    <span style=\"color: #0000ff;\">if<\/span> <span style=\"color: #008000;\">(<\/span>ioctl<span style=\"color: #008000;\">(<\/span>dev_, I2C_SLAVE, addr<span style=\"color: #008000;\">)<\/span> <span style=\"color: #000080;\">&lt;<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #008000;\">)<\/span>\r\n    <span style=\"color: #008000;\">{<\/span>\r\n      std<span style=\"color: #008080;\">::<\/span><span style=\"color: #0000dd;\">cerr<\/span> <span style=\"color: #000080;\">&lt;&lt;<\/span> name_.<span style=\"color: #007788;\">c_str<\/span><span style=\"color: #008000;\">(<\/span><span style=\"color: #008000;\">)<\/span>\r\n        <span style=\"color: #000080;\">&lt;&lt;<\/span> <span style=\"color: #ff0000;\">\" addr: 0x\"<\/span> <span style=\"color: #000080;\">&lt;&lt;<\/span> std<span style=\"color: #008080;\">::<\/span><span style=\"color: #007788;\">hex<\/span> <span style=\"color: #000080;\">&lt;&lt;<\/span> addr <span style=\"color: #000080;\">&lt;&lt;<\/span> std<span style=\"color: #008080;\">::<\/span><span style=\"color: #007788;\">dec<\/span>\r\n        <span style=\"color: #000080;\">&lt;&lt;<\/span> <span style=\"color: #ff0000;\">\" error: \"<\/span> <span style=\"color: #000080;\">&lt;&lt;<\/span> <span style=\"color: #0000dd;\">strerror<\/span><span style=\"color: #008000;\">(<\/span><span style=\"color: #0000ff;\">errno<\/span><span style=\"color: #008000;\">)<\/span> <span style=\"color: #000080;\">&lt;&lt;<\/span> std<span style=\"color: #008080;\">::<\/span><span style=\"color: #007788;\">endl<\/span><span style=\"color: #008080;\">;<\/span>\r\n    <span style=\"color: #008000;\">}<\/span>\r\n    <span style=\"color: #0000ff;\">else<\/span>\r\n    <span style=\"color: #008000;\">{<\/span>\r\n      std<span style=\"color: #008080;\">::<\/span><span style=\"color: #0000dd;\">cout<\/span> <span style=\"color: #000080;\">&lt;&lt;<\/span> <span style=\"color: #ff0000;\">\"Channel #\"<\/span> <span style=\"color: #000080;\">&lt;&lt;<\/span> dev_\r\n        <span style=\"color: #000080;\">&lt;&lt;<\/span> <span style=\"color: #ff0000;\">\" for \"<\/span> <span style=\"color: #000080;\">&lt;&lt;<\/span> name_.<span style=\"color: #007788;\">c_str<\/span><span style=\"color: #008000;\">(<\/span><span style=\"color: #008000;\">)<\/span>\r\n        <span style=\"color: #000080;\">&lt;&lt;<\/span> <span style=\"color: #ff0000;\">\"0x\"<\/span> <span style=\"color: #000080;\">&lt;&lt;<\/span> std<span style=\"color: #008080;\">::<\/span><span style=\"color: #007788;\">hex<\/span> <span style=\"color: #000080;\">&lt;&lt;<\/span> addr <span style=\"color: #000080;\">&lt;&lt;<\/span> std<span style=\"color: #008080;\">::<\/span><span style=\"color: #007788;\">dec<\/span>\r\n        <span style=\"color: #000080;\">&lt;&lt;<\/span> <span style=\"color: #ff0000;\">\" is open.\"<\/span> <span style=\"color: #000080;\">&lt;&lt;<\/span> std<span style=\"color: #008080;\">::<\/span><span style=\"color: #007788;\">endl<\/span><span style=\"color: #008080;\">;<\/span>\r\n    <span style=\"color: #008000;\">}<\/span>\r\n  <span style=\"color: #008000;\">}<\/span>\r\n<span style=\"color: #008000;\">}<\/span>\r\n\u00a0\r\n<span style=\"color: #666666;\">\/\/ ------------------------------------------------------------------<\/span>\r\n<span style=\"color: #666666;\">\/\/ --<\/span>\r\n<span style=\"color: #666666;\">\/\/ ------------------------------------------------------------------<\/span>\r\nI2cDevice<span style=\"color: #008080;\">::<\/span>~I2cDevice<span style=\"color: #008000;\">(<\/span><span style=\"color: #008000;\">)<\/span>\r\n<span style=\"color: #008000;\">{<\/span>\r\n  <span style=\"color: #0000ff;\">if<\/span> <span style=\"color: #008000;\">(<\/span>dev_ <span style=\"color: #000080;\">&gt;<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #008000;\">)<\/span>\r\n  <span style=\"color: #008000;\">{<\/span>\r\n    close<span style=\"color: #008000;\">(<\/span>dev_<span style=\"color: #008000;\">)<\/span><span style=\"color: #008080;\">;<\/span>\r\n    dev_ <span style=\"color: #000080;\">=<\/span> <span style=\"color: #000040;\">-<\/span><span style=\"color: #0000dd;\">1<\/span><span style=\"color: #008080;\">;<\/span>\r\n  <span style=\"color: #008000;\">}<\/span>\r\n<span style=\"color: #008000;\">}<\/span>\r\n\u00a0\r\n\u00a0\r\n<span style=\"color: #666666;\">\/\/ ------------------------------------------------------------------<\/span>\r\n<span style=\"color: #666666;\">\/\/ --<\/span>\r\n<span style=\"color: #666666;\">\/\/ ------------------------------------------------------------------<\/span>\r\n<span style=\"color: #0000ff;\">unsigned<\/span> <span style=\"color: #0000ff;\">char<\/span> I2cDevice<span style=\"color: #008080;\">::<\/span><span style=\"color: #007788;\">write<\/span><span style=\"color: #008000;\">(<\/span><span style=\"color: #0000ff;\">unsigned<\/span> <span style=\"color: #0000ff;\">char<\/span> data<span style=\"color: #008000;\">)<\/span>\r\n<span style=\"color: #008000;\">{<\/span>\r\n  <span style=\"color: #0000ff;\">if<\/span><span style=\"color: #008000;\">(<\/span><span style=\"color: #008080;\">::<\/span><span style=\"color: #007788;\">write<\/span><span style=\"color: #008000;\">(<\/span>dev_, <span style=\"color: #000040;\">&amp;<\/span>data, <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #008000;\">)<\/span> <span style=\"color: #000040;\">!<\/span><span style=\"color: #000080;\">=<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #008000;\">)<\/span>\r\n  <span style=\"color: #008000;\">{<\/span>\r\n    std<span style=\"color: #008080;\">::<\/span><span style=\"color: #0000dd;\">cerr<\/span> <span style=\"color: #000080;\">&lt;&lt;<\/span> <span style=\"color: #ff0000;\">\"Device \"<\/span> <span style=\"color: #000080;\">&lt;&lt;<\/span> name_.<span style=\"color: #007788;\">c_str<\/span><span style=\"color: #008000;\">(<\/span><span style=\"color: #008000;\">)<\/span>\r\n      <span style=\"color: #000080;\">&lt;&lt;<\/span> <span style=\"color: #ff0000;\">\" value: \"<\/span> <span style=\"color: #000080;\">&lt;&lt;<\/span> std<span style=\"color: #008080;\">::<\/span><span style=\"color: #007788;\">bitset<\/span><span style=\"color: #000080;\">&lt;<\/span><span style=\"color: #0000dd;\">8<\/span><span style=\"color: #000080;\">&gt;<\/span><span style=\"color: #008000;\">(<\/span>data<span style=\"color: #008000;\">)<\/span>\r\n      <span style=\"color: #000080;\">&lt;&lt;<\/span> <span style=\"color: #ff0000;\">\" write error: \"<\/span> <span style=\"color: #000080;\">&lt;&lt;<\/span> <span style=\"color: #0000dd;\">strerror<\/span><span style=\"color: #008000;\">(<\/span><span style=\"color: #0000ff;\">errno<\/span><span style=\"color: #008000;\">)<\/span> <span style=\"color: #000080;\">&lt;&lt;<\/span> std<span style=\"color: #008080;\">::<\/span><span style=\"color: #007788;\">endl<\/span><span style=\"color: #008080;\">;<\/span>\r\n  <span style=\"color: #008000;\">}<\/span>\r\n  <span style=\"color: #0000ff;\">else<\/span>\r\n  <span style=\"color: #008000;\">{<\/span>\r\n    std<span style=\"color: #008080;\">::<\/span><span style=\"color: #0000dd;\">cout<\/span> <span style=\"color: #000080;\">&lt;&lt;<\/span> <span style=\"color: #ff0000;\">\"new value: \"<\/span> <span style=\"color: #000080;\">&lt;&lt;<\/span> std<span style=\"color: #008080;\">::<\/span><span style=\"color: #007788;\">bitset<\/span><span style=\"color: #000080;\">&lt;<\/span><span style=\"color: #0000dd;\">8<\/span><span style=\"color: #000080;\">&gt;<\/span><span style=\"color: #008000;\">(<\/span>data<span style=\"color: #008000;\">)<\/span> <span style=\"color: #000080;\">&lt;&lt;<\/span> std<span style=\"color: #008080;\">::<\/span><span style=\"color: #007788;\">endl<\/span><span style=\"color: #008080;\">;<\/span>\r\n  <span style=\"color: #008000;\">}<\/span>\r\n\u00a0\r\n  <span style=\"color: #0000ff;\">return<\/span><span style=\"color: #008000;\">(<\/span>data<span style=\"color: #008000;\">)<\/span><span style=\"color: #008080;\">;<\/span>\r\n<span style=\"color: #008000;\">}<\/span>\r\n\u00a0\r\n\u00a0\r\n<span style=\"color: #666666;\">\/\/ ------------------------------------------------------------------<\/span>\r\n<span style=\"color: #666666;\">\/\/ --<\/span>\r\n<span style=\"color: #666666;\">\/\/ ------------------------------------------------------------------<\/span>\r\n<span style=\"color: #0000ff;\">unsigned<\/span> <span style=\"color: #0000ff;\">char<\/span> I2cDevice<span style=\"color: #008080;\">::<\/span><span style=\"color: #007788;\">write<\/span><span style=\"color: #008000;\">(<\/span><span style=\"color: #0000ff;\">int<\/span> op, <span style=\"color: #0000ff;\">unsigned<\/span> <span style=\"color: #0000ff;\">int<\/span> bitNo<span style=\"color: #008000;\">)<\/span>\r\n<span style=\"color: #008000;\">{<\/span>\r\n  <span style=\"color: #0000ff;\">unsigned<\/span> <span style=\"color: #0000ff;\">char<\/span>  mask <span style=\"color: #000080;\">=<\/span> <span style=\"color: #008000;\">(<\/span><span style=\"color: #0000ff;\">unsigned<\/span> <span style=\"color: #0000ff;\">char<\/span><span style=\"color: #008000;\">)<\/span><span style=\"color: #008000;\">(<\/span><span style=\"color: #0000dd;\">1<\/span> <span style=\"color: #000080;\">&lt;&lt;<\/span> <span style=\"color: #008000;\">(<\/span>bitNo <span style=\"color: #000040;\">-<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #008000;\">)<\/span><span style=\"color: #008000;\">)<\/span><span style=\"color: #008080;\">;<\/span>\r\n  <span style=\"color: #0000ff;\">unsigned<\/span> <span style=\"color: #0000ff;\">char<\/span> data <span style=\"color: #000080;\">=<\/span> read<span style=\"color: #008000;\">(<\/span><span style=\"color: #ff0000;\">\"old value: \"<\/span><span style=\"color: #008000;\">)<\/span><span style=\"color: #008080;\">;<\/span>\r\n\u00a0\r\n  <span style=\"color: #0000ff;\">if<\/span> <span style=\"color: #008000;\">(<\/span>op <span style=\"color: #000080;\">==<\/span> CLEAR<span style=\"color: #008000;\">)<\/span>\r\n    data <span style=\"color: #000080;\">=<\/span> data <span style=\"color: #000040;\">&amp;<\/span> <span style=\"color: #008000;\">(<\/span>~mask<span style=\"color: #008000;\">)<\/span><span style=\"color: #008080;\">;<\/span>\r\n  <span style=\"color: #0000ff;\">else<\/span>\r\n    data <span style=\"color: #000080;\">=<\/span> data <span style=\"color: #000040;\">|<\/span> mask<span style=\"color: #008080;\">;<\/span>\r\n\u00a0\r\n  <span style=\"color: #0000ff;\">return<\/span><span style=\"color: #008000;\">(<\/span>write<span style=\"color: #008000;\">(<\/span>data<span style=\"color: #008000;\">)<\/span><span style=\"color: #008000;\">)<\/span><span style=\"color: #008080;\">;<\/span>\r\n<span style=\"color: #008000;\">}<\/span>\r\n\u00a0\r\n\u00a0\r\n<span style=\"color: #666666;\">\/\/ ------------------------------------------------------------------<\/span>\r\n<span style=\"color: #666666;\">\/\/ --<\/span>\r\n<span style=\"color: #666666;\">\/\/ ------------------------------------------------------------------<\/span>\r\n<span style=\"color: #0000ff;\">unsigned<\/span> <span style=\"color: #0000ff;\">char<\/span> I2cDevice<span style=\"color: #008080;\">::<\/span><span style=\"color: #007788;\">read<\/span><span style=\"color: #008000;\">(<\/span><span style=\"color: #0000ff;\">const<\/span> <span style=\"color: #0000ff;\">char<\/span> <span style=\"color: #000040;\">*<\/span>label<span style=\"color: #008000;\">)<\/span>\r\n<span style=\"color: #008000;\">{<\/span>\r\n  <span style=\"color: #0000ff;\">char<\/span> data <span style=\"color: #000080;\">=<\/span> <span style=\"color: #ff0000;\">'<span style=\"color: #006699; font-weight: bold;\">\\0<\/span>'<\/span><span style=\"color: #008080;\">;<\/span>\r\n  <span style=\"color: #0000ff;\">if<\/span> <span style=\"color: #008000;\">(<\/span><span style=\"color: #008080;\">::<\/span><span style=\"color: #007788;\">read<\/span><span style=\"color: #008000;\">(<\/span>dev_, <span style=\"color: #000040;\">&amp;<\/span>data, <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #008000;\">)<\/span> <span style=\"color: #000040;\">!<\/span><span style=\"color: #000080;\">=<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #008000;\">)<\/span>\r\n  <span style=\"color: #008000;\">{<\/span>\r\n    std<span style=\"color: #008080;\">::<\/span><span style=\"color: #0000dd;\">cerr<\/span> <span style=\"color: #000080;\">&lt;&lt;<\/span> <span style=\"color: #ff0000;\">\"Device \"<\/span> <span style=\"color: #000080;\">&lt;&lt;<\/span> name_.<span style=\"color: #007788;\">c_str<\/span><span style=\"color: #008000;\">(<\/span><span style=\"color: #008000;\">)<\/span>\r\n      <span style=\"color: #000080;\">&lt;&lt;<\/span> <span style=\"color: #ff0000;\">\" value: \"<\/span> <span style=\"color: #000080;\">&lt;&lt;<\/span> std<span style=\"color: #008080;\">::<\/span><span style=\"color: #007788;\">bitset<\/span><span style=\"color: #000080;\">&lt;<\/span><span style=\"color: #0000dd;\">8<\/span><span style=\"color: #000080;\">&gt;<\/span><span style=\"color: #008000;\">(<\/span>data<span style=\"color: #008000;\">)<\/span>\r\n      <span style=\"color: #000080;\">&lt;&lt;<\/span> <span style=\"color: #ff0000;\">\" read error: \"<\/span> <span style=\"color: #000080;\">&lt;&lt;<\/span> <span style=\"color: #0000dd;\">strerror<\/span><span style=\"color: #008000;\">(<\/span><span style=\"color: #0000ff;\">errno<\/span><span style=\"color: #008000;\">)<\/span> <span style=\"color: #000080;\">&lt;&lt;<\/span> std<span style=\"color: #008080;\">::<\/span><span style=\"color: #007788;\">endl<\/span><span style=\"color: #008080;\">;<\/span>\r\n  <span style=\"color: #008000;\">}<\/span>\r\n  <span style=\"color: #0000ff;\">else<\/span>\r\n  <span style=\"color: #008000;\">{<\/span>\r\n    std<span style=\"color: #008080;\">::<\/span><span style=\"color: #0000dd;\">cout<\/span> <span style=\"color: #000080;\">&lt;&lt;<\/span> label <span style=\"color: #000080;\">&lt;&lt;<\/span> std<span style=\"color: #008080;\">::<\/span><span style=\"color: #007788;\">bitset<\/span><span style=\"color: #000080;\">&lt;<\/span><span style=\"color: #0000dd;\">8<\/span><span style=\"color: #000080;\">&gt;<\/span><span style=\"color: #008000;\">(<\/span>~data<span style=\"color: #008000;\">)<\/span> <span style=\"color: #000080;\">&lt;&lt;<\/span> std<span style=\"color: #008080;\">::<\/span><span style=\"color: #007788;\">endl<\/span><span style=\"color: #008080;\">;<\/span>\r\n  <span style=\"color: #008000;\">}<\/span>\r\n  <span style=\"color: #0000ff;\">return<\/span><span style=\"color: #008000;\">(<\/span>data<span style=\"color: #008000;\">)<\/span><span style=\"color: #008080;\">;<\/span>\r\n<span style=\"color: #008000;\">}<\/span>\r\n\u00a0\r\n\u00a0\r\n<span style=\"color: #666666;\">\/\/ ------------------------------------------------------------------<\/span>\r\n<span style=\"color: #666666;\">\/\/ -- write a menue an read the user input<\/span>\r\n<span style=\"color: #666666;\">\/\/ ------------------------------------------------------------------<\/span>\r\n<span style=\"color: #0000ff;\">static<\/span> <span style=\"color: #0000ff;\">char<\/span> getCommand<span style=\"color: #008000;\">(<\/span><span style=\"color: #0000ff;\">unsigned<\/span> <span style=\"color: #0000ff;\">int<\/span> <span style=\"color: #000040;\">&amp;<\/span>bitNo<span style=\"color: #008000;\">)<\/span>\r\n<span style=\"color: #008000;\">{<\/span>\r\n  std<span style=\"color: #008080;\">::<\/span><span style=\"color: #0000dd;\">cout<\/span> <span style=\"color: #000080;\">&lt;&lt;<\/span> <span style=\"color: #ff0000;\">\"<span style=\"color: #000099; font-weight: bold;\">\\n<\/span>\"<\/span>\r\n    <span style=\"color: #000080;\">&lt;&lt;<\/span> <span style=\"color: #ff0000;\">\"<span style=\"color: #000099; font-weight: bold;\">\\n<\/span>  r... Read inputs \"<\/span>\r\n    <span style=\"color: #000080;\">&lt;&lt;<\/span> <span style=\"color: #ff0000;\">\"<span style=\"color: #000099; font-weight: bold;\">\\n<\/span>  s... Set output bit &lt;n&gt;   z.B. s 3\"<\/span>\r\n    <span style=\"color: #000080;\">&lt;&lt;<\/span> <span style=\"color: #ff0000;\">\"<span style=\"color: #000099; font-weight: bold;\">\\n<\/span>  c... Clear Output bit &lt;n&gt; z.B. c 5\"<\/span>\r\n    <span style=\"color: #000080;\">&lt;&lt;<\/span> <span style=\"color: #ff0000;\">\"<span style=\"color: #000099; font-weight: bold;\">\\n<\/span>  ----------------------------------\"<\/span>\r\n    <span style=\"color: #000080;\">&lt;&lt;<\/span> <span style=\"color: #ff0000;\">\"<span style=\"color: #000099; font-weight: bold;\">\\n<\/span>  e... Exit \"<\/span>\r\n    <span style=\"color: #000080;\">&lt;&lt;<\/span> std<span style=\"color: #008080;\">::<\/span> <span style=\"color: #007788;\">endl<\/span><span style=\"color: #008080;\">;<\/span>\r\n\u00a0\r\n  <span style=\"color: #0000ff;\">char<\/span> cmd<span style=\"color: #008080;\">;<\/span>\r\n  <span style=\"color: #0000dd;\">scanf<\/span><span style=\"color: #008000;\">(<\/span><span style=\"color: #ff0000;\">\"%c\"<\/span>, <span style=\"color: #000040;\">&amp;<\/span>cmd<span style=\"color: #008000;\">)<\/span><span style=\"color: #008080;\">;<\/span>\r\n  <span style=\"color: #0000ff;\">if<\/span> <span style=\"color: #008000;\">(<\/span>cmd <span style=\"color: #000080;\">==<\/span> <span style=\"color: #ff0000;\">'s'<\/span> <span style=\"color: #000040;\">||<\/span> cmd <span style=\"color: #000080;\">==<\/span> <span style=\"color: #ff0000;\">'c'<\/span><span style=\"color: #008000;\">)<\/span>\r\n  <span style=\"color: #008000;\">{<\/span>\r\n    <span style=\"color: #0000dd;\">scanf<\/span><span style=\"color: #008000;\">(<\/span><span style=\"color: #ff0000;\">\"%d\"<\/span>, <span style=\"color: #000040;\">&amp;<\/span>bitNo<span style=\"color: #008000;\">)<\/span><span style=\"color: #008080;\">;<\/span>\r\n  <span style=\"color: #008000;\">}<\/span>\r\n\u00a0\r\n  <span style=\"color: #0000ff;\">char<\/span> dummy<span style=\"color: #008080;\">;<\/span>\r\n  <span style=\"color: #0000dd;\">scanf<\/span><span style=\"color: #008000;\">(<\/span><span style=\"color: #ff0000;\">\"%c\"<\/span>, <span style=\"color: #000040;\">&amp;<\/span>dummy<span style=\"color: #008000;\">)<\/span><span style=\"color: #008080;\">;<\/span>\r\n\u00a0\r\n  <span style=\"color: #0000ff;\">return<\/span><span style=\"color: #008000;\">(<\/span>cmd<span style=\"color: #008000;\">)<\/span><span style=\"color: #008080;\">;<\/span>\r\n<span style=\"color: #008000;\">}<\/span>\r\n\u00a0\r\n<span style=\"color: #666666;\">\/\/ ==================================================================<\/span>\r\n<span style=\"color: #666666;\">\/\/ ==================================================================<\/span>\r\n<span style=\"color: #666666;\">\/\/ ==================================================================<\/span>\r\n<span style=\"color: #0000ff;\">int<\/span> main<span style=\"color: #008000;\">(<\/span><span style=\"color: #008000;\">)<\/span>\r\n<span style=\"color: #008000;\">{<\/span>\r\n  <span style=\"color: #666666;\">\/\/ this example communicates to two I2C devices<\/span>\r\n  I2cDevice dIn<span style=\"color: #008000;\">(<\/span><span style=\"color: #ff0000;\">\"Digital Input\"<\/span>, DEF_IN<span style=\"color: #008000;\">)<\/span><span style=\"color: #008080;\">;<\/span>\r\n  I2cDevice dOut<span style=\"color: #008000;\">(<\/span><span style=\"color: #ff0000;\">\"Digital Output\"<\/span>, DEF_OUT<span style=\"color: #008000;\">)<\/span><span style=\"color: #008080;\">;<\/span>\r\n\u00a0\r\n  dIn.<span style=\"color: #007788;\">write<\/span><span style=\"color: #008000;\">(<\/span><span style=\"color: #208080;\">0xff<\/span><span style=\"color: #008000;\">)<\/span><span style=\"color: #008080;\">;<\/span>           <span style=\"color: #666666;\">\/\/ set all inputs to active<\/span>\r\n\u00a0\r\n  <span style=\"color: #0000ff;\">if<\/span> <span style=\"color: #008000;\">(<\/span>dIn.<span style=\"color: #007788;\">ok<\/span><span style=\"color: #008000;\">(<\/span><span style=\"color: #008000;\">)<\/span> <span style=\"color: #000040;\">&amp;&amp;<\/span> dOut.<span style=\"color: #007788;\">ok<\/span><span style=\"color: #008000;\">(<\/span><span style=\"color: #008000;\">)<\/span><span style=\"color: #008000;\">)<\/span> <span style=\"color: #666666;\">\/\/ check if communication is established<\/span>\r\n  <span style=\"color: #008000;\">{<\/span>\r\n    <span style=\"color: #0000ff;\">char<\/span> cmd <span style=\"color: #000080;\">=<\/span> <span style=\"color: #ff0000;\">' '<\/span><span style=\"color: #008080;\">;<\/span>\r\n    <span style=\"color: #0000ff;\">do<\/span>\r\n    <span style=\"color: #008000;\">{<\/span>\r\n      <span style=\"color: #0000ff;\">unsigned<\/span> <span style=\"color: #0000ff;\">int<\/span> bitNo<span style=\"color: #008080;\">;<\/span>\r\n      cmd <span style=\"color: #000080;\">=<\/span> getCommand<span style=\"color: #008000;\">(<\/span>bitNo<span style=\"color: #008000;\">)<\/span><span style=\"color: #008080;\">;<\/span>  <span style=\"color: #666666;\">\/\/ write menue and get user input<\/span>\r\n\u00a0\r\n                                <span style=\"color: #666666;\">\/\/ execute the users input<\/span>\r\n      <span style=\"color: #0000ff;\">switch<\/span><span style=\"color: #008000;\">(<\/span>cmd<span style=\"color: #008000;\">)<\/span>\r\n      <span style=\"color: #008000;\">{<\/span>\r\n      <span style=\"color: #0000ff;\">case<\/span> <span style=\"color: #ff0000;\">'r'<\/span><span style=\"color: #008080;\">:<\/span>  dIn.<span style=\"color: #007788;\">read<\/span><span style=\"color: #008000;\">(<\/span><span style=\"color: #ff0000;\">\"Inputs: \"<\/span><span style=\"color: #008000;\">)<\/span><span style=\"color: #008080;\">;<\/span> <span style=\"color: #0000ff;\">break<\/span><span style=\"color: #008080;\">;<\/span>\r\n      <span style=\"color: #0000ff;\">case<\/span> <span style=\"color: #ff0000;\">'s'<\/span><span style=\"color: #008080;\">:<\/span>  dOut.<span style=\"color: #007788;\">write<\/span><span style=\"color: #008000;\">(<\/span>SET, bitNo<span style=\"color: #008000;\">)<\/span><span style=\"color: #008080;\">;<\/span> <span style=\"color: #0000ff;\">break<\/span><span style=\"color: #008080;\">;<\/span>\r\n      <span style=\"color: #0000ff;\">case<\/span> <span style=\"color: #ff0000;\">'c'<\/span><span style=\"color: #008080;\">:<\/span>  dOut.<span style=\"color: #007788;\">write<\/span><span style=\"color: #008000;\">(<\/span>CLEAR, bitNo<span style=\"color: #008000;\">)<\/span><span style=\"color: #008080;\">;<\/span> <span style=\"color: #0000ff;\">break<\/span><span style=\"color: #008080;\">;<\/span>\r\n      <span style=\"color: #0000ff;\">default<\/span> <span style=\"color: #008080;\">:<\/span>  <span style=\"color: #0000ff;\">break<\/span><span style=\"color: #008080;\">;<\/span>\r\n      <span style=\"color: #008000;\">}<\/span>\r\n\u00a0\r\n    <span style=\"color: #008000;\">}<\/span>\r\n    <span style=\"color: #0000ff;\">while<\/span> <span style=\"color: #008000;\">(<\/span>cmd <span style=\"color: #000040;\">!<\/span><span style=\"color: #000080;\">=<\/span> <span style=\"color: #ff0000;\">'e'<\/span><span style=\"color: #008000;\">)<\/span><span style=\"color: #008080;\">;<\/span>         <span style=\"color: #666666;\">\/\/ leave if the user pressed e<\/span>\r\n\u00a0\r\n  <span style=\"color: #008000;\">}<\/span>\r\n<span style=\"color: #008000;\">}<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>den Code hat Andreas P. freundlicherweise zur Verf\u00fcgung gestellt. Ich habe zur Ansteuerung der Bausteine Digital Input und Digital Output ein kleine Demo in C++ f\u00fcr den PI geschrieben. Auf http:\/\/www.netzmafia.de\/skripten\/hardware\/RasPi\/RasPi_I2C.html gibt es eine gute Beschreibung zur Installation der Device&#8230; <a class=\"continue-reading-link\" href=\"https:\/\/www.horter.de\/blog\/code-fuer-c-i2c-di-und-i2c-do\/\">mehr lesen<\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[255],"tags":[172,168,169,69,171,173,170,7,45,108],"class_list":["post-1294","post","type-post","status-publish","format-standard","hentry","category-raspberry-pi","tag-ausgabekarte","tag-c","tag-code","tag-digital-input","tag-digital-output","tag-digitalsignale","tag-eingabekarte","tag-i2c","tag-input","tag-raspberry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>C++ Code f\u00fcr digitale I2C-Baugruppen - Horter &amp; Kalb Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.horter.de\/blog\/code-fuer-c-i2c-di-und-i2c-do\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C++ Code f\u00fcr digitale I2C-Baugruppen - Horter &amp; Kalb Blog\" \/>\n<meta property=\"og:description\" content=\"den Code hat Andreas P. freundlicherweise zur Verf\u00fcgung gestellt. Ich habe zur Ansteuerung der Bausteine Digital Input und Digital Output ein kleine Demo in C++ f\u00fcr den PI geschrieben. Auf http:\/\/www.netzmafia.de\/skripten\/hardware\/RasPi\/RasPi_I2C.html gibt es eine gute Beschreibung zur Installation der Device... mehr lesen\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.horter.de\/blog\/code-fuer-c-i2c-di-und-i2c-do\/\" \/>\n<meta property=\"og:site_name\" content=\"Horter &amp; Kalb Blog\" \/>\n<meta property=\"article:published_time\" content=\"2016-10-04T16:33:10+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-01-13T15:32:03+00:00\" \/>\n<meta name=\"author\" content=\"JH\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Verfasst von\" \/>\n\t<meta name=\"twitter:data1\" content=\"JH\" \/>\n\t<meta name=\"twitter:label2\" content=\"Gesch\u00e4tzte Lesezeit\" \/>\n\t<meta name=\"twitter:data2\" content=\"5\u00a0Minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.horter.de\/blog\/code-fuer-c-i2c-di-und-i2c-do\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.horter.de\/blog\/code-fuer-c-i2c-di-und-i2c-do\/\"},\"author\":{\"name\":\"JH\",\"@id\":\"https:\/\/www.horter.de\/blog\/#\/schema\/person\/a8a4c3c5d3167dce7c7d31df6088b5d2\"},\"headline\":\"C++ Code f\u00fcr digitale I2C-Baugruppen\",\"datePublished\":\"2016-10-04T16:33:10+00:00\",\"dateModified\":\"2023-01-13T15:32:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.horter.de\/blog\/code-fuer-c-i2c-di-und-i2c-do\/\"},\"wordCount\":130,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.horter.de\/blog\/#organization\"},\"keywords\":[\"Ausgabekarte\",\"C++\",\"Code\",\"digital input\",\"digital output\",\"Digitalsignale\",\"Eingabekarte\",\"I2C\",\"Input\",\"Raspberry\"],\"articleSection\":[\"Raspberry PI\"],\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.horter.de\/blog\/code-fuer-c-i2c-di-und-i2c-do\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.horter.de\/blog\/code-fuer-c-i2c-di-und-i2c-do\/\",\"url\":\"https:\/\/www.horter.de\/blog\/code-fuer-c-i2c-di-und-i2c-do\/\",\"name\":\"C++ Code f\u00fcr digitale I2C-Baugruppen - Horter &amp; Kalb Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.horter.de\/blog\/#website\"},\"datePublished\":\"2016-10-04T16:33:10+00:00\",\"dateModified\":\"2023-01-13T15:32:03+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.horter.de\/blog\/code-fuer-c-i2c-di-und-i2c-do\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.horter.de\/blog\/code-fuer-c-i2c-di-und-i2c-do\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.horter.de\/blog\/code-fuer-c-i2c-di-und-i2c-do\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Start\",\"item\":\"https:\/\/www.horter.de\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C++ Code f\u00fcr digitale I2C-Baugruppen\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.horter.de\/blog\/#website\",\"url\":\"https:\/\/www.horter.de\/blog\/\",\"name\":\"Horter & Kalb Blog\",\"description\":\"SPS, I2C und mehr\",\"publisher\":{\"@id\":\"https:\/\/www.horter.de\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.horter.de\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"de\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.horter.de\/blog\/#organization\",\"name\":\"Horter & Kalb Blog\",\"url\":\"https:\/\/www.horter.de\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"de\",\"@id\":\"https:\/\/www.horter.de\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.horter.de\/blog\/wp-content\/uploads\/2026\/01\/hoka_Icon_400x400.png\",\"contentUrl\":\"https:\/\/www.horter.de\/blog\/wp-content\/uploads\/2026\/01\/hoka_Icon_400x400.png\",\"width\":400,\"height\":400,\"caption\":\"Horter & Kalb Blog\"},\"image\":{\"@id\":\"https:\/\/www.horter.de\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.horter.de\/blog\/#\/schema\/person\/a8a4c3c5d3167dce7c7d31df6088b5d2\",\"name\":\"JH\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"de\",\"@id\":\"https:\/\/www.horter.de\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/www.horter.de\/blog\/wp-content\/uploads\/2015\/07\/jhfb.jpg\",\"contentUrl\":\"https:\/\/www.horter.de\/blog\/wp-content\/uploads\/2015\/07\/jhfb.jpg\",\"caption\":\"JH\"},\"url\":\"https:\/\/www.horter.de\/blog\/author\/j-horter\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"C++ Code f\u00fcr digitale I2C-Baugruppen - Horter &amp; Kalb Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.horter.de\/blog\/code-fuer-c-i2c-di-und-i2c-do\/","og_locale":"de_DE","og_type":"article","og_title":"C++ Code f\u00fcr digitale I2C-Baugruppen - Horter &amp; Kalb Blog","og_description":"den Code hat Andreas P. freundlicherweise zur Verf\u00fcgung gestellt. Ich habe zur Ansteuerung der Bausteine Digital Input und Digital Output ein kleine Demo in C++ f\u00fcr den PI geschrieben. Auf http:\/\/www.netzmafia.de\/skripten\/hardware\/RasPi\/RasPi_I2C.html gibt es eine gute Beschreibung zur Installation der Device... mehr lesen","og_url":"https:\/\/www.horter.de\/blog\/code-fuer-c-i2c-di-und-i2c-do\/","og_site_name":"Horter &amp; Kalb Blog","article_published_time":"2016-10-04T16:33:10+00:00","article_modified_time":"2023-01-13T15:32:03+00:00","author":"JH","twitter_card":"summary_large_image","twitter_misc":{"Verfasst von":"JH","Gesch\u00e4tzte Lesezeit":"5\u00a0Minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.horter.de\/blog\/code-fuer-c-i2c-di-und-i2c-do\/#article","isPartOf":{"@id":"https:\/\/www.horter.de\/blog\/code-fuer-c-i2c-di-und-i2c-do\/"},"author":{"name":"JH","@id":"https:\/\/www.horter.de\/blog\/#\/schema\/person\/a8a4c3c5d3167dce7c7d31df6088b5d2"},"headline":"C++ Code f\u00fcr digitale I2C-Baugruppen","datePublished":"2016-10-04T16:33:10+00:00","dateModified":"2023-01-13T15:32:03+00:00","mainEntityOfPage":{"@id":"https:\/\/www.horter.de\/blog\/code-fuer-c-i2c-di-und-i2c-do\/"},"wordCount":130,"commentCount":0,"publisher":{"@id":"https:\/\/www.horter.de\/blog\/#organization"},"keywords":["Ausgabekarte","C++","Code","digital input","digital output","Digitalsignale","Eingabekarte","I2C","Input","Raspberry"],"articleSection":["Raspberry PI"],"inLanguage":"de","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.horter.de\/blog\/code-fuer-c-i2c-di-und-i2c-do\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.horter.de\/blog\/code-fuer-c-i2c-di-und-i2c-do\/","url":"https:\/\/www.horter.de\/blog\/code-fuer-c-i2c-di-und-i2c-do\/","name":"C++ Code f\u00fcr digitale I2C-Baugruppen - Horter &amp; Kalb Blog","isPartOf":{"@id":"https:\/\/www.horter.de\/blog\/#website"},"datePublished":"2016-10-04T16:33:10+00:00","dateModified":"2023-01-13T15:32:03+00:00","breadcrumb":{"@id":"https:\/\/www.horter.de\/blog\/code-fuer-c-i2c-di-und-i2c-do\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.horter.de\/blog\/code-fuer-c-i2c-di-und-i2c-do\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.horter.de\/blog\/code-fuer-c-i2c-di-und-i2c-do\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Start","item":"https:\/\/www.horter.de\/blog\/"},{"@type":"ListItem","position":2,"name":"C++ Code f\u00fcr digitale I2C-Baugruppen"}]},{"@type":"WebSite","@id":"https:\/\/www.horter.de\/blog\/#website","url":"https:\/\/www.horter.de\/blog\/","name":"Horter & Kalb Blog","description":"SPS, I2C und mehr","publisher":{"@id":"https:\/\/www.horter.de\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.horter.de\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"de"},{"@type":"Organization","@id":"https:\/\/www.horter.de\/blog\/#organization","name":"Horter & Kalb Blog","url":"https:\/\/www.horter.de\/blog\/","logo":{"@type":"ImageObject","inLanguage":"de","@id":"https:\/\/www.horter.de\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.horter.de\/blog\/wp-content\/uploads\/2026\/01\/hoka_Icon_400x400.png","contentUrl":"https:\/\/www.horter.de\/blog\/wp-content\/uploads\/2026\/01\/hoka_Icon_400x400.png","width":400,"height":400,"caption":"Horter & Kalb Blog"},"image":{"@id":"https:\/\/www.horter.de\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.horter.de\/blog\/#\/schema\/person\/a8a4c3c5d3167dce7c7d31df6088b5d2","name":"JH","image":{"@type":"ImageObject","inLanguage":"de","@id":"https:\/\/www.horter.de\/blog\/#\/schema\/person\/image\/","url":"https:\/\/www.horter.de\/blog\/wp-content\/uploads\/2015\/07\/jhfb.jpg","contentUrl":"https:\/\/www.horter.de\/blog\/wp-content\/uploads\/2015\/07\/jhfb.jpg","caption":"JH"},"url":"https:\/\/www.horter.de\/blog\/author\/j-horter\/"}]}},"_links":{"self":[{"href":"https:\/\/www.horter.de\/blog\/wp-json\/wp\/v2\/posts\/1294","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.horter.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.horter.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.horter.de\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.horter.de\/blog\/wp-json\/wp\/v2\/comments?post=1294"}],"version-history":[{"count":9,"href":"https:\/\/www.horter.de\/blog\/wp-json\/wp\/v2\/posts\/1294\/revisions"}],"predecessor-version":[{"id":1312,"href":"https:\/\/www.horter.de\/blog\/wp-json\/wp\/v2\/posts\/1294\/revisions\/1312"}],"wp:attachment":[{"href":"https:\/\/www.horter.de\/blog\/wp-json\/wp\/v2\/media?parent=1294"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.horter.de\/blog\/wp-json\/wp\/v2\/categories?post=1294"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.horter.de\/blog\/wp-json\/wp\/v2\/tags?post=1294"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}