SevSeg display with I2C backpack

I had a project that was working perfectly using a SevSeg display. Then I switched the display for one with an I2C backpack, so that I could consolidate the 14 wires into 4. The display works with the example code, but not with my project.

Below is the simple version of the project where I use a rotary switch to move through 3 modes. Each mode should print the mode number in the serial monitor and display the number on the display. Without any of the matrix.writeDisplay() lines, it works. As soon as I add any of these lines back, it stops working (the serial monitor stops).

Also, do you know how to make this display go blank? Without the backpack, I could use "sevseg.blank()". But I'm not finding anything such code for this version.

Thanks!!

#include <Wire.h> // Enable this line if using Arduino Uno, Mega, etc.
#include <Adafruit_GFX.h>
#include "Adafruit_LEDBackpack.h"
Adafruit_7segment matrix = Adafruit_7segment();

const int mode2 = A4; // switch set to mode 2 - counts
const int mode3 = A5; // switch set to mode 3 - timer


void setup() {
  Serial.begin(115200);
  
  pinMode(mode2, INPUT_PULLUP);
  pinMode(mode3, INPUT_PULLUP);
  
  matrix.begin(0x70);
}



void loop() {

  if (digitalRead(mode2) == LOW){
    Serial.println("mode 2");
    matrix.print(0002);
    matrix.writeDisplay();
  }

  else if (digitalRead(mode3) == LOW){
    Serial.println("mode 3");
    matrix.print(0003);
    matrix.writeDisplay();
  }

  else {
    Serial.println("mode 1");
    matrix.print(0001);
    matrix.writeDisplay();
  }

}

If your "backpack" is I2C, pins A4 and A5 must be used for I2C. The "mode2" and "mode3" pins should be some other pins.

Also, provide a datasheet, link to a datasheet or part number to find it.

Weird. I have the backpack plugged into SCL and SDA pins on the Arduino. And I don't see any markings on the board to indicate that A4 and A5 are special, but I just tried A2 and A3 and it works as expected. I also tried some digital pins and those worked too. So I guess I just happened to pick the only 2 pins that wouldn't work. Thanks!

It's always a good idea to mention the model of Arduino you are using in your first post. They are not all the same.

From what you told in post #4, it is now clear that @xfpd guessed correctly that you are using an Uno R3.

On Uno R3, the SDA & SCL pins are connected directly to the A4 & A5 pins. This is not true on other models.

I should have mentioned that, indeed, I guessed at Uno/Nano (supported with a little probability).

It couldn't have been Nano because that doesn't have pins labelled SCL & SDA. @fishysam would have needed to connect the display to A4 & A5, so it would have (hopefully) been obvious that those same pins could not be used for button inputs.

(Although they could if an I2C I/O expander chip was used!)

That makes sense. I'll try to remember to include that information in future posts. Thanks.

1 Like

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