Arduino Library Code with "Daisy-chained" Adafruit LED Arcade Button 1x4 STEMMA QT

Hello,

I'm a beginner Arduino user and would like some help writing code to expand the use of the Adafruit LED Arcade Button 1x4 STEMMA QT.

I'd like to use not only 4 buttons option but daisy chain an additional 1x4 STEMMA QT to the tail end of the original. My understanding is that a new 1x4 STEMMA QT board would have a new "name" in the code different from the original "DEFAULT_I2C_ADDR 0x3A" and the "names" of the button inputs would also be different.

I'm unsure of where to insert these new lines of code into the Adafruit Library supplied example.

Any help is appreciated! Thanks for reading my question.

The Library code copy for the 1x4 STEMMA QT breakout is below:

/*
 * This example shows how read arcade buttons and PWM the LEDs on the Adafruit Arcade QT!
 */

#include "Adafruit_seesaw.h"
#include <seesaw_neopixel.h>

#define  DEFAULT_I2C_ADDR 0x3A

#define  SWITCH1  18  // PA01
#define  SWITCH2  19 // PA02
#define  SWITCH3  20 // PA03
#define  SWITCH4  2 // PA06
#define  PWM1  12  // PC00
#define  PWM2  13 // PC01
#define  PWM3  0 // PA04
#define  PWM4  1 // PA05


Adafruit_seesaw ss;

void setup() {
  Serial.begin(115200);
  
  while (!Serial) delay(10);   // wait until serial port is opened

  Serial.println(F("Adafruit PID 5296 I2C QT 4x LED Arcade Buttons test!"));
  
  if (!ss.begin(DEFAULT_I2C_ADDR)) {
    Serial.println(F("seesaw not found!"));
    while(1) delay(10);
  }

  uint16_t pid;
  uint8_t year, mon, day;
  
  ss.getProdDatecode(&pid, &year, &mon, &day);
  Serial.print("seesaw found PID: ");
  Serial.print(pid);
  Serial.print(" datecode: ");
  Serial.print(2000+year); Serial.print("/"); 
  Serial.print(mon); Serial.print("/"); 
  Serial.println(day);

  if (pid != 5296) {
    Serial.println(F("Wrong seesaw PID"));
    while (1) delay(10);
  }

  Serial.println(F("seesaw started OK!"));
  ss.pinMode(SWITCH1, INPUT_PULLUP);
  ss.pinMode(SWITCH2, INPUT_PULLUP);
  ss.pinMode(SWITCH3, INPUT_PULLUP);
  ss.pinMode(SWITCH4, INPUT_PULLUP);
  ss.analogWrite(PWM1, 127);
  ss.analogWrite(PWM2, 127);
  ss.analogWrite(PWM3, 127);
  ss.analogWrite(PWM4, 127);
}

uint8_t incr = 0;

void loop() {
  if (! ss.digitalRead(SWITCH1)) {
    Serial.println("Switch 1 pressed");
    ss.analogWrite(PWM1, incr);
    incr += 5;
  } else {
    ss.analogWrite(PWM1, 0);
  }
  
  if (! ss.digitalRead(SWITCH2)) {
    Serial.println("Switch 2 pressed");
    ss.analogWrite(PWM2, incr);
    incr += 5;
  } else {
    ss.analogWrite(PWM2, 0);
  }
  
  if (! ss.digitalRead(SWITCH3)) {
    Serial.println("Switch 3 pressed");
    ss.analogWrite(PWM3, incr);
    incr += 5;
  } else {
    ss.analogWrite(PWM3, 0);
  }
  
  if (! ss.digitalRead(SWITCH4)) {
    Serial.println("Switch 4 pressed");
    ss.analogWrite(PWM4, incr);
    incr += 5;
  } else {
    ss.analogWrite(PWM4, 0);
  }
  delay(10);
}

I2C devices each have to have their own address. Looking at the Adafruit page, this board has jumpers on it that allow you to change the default address. This is something you will have to do for your second board. The default value is 0x3A. Cutting open one of the address jumper lines on your second board will change that value. You can use the i2c bus scanner sketch to determine what the new address is.

Then, in your code you will create 2 instances of the board, and then call begin() on the first one with the default value and call begin() on the second one with your other address.

Adafruit_seesaw ss1;
Adafruit_seesaw ss2;
...
void setup() {
  ss1.begin(DEFAULT_I2C_ADDR);
  ss2.begin(other_address);
...

The jumpers are the thin lines of copper on the back side of the board.

blh64,

I see... thank you for the address suggestion. That helped me troubleshoot.

The code below Verifies and is Uploaded to the Arduino UNO with no error messages, but when ran the second board is not found - with this message:

18:25:20.939 -> Adafruit PID 5296 I2C QT 4x LED Arcade Buttons test!
18:25:20.969 -> seesaw found PID: 5296 datecode: 2021/12/13
18:25:20.969 -> seesaw started OK!
18:25:21.061 -> Adafruit PID 5296 I2C QT 4x LED Arcade Buttons test!
18:25:21.139 -> SS 2 seesaw not found!

Is there something with my code below that you see as an issue?

Thank you, again.

/*
 * This example shows how read arcade buttons and PWM the LEDs on the Adafruit Arcade QT!
 */

#include "Adafruit_seesaw.h"
#include <seesaw_neopixel.h>

#define  DEFAULT_I2C_ADDR 0x3A

#define  SWITCH1  18  // PA01
#define  SWITCH2  19 // PA02
#define  SWITCH3  20 // PA03
#define  SWITCH4  2 // PA06
#define  PWM1  12  // PC00
#define  PWM2  13 // PC01
#define  PWM3  0 // PA04
#define  PWM4  1 // PA05

Adafruit_seesaw ss;

#define  DEFAULT_I2C_ADDR2 0x3B

#define  SWITCH5  18  // PA01
#define  SWITCH6  19 // PA02
#define  SWITCH7  20 // PA03
#define  SWITCH8  2 // PA06
#define  PWM5  12  // PC00
#define  PWM6  13 // PC01
#define  PWM7  0 // PA04
#define  PWM8  1 // PA05

Adafruit_seesaw ss2;

void setup() {
  ss.begin(DEFAULT_I2C_ADDR);

  ss2.begin (DEFAULT_I2C_ADDR2)

  ;Serial.begin(115200);


  while (!Serial) delay(10);   // wait until serial port is opened

  Serial.println(F("Adafruit PID 5296 I2C QT 4x LED Arcade Buttons test!"));
  
  if (!ss.begin(DEFAULT_I2C_ADDR)) {
    Serial.println(F(" SS seesaw not found!"));
    while(1) delay(10);
  }

  uint16_t pid;
  uint8_t year, mon, day;
  
  ss.getProdDatecode(&pid, &year, &mon, &day);
  Serial.print("seesaw found PID: ");
  Serial.print(pid);
  Serial.print(" datecode: ");
  Serial.print(2000+year); Serial.print("/"); 
  Serial.print(mon); Serial.print("/"); 
  Serial.println(day);

  if (pid != 5296) {
    Serial.println(F("Wrong seesaw PID"));
    while (1) delay(10);
  }

  Serial.println(F("seesaw started OK!"));
  ss.pinMode(SWITCH1, INPUT_PULLUP);
  ss.pinMode(SWITCH2, INPUT_PULLUP);
  ss.pinMode(SWITCH3, INPUT_PULLUP);
  ss.pinMode(SWITCH4, INPUT_PULLUP);
  ss.analogWrite(PWM1, 127);
  ss.analogWrite(PWM2, 127);
  ss.analogWrite(PWM3, 127);
  ss.analogWrite(PWM4, 127);
  

Serial.println(F("Adafruit PID 5296 I2C QT 4x LED Arcade Buttons test!"));
  
  if (!ss2.begin(DEFAULT_I2C_ADDR2)) {
    Serial.println(F("SS 2 seesaw not found!"));
    while(1) delay(10);
  }
  
  ss2.getProdDatecode(&pid, &year, &mon, &day);
  Serial.print("seesaw found PID: ");
  Serial.print(pid);
  Serial.print(" datecode: ");
  Serial.print(2000+year); Serial.print("/"); 
  Serial.print(mon); Serial.print("/"); 
  Serial.println(day);

  if (pid != 5296) {
    Serial.println(F("Wrong seesaw PID"));
    while (1) delay(10);
  }

  Serial.println(F("seesaw started OK!"));
  ss2.pinMode(SWITCH5, INPUT_PULLUP);
  ss2.pinMode(SWITCH6, INPUT_PULLUP);
  ss2.pinMode(SWITCH7, INPUT_PULLUP);
  ss2.pinMode(SWITCH8, INPUT_PULLUP);
  ss2.analogWrite(PWM5, 127);
  ss2.analogWrite(PWM6, 127);
  ss2.analogWrite(PWM7, 127);
  ss2.analogWrite(PWM8, 127);
}


uint8_t incr = 0;

void loop() {
  if (! ss.digitalRead(SWITCH1)) {
    Serial.println("Switch 1 pressed");
    ss.analogWrite(PWM1, incr);
    incr += 5;
  } else {
    ss.analogWrite(PWM1, 0);
  }
  
  if (! ss.digitalRead(SWITCH2)) {
    Serial.println("Switch 2 pressed");
    ss.analogWrite(PWM2, incr);
    incr += 5;
  } else {
    ss.analogWrite(PWM2, 0);
  }
  
  if (! ss.digitalRead(SWITCH3)) {
    Serial.println("Switch 3 pressed");
    ss.analogWrite(PWM3, incr);
    incr += 5;
  } else {
    ss.analogWrite(PWM3, 0);
  }
  
  if (! ss.digitalRead(SWITCH4)) {
    Serial.println("Switch 4 pressed");
    ss.analogWrite(PWM4, incr);
    incr += 5;
  } else {
    ss.analogWrite(PWM4, 0);
  }
  delay(10);

  if (! ss2.digitalRead(SWITCH5)) {
    Serial.println("Switch 1 pressed");
    ss2.analogWrite(PWM5, incr);
    incr += 5;
  } else {
    ss2.analogWrite(PWM5, 0);
  }
  
  if (! ss2.digitalRead(SWITCH6)) {
    Serial.println("Switch 6 pressed");
    ss2.analogWrite(PWM6, incr);
    incr += 5;
  } else {
    ss2.analogWrite(PWM6, 0);
  }
  
  if (! ss2.digitalRead(SWITCH7)) {
    Serial.println("Switch 7 pressed");
    ss2.analogWrite(PWM7, incr);
    incr += 5;
  } else {
    ss2.analogWrite(PWM7, 0);
  }
  
  if (! ss2.digitalRead(SWITCH8)) {
    Serial.println("Switch 8 pressed");
    ss2.analogWrite(PWM8, incr);
    incr += 5;
  } else {
    ss2.analogWrite(PWM8, 0);
  }
  delay(10);
}

Did you verify the address of your second board? Here's what I would do...

  1. cut one of the address traces on the second board.
  2. Connect just that board to your Uno
  3. upload the i2c scanner sketch Arduino Playground - I2cScanner and see what address it tells you
  4. Use that address in your example code for the board.
  5. If all works, then connect both boards and check if your new code works that addresses both boards.

FYI.... you don't need to .begin() calls in your setup for each of the boards. Only 1 per board is required.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.