Qwiic button library problems under Arduino IDE

I’ve been able to use my Qwiic buttons compling under PlatformIO. And I’ve been able to scan I2C addresses under Arduino IDE, but haven’t been able to get the stock examples going. Code that I’ve been trying follows. Added the definition of SDA and SCL as they were wrong with my Sparkfun Thing Plus. As mentioned code for a scanner runs under Arduino IDE but Sparkfun QwiicButon doesn’t. Here’s my code:

/******************************************************************************
  Checks whether the button is pressed, and then prints its status over serial!

  Fischer Moseley @ SparkFun Electronics
  Original Creation Date: June 28, 2019

  This code is Lemonadeware; if you see me (or any other SparkFun employee) at the
  local, and you've found our code helpful, please buy us a round!

  Hardware Connections:
  Attach the Qwiic Shield to your Arduino/Photon/ESP32 or other
  Plug the button into the shield
  Print it to the serial monitor at 115200 baud.

  Distributed as-is; no warranty is given.
******************************************************************************/

//For this example to work, you must daisy chain together two Qwiic buttons with different addresses. 
//To change the address of a Qwiic button, please visit example 6
#include <arduino.h>

#include "SparkFun_Qwiic_Button.h"
//#include "wire.h"

QwiicButton button1;
QwiicButton button2;

void setup() {
  Serial.begin(115200);
  Serial.println("Qwiic button examples");
  
//modified from example
const int SCLpin = 22;
const int SDApin = 23; 

  Serial.println("\n*************\nSDA = "+String(SDA));
  Serial.println("SCL = "+String(SCL));
  Serial.println("SDA Pin = "+String(SDApin));
  Serial.println("SCL Pin = "+String(SCLpin));
  Wire.begin(SDApin, SCLpin);


  


  //check if the buttons will acknowledge over I2C
  //connect to Qwiic button at address 0x5B
  if (button1.begin(0x67) == false){
    Serial.println("Button 1 did not acknowledge! Freezing.");
    while(1);
  }
  
}


void loop() {
  //check if button 1 is pressed, and tell us if it is!
  if (button1.isPressed() == true) {
    Serial.println("Button 1 is pressed!");
    while (button1.isPressed() == true)
      delay(10);  //wait for user to stop pressing
    Serial.println("Button 1 is not pressed.");
  }

  //check if button 2 is pressed, and tell us if it is!
  if (button2.isPressed() == true){
    Serial.println("Button 2 is pressed!");
    while (button2.isPressed() == true)
      delay(10);  //wait for user to stop pressing
    Serial.println("Button 2 is not pressed.");
  }
  delay(20); //Don't hammer too hard on the I2C bus.
}

In the above code I actually have two buttons one at 0x5B and the other at

0x67 these are both found successfully on the scanner not using the Qwiic Button library.

Which Thing Plus are you using?

Brandon

Mine is the Thing Plus ESP32 WROOM

You shouldn’t have a button at 0x5B, please see the I2C table for which address is per each configuration: https://learn.sparkfun.com/tutorials/sp … e-overview

Are you getting any error messages in the serial output?

brandon:

Thanks for the responses. This may be an electricphred problem as my I2C scanner sketch opens in both PlatformIO and Arduino IDE:

Scanning…

I2C device found at address 0x10 !

I2C device found at address 0x3C !

I2C device found at address 0x6F !

The first and third are my QwiicButtons and 0x3C is a transparent OLED. All three devices work fine under PlatformIO

My problem before was post compile, the other sketch would say “Couldn’t connect to I2C”. Once I chase that down I shall post here, thanks for your help

Well I don’t think I called up the correct sketch which corrects the wrong default SCL and SDA pins for the Huzzah32. They should be as follows:

//modified from example

const int SCLpin = 22;

const int SDApin = 23;

in the defaults which come up they are 21 and 22 respectively. So my code compiled and nothing happened when I tried to access I2C over the WRONG DEFAULT pins. This should get fixed Sparkfun!