Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. My Project
  3. Gateway - I2C Advanced button and led

Gateway - I2C Advanced button and led

Scheduled Pinned Locked Moved My Project
httpsgist.github.comclclon
2 Posts 1 Posters 49 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Clone Tv
    wrote on last edited by Clone Tv
    #1

    I have a gate based on esp2866, wemos mini board. There are few gpio outputs on it. To implement additional features, such as an inclusive button and status LEDs, 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 attached in gist.

    Example sketch code:

    #define MY_DEFAULT_LED_EXT 1
    #define MY_INCLUSION_MODE_FEATURE
    #define MY_INCLUSION_BUTTON_FEATURE
    #define MY_INCLUSION_MODE_DURATION 10
    
    #include <MySensors.h>
    #include <core/MyInclusionMode.h>
    #include <PCF8574.h>
    
    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 < 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 & state) { expander.digitalWrite(led_device[1], state); },
        [=](uint8_t & state) { expander.digitalWrite(led_device[2], state); },
        [=](uint8_t & state) { expander.digitalWrite(led_device[3], state); }
      );
      inclusionSetCb(
        [=]() { return (expander.digitalRead(btn_device[0], true) == LOW); },
        [=](uint8_t & state) { expander.digitalWrite(led_device[0], state); }
      );
    }
    
    void loop() {}
    
    
    

    I2C extender
    PCF8574-module-type2-800x800.jpg

    C 1 Reply Last reply
    1
    • C Clone Tv

      I have a gate based on esp2866, wemos mini board. There are few gpio outputs on it. To implement additional features, such as an inclusive button and status LEDs, 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 attached in gist.

      Example sketch code:

      #define MY_DEFAULT_LED_EXT 1
      #define MY_INCLUSION_MODE_FEATURE
      #define MY_INCLUSION_BUTTON_FEATURE
      #define MY_INCLUSION_MODE_DURATION 10
      
      #include <MySensors.h>
      #include <core/MyInclusionMode.h>
      #include <PCF8574.h>
      
      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 < 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 & state) { expander.digitalWrite(led_device[1], state); },
          [=](uint8_t & state) { expander.digitalWrite(led_device[2], state); },
          [=](uint8_t & state) { expander.digitalWrite(led_device[3], state); }
        );
        inclusionSetCb(
          [=]() { return (expander.digitalRead(btn_device[0], true) == LOW); },
          [=](uint8_t & state) { expander.digitalWrite(led_device[0], state); }
        );
      }
      
      void loop() {}
      
      
      

      I2C extender
      PCF8574-module-type2-800x800.jpg

      C Offline
      C Offline
      Clone Tv
      wrote on last edited by
      #2

      small fix of the patch, removed "contact bounce" in the inclusive button.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      16

      Online

      11.7k

      Users

      11.2k

      Topics

      113.1k

      Posts


      Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • MySensors
      • OpenHardware.io
      • Categories
      • Recent
      • Tags
      • Popular