General

problem DFRobot RGB I2C Buttons (DFR0991) being "stuck"

userHead AndF 2025-09-11 18:16:20 68 Views2 Replies

Hello,

 

I am having a problem with using DFRobot RGB I2C Buttons (DFR0991).

According to DFRobot documentation, up to 8 devices work on a single I²C bus. I am using 5 modules connected to Arduino Nano ESP32.

I also tried using the ESP32’s second I²C bus: Buttons 1–2 on the standard bus, Buttons 3–5 on the second bus.

 

My goal is to have 5 buttons, each in a different color and the last button pressed (selected button) is supposed to be brighter than the others. This is working as expected most of the time.

 

The issue is that sometimes a button gets “stuck”, meaning it reports a press even though it was not pressed.

 

For example, in the videos below:

- Button 2 (red) is selected.

- Pressing button 3 (yellow) lights it up correctly and serial prints the right button number.

- Releasing button 3 immediately causes button 2 to light up again and report a press, even though it is not being pressed.

- Repressing the “stuck” button temporarily fixes the problem until it occurs again unpredictably.

The problem also occurs with other buttons being "stuck".

Notably, while button two is “stuck”, button 3, 4 and 5 react to presses, but button 1 does not react at all.

 

Videos showing the issue:

5 Buttons on the standard I2C Bus:

https://vimeo.com/1117724906?share=copy#t=17 

Buttons split across two I2C busses:

https://vimeo.com/1117729911?share=copy#t=0 

 

My setup is:

Arduino Nano ESP32

5 DFRboot RGB I2C Buttons 0x23-0x27 connected to 3.3V, Gnd, A4, A5

 

What I tested so far:

- Use two I2C busses separating the buttons - problem persists

- Adding 4.7 kΩ pull-ups on SDA/SCL – problem persists

- change wire clock to 50khz - problem persists

- adding short delays in between the differen getButtonStatus() - problem persists 

 

 

Here you find my code:

 

#include <DFRobot_RGBButton.h> // Button Library

 

DFRobot_RGBButton RGBButton1(&Wire, /*I2CAddr*/ 0x23);   // button 1 green

DFRobot_RGBButton RGBButton2(&Wire, /*I2CAddr*/ 0x24);   // button 2 red

DFRobot_RGBButton RGBButton3(&Wire, /*I2CAddr*/ 0x25);   // button 3 yellow

DFRobot_RGBButton RGBButton4(&Wire, /*I2CAddr*/ 0x26);   // button 4 blue

DFRobot_RGBButton RGBButton5(&Wire, /*I2CAddr*/ 0x27);   // button 5 white

 

int selectedButton = 1; 

int lastSelected = 0;

 

void setup()

{

  Serial.begin(115200);

 

  while( ! RGBButton1.begin() ){

    Serial.println("Communication with device 1 failed, please check connection!");

    delay(3000);

  }

  while( ! RGBButton2.begin() ){

    Serial.println("Communication with device 2 failed, please check connection!");

    delay(3000);

  }

  while( ! RGBButton3.begin() ){

    Serial.println("Communication with device 3 failed, please check connection!");

    delay(3000);

  }

  while( ! RGBButton4.begin() ){

    Serial.println("Communication with device 4 failed, please check connection!");

    delay(3000);

  }

  while( ! RGBButton5.begin() ){

    Serial.println("Communication with device 5 failed, please check connection!");

    delay(3000);

  }

  Serial.println("Begin ok!\n");

 

  updateLEDs(1);

 

}

 

void loop() {

  if (RGBButton1.getButtonStatus()) selectedButton = 1;

  if (RGBButton2.getButtonStatus()) selectedButton = 2;

  if (RGBButton3.getButtonStatus()) selectedButton = 3;

  if (RGBButton4.getButtonStatus()) selectedButton = 4;

  if (RGBButton5.getButtonStatus()) selectedButton = 5;

 

  if (selectedButton != lastSelected) {

    updateLEDs(selectedButton);

    lastSelected = selectedButton;

 

    Serial.print("Digital_values: ");

    Serial.println(selectedButton - 1); // kompatibel mit altem Patch

  }

 

  delay(10); // Entlastung für I2C

}

 

 

void updateLEDs(int active) {

  if (active == 1) RGBButton1.setRGBColor(0, 255, 0);  // hell

  else RGBButton1.setRGBColor(0, 5, 0);               // gedimmt

 

  if (active == 2) RGBButton2.setRGBColor(255, 0, 0);

  else RGBButton2.setRGBColor(5, 0, 0);

 

  if (active == 3) RGBButton3.setRGBColor(255, 255, 0);

  else RGBButton3.setRGBColor(5, 5, 0);

 

  if (active == 4) RGBButton4.setRGBColor(0, 0, 255);

  else RGBButton4.setRGBColor(0, 0, 5);

 

  if (active == 5) RGBButton5.setRGBColor(255, 255, 255);

  else RGBButton5.setRGBColor(5, 5, 5);

}

2025-09-11 18:45:06

The DFRobot RGB Button library has both getButtonStatus() and available().
The correct usage is often:

 

if (RGBButton1.available()) {
 if (RGBButton1.getButtonStatus() == DFRobot_RGBButton::PRESSED) {
   selectedButton = 1;
 }
}
Without available(), you sometimes re-read stale states.

userHeadPic ahsrab.rifat
AndF wrote:

Thanks for the reply, but when I try this I get “Compilation error: 'class DFRobot_RGBButton' has no member named 'available'” 

2025-09-11 19:10:02
1 Replies