I just bought some of these buttons: Qwiic Button - Red SPX-15584 , installed the library on a win10, arduino ide 1.8.5 and was testing with Example1_PrintButtonStatus.ino and Example2_LightWhenPressed.ino, but not getting the results I would have expected.
In both sketches I have tested I have to hold the button down for 3-4 seconds before it will find it and then the serial console reports back a dozen of so button presses. If I push the button once it does not recognize it.
I would hope a single button press would report back one “The button is pressed!” I tried both a red and blue button with the same results.
thoughts ?
sample output: ( I commented out the //Serial.println(“The button is not pressed.”); since it was filling up the console so fast it was hard to see a legitimate button press event)
Device will acknowledge!
The button is pressed!
The button is pressed!
The button is pressed!
The button is pressed!
The button is pressed!
The button is pressed!
The button is pressed!
The button is pressed!
The button is pressed!
The button is pressed!
The button is pressed!
Hi Jim.
It looks like we may have an error somewhere in the library. I’ll check with the SparkX team and see if they can get that fixed really qwiic for you!
Lol ! Thanks Chris
Btw - using a blackboard w/Qwiic connector if that matters
Hey jimk123! I’m Fischer, the guy behind the firmware on the button. Super sorry to hear that it’s giving you trouble, but the fix is pretty straightforward!
tl;dr: Add button.setDebounceTime(10); to your sketch after button.begin(DEFAULT_BUTTON_ADDRESS); I’ve attached a .ino that should do what you want!
The real source of the issue is in how the button’s settings are stored in EEPROM. Whenever the button turns on, it loads settings from memory (things like the LED’s brightness and I2C address). One of those settings is the button’s debounce time. When we program the onboard microcontroller, all of the EEPROM bytes are 0xFF by default, so when the button boots, it grabs settings from EEPROM, including the debounce time. As a result, the debounce time isn’t set correctly on it’s first boot, so we connect an Arduino to the button and run a program that sets all of the settings on the button. This is an extra step, and it looks like this one might have not made it through!
Hope this helps, and enjoy your buttoneering
-Fischer
Example1_PrintButtonStatus.zip (986 Bytes)
Hi Fischer
Thanks for the reply. I added the line:
button.setDebounceTime(10); //Set Debounce Time to 10ms
after button.begin…
now it detects a quick button press but still reports back 5 button presses. I wanted to use this in a sketch were a single button press sends a SMS txt messge. I did this in code a long time ago with a traditional button but what a pain, so I was excited to see this product plus a builtin LED to confirm the button press. Is there a way to tune this so one quick button press only generates a single button press event ? I tried to increase the delay time but that had an unwanted effect where you had to hold the button down much longer.
thanks
Jim
The button is pressed!
The button is pressed!
The button is pressed!
The button is pressed!
The button is pressed!
you mentioned you are using EEPROM to store the button config info. Is it the arduino EEPROM or does the sensor have its own EEPROM ? I ask because I use EEPROM on some of my projects and if you are using the arduino EEPROM it would be nice to know what locations it is writing to.
thanks
now it detects a quick button press but still reports back 5 button presses.
What you’re seeing is the example code polling the button very quickly. There’s only one button press but the code is so fast that it’s checking the button state 5 times while the button is still down. (even though it’s super short time wise) You’d need to write your own code or edit the example code to stop polling the button for a bit once it detects a press, or just have it ignore repeats until it sees a button not pressed message again.
ok - I will try and adding code to handle extra button events. can you comment on which eeprom you are using ? does the board have eeprom or are you using the redboard ? if it is the redboard can you document which addresses it uses ? like I mentioned I use eeprom in some projects and could see where that would cause a collision
thanks
I am not a programmer but this was my attempt at adding code to introduce a delay so if you hold down the button too long it will not trigger multiple ‘button press’ events In this example I am using a 2 second delay to ignore additional button presses
unsigned long lastButtonPush = 0; // start a timer once the first button press is detected
unsigned long debounceDelay = 2000; // ignore any additional button presses after the first press for this time
in the loop function:
if(button.isPressed())
{
if ((millis() - lastButtonPush) > debounceDelay ) // if the timer ran more than ‘n’ miliseconds process it
{
lastButtonPush = millis(); // start a timer to ignore any new button presses for awhile…
Serial.println(“The button is pressed!”);
button.LEDon(brightness);
}
else
{
Serial.println(F(“IGNORE BUTTON PRESS”));
}
}
else
{
//Serial.println(“The button is not pressed.”);
button.LEDoff();
}
delay(100); //Don’t hammer too hard on the I2C bus
does the board have eeprom or are you using the redboard
The Qwiic Button board has a ATtiny84 microcontroller on it and that has a 512 byte EEPROM built in. The EEPROM is used by the firmware on the board itself and isn’t accessible to the end user so you don’t need to worry about accidentally accessing it.
Excellent, thanks Chris !