Dual 7 Segment Display/Mega/Code Help

I’m trying to get some dual 7 segment displays working with the following code, but I’m only getting the middle LED (g) on each digit to light up. after uploading the code to my Mega.

int awayDs1 = 12;
int awayDs2 = 13;
int homeDs1 = 22;
int homeDs2 = 23;

#include "SevSegNums.h"
#include "Arduino.h"

#include <Wire.h>
#include <Adafruit_GFX.h>
#include "Adafruit_LEDBackpack.h"

Adafruit_7segment matrix = Adafruit_7segment();

// pinouts for each 7 segment display
int homeBoard[7] = {2, 3, 4, 5, 6, 7, 8};
int awayBoard[7] = {24, 25, 26, 27, 28, 29, 30};
int periodBoard[7] = {40, 41, 42, 43, 44, 45, 46};

int away;
int home;
int minutesTens;
int minutesOnes;
int secondsTens;
int secondsOnes;
int periodNum;

String data;
String homeScore;
String awayScore;
String period;
String minutes;
String seconds;

void setup() {

  // set the pin mode for the setup
  pinMode(awayDs1, OUTPUT);
  pinMode(awayDs2, OUTPUT);
  pinMode(homeDs1, OUTPUT);
  pinMode(homeDs2, OUTPUT);

  // set all 7 segment display pins to output
  for (int i = 0; i < 9; i++) {
    pinMode(awayBoard[i], OUTPUT);
    pinMode(homeBoard[i], OUTPUT);
    pinMode(periodBoard[i], OUTPUT);
  }

  Serial.begin(115200);
  matrix.begin(0x70);

  // display all 0's on all 7 segment displays to start
  displayNumber[0](awayBoard);
  displayNumber[0](homeBoard);
  displayNumber[0](periodBoard);
  
  matrix.writeDigitNum(0, 0, false);
  matrix.writeDigitNum(1, 0, false);
  matrix.drawColon(true);
  matrix.writeDigitNum(3, 0, false);
  matrix.writeDigitNum(4, 0, false);
  matrix.writeDisplay();
  
}

void loop() {

  if (Serial.available()) {
    
    // if we receive data, parse it
    data = Serial.readStringUntil(',');
    awayScore = Serial.readStringUntil(',');
    homeScore = Serial.readStringUntil(',');
    period = Serial.readStringUntil(',');
    minutes = Serial.readStringUntil(',');
    seconds = Serial.readStringUntil('\n');

    // convert the string data that was parsed into integers
    if(data != "data") return;
    away = awayScore[awayScore.length()-2] - '0';
    home = homeScore[homeScore.length()-2] - '0';
    minutesTens = minutes[0] - '0';
    minutesOnes = minutes[1] - '0';
    secondsTens = seconds[0] - '0';
    secondsOnes = seconds[1] - '0';
    periodNum = period.toInt();

    // display the scores and period
    displayNumber[away](awayBoard);
    displayNumber[home](homeBoard);
    displayNumber[periodNum](periodBoard);

    // display the time
    matrix.writeDigitNum(0, minutesTens, false);
    matrix.writeDigitNum(1, minutesOnes, false);
    matrix.drawColon(true);
    matrix.writeDigitNum(3, secondsTens, false);
    matrix.writeDigitNum(4, secondsOnes, false);
    matrix.writeDisplay();
    
  }
}

I’ve also uploaded here, an image of my Fritzing layout (sorry for the mess of wires).

Any help would be much appreciated. I’m a real novice when it comes to coding.

Thanks

smilliken:
I’ve also uploaded here, an image of my Fritzing layout (sorry for the mess of wires).

Any help would be much appreciated. I’m a real novice when it comes to coding.

  • start new from scrath with one Dual-LED Display only!
  • double check the PIN-Out of your LED
  • if you can’t make it work provide a Link to your display and a link to the datasheet

Thanks for your reply.

- start new from scrath with one Dual-LED Display only!

I’m able to up load a sketch to run the display by itself and it works fine.

- double check the PIN-Out of your LED

Have done this numerous times. They all seem to be in place.

- if you can't make it work provide a Link to your display and a link to the datasheet

I purchased the displays from https://www.amazon.ca/gp/product/B079Q3Z7LN/ref=oh_aui_detailpage_o01_s01?ie=UTF8&psc=1.
http://robojax.com/products.php?pid=500

0.56_2_digit_datasheet_robojax.com.pdf (358 KB)

OUTPUT);

  // set all 7 segment display pins to output
  for (int i = 0; i < 9; i++) {
    pinMode(awayBoard[i], OUTPUT);
    pinMode(homeBoard[i], OUTPUT);
    pinMode(periodBoard[i], OUTPUT);
  }

Those arrays are only 7 elements long but you use them as if they were a 9 element array, so you are setting random pins to outputs as well.

Probably a lot more wrong with this code but like a compiler I stopped looking at the first error I saw.

The classic mistake you made is trying to do too much at once. Start off simply with just one display, get that working and your hardware verified and only then think of adding more hardware and code.