<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Gateway - I2C Advanced button and led]]></title><description><![CDATA[<p dir="auto">I have a gate based on esp2866, wemos mini board.  There are few gpio outputs on it.  To implement additional features, such as an <a href="https://www.mysensors.org/build/advanced_gateway" rel="nofollow ugc">inclusive button and status LEDs</a>, I had to connect a gpio expansion board via I2C.  I took a PCF8574 based board.  For the operation of the button and indication through it, the sources had to be slightly changed, the patch for version 2.4.0 is <a href="https://gist.github.com/clclon/8c1ffa2b7d0566055a5b69b6fd9534a5" rel="nofollow ugc">attached</a> in gist.</p>
<p dir="auto">Example sketch code:</p>
<pre><code>#define MY_DEFAULT_LED_EXT 1
#define MY_INCLUSION_MODE_FEATURE
#define MY_INCLUSION_BUTTON_FEATURE
#define MY_INCLUSION_MODE_DURATION 10

#include &lt;MySensors.h&gt;
#include &lt;core/MyInclusionMode.h&gt;
#include &lt;PCF8574.h&gt;

const uint8_t scl_PIN = D1;
const uint8_t sda_PIN = D2;
const uint8_t led_device[4] { 2U, 3U, 6U, 4U };
const uint8_t btn_device[4] { 0U, 1U, 5U, 7U };
PCF8574 expander(0x22, sda_PIN, scl_PIN);

void setup() {
  Wire.begin(sda_PIN, scl_PIN);
  Serial.begin(115200);
  while (!Serial) delay(50);
  
  for (uint8_t i = 0; i &lt; 4U; i++) {
    expander.pinMode(led_device[i], OUTPUT);
    expander.digitalWrite(led_device[i], HIGH);
    Serial.printf("Init LED expander: %u/%u\n", (uint16_t)i, (uint16_t)led_device[i]);

    expander.pinMode(btn_device[i], INPUT);
    expander.digitalWrite(btn_device[i], HIGH);
    Serial.printf("Init BTN expander: %u/%u\n", (uint16_t)i, (uint16_t)btn_device[i]);
  }
  expander.begin();
  ledsSetCb(
    [=](uint8_t &amp; state) { expander.digitalWrite(led_device[1], state); },
    [=](uint8_t &amp; state) { expander.digitalWrite(led_device[2], state); },
    [=](uint8_t &amp; state) { expander.digitalWrite(led_device[3], state); }
  );
  inclusionSetCb(
    [=]() { return (expander.digitalRead(btn_device[0], true) == LOW); },
    [=](uint8_t &amp; state) { expander.digitalWrite(led_device[0], state); }
  );
}

void loop() {}


</code></pre>
<p dir="auto">I2C extender<br />
<img src="/assets/uploads/files/1602087315689-pcf8574-module-type2-800x800.jpg" alt="PCF8574-module-type2-800x800.jpg" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.mysensors.org/topic/11396/gateway-i2c-advanced-button-and-led</link><generator>RSS for Node</generator><lastBuildDate>Mon, 12 Oct 2026 06:02:31 GMT</lastBuildDate><atom:link href="https://forum.mysensors.org/topic/11396.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 07 Oct 2020 16:15:22 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Gateway - I2C Advanced button and led on Fri, 09 Oct 2020 11:57:13 GMT]]></title><description><![CDATA[<p dir="auto">small fix of the <a href="https://github.com/CloneTV/MySensor-Home-Net/raw/master/src/MySensors-I2C-LED.zip" rel="nofollow ugc">patch</a>, removed "contact bounce" in the inclusive button.</p>
]]></description><link>https://forum.mysensors.org/post/107753</link><guid isPermaLink="true">https://forum.mysensors.org/post/107753</guid><dc:creator><![CDATA[Clone Tv]]></dc:creator><pubDate>Fri, 09 Oct 2020 11:57:13 GMT</pubDate></item></channel></rss>