I’ve got my scoreboard project nearing completion. I am having a problem though. Random segments will light up and turn off. For instance, I had a test program that just counted up from 00 to 99, with a new number each second. Some numbers would display just fine (like, 02) and then next time through, the 2 might be missing the lower tail. Or one of the segments that isn’t supposed to be lighted, would be.
Somehow it seems to be related to the number of segments that are supposed to be lighted. For instance, sixes, nines and eights almost always have segments missing, but 11 never has a problem. I know my encoding is right (that is, which segments go with which numbers) because a lot of times it will work fine. Of course, I want it to work right all the time.
I am powering the board with a 4S LiPo battery and a 12v and and 9v voltage regulator for the display and arduino respectively.
Based on the symptoms where it seemed to be related to the number of segments, that made me think it was a power problem, so I tried using two batteries, a 5000maH 4S LiPo for the display and a 2100maH 4S LiPo for the arduino. Still, same symptoms.
There are no switches wired up to the board yet. All I am trying to do at this point is successfully count to 99. When I see things happen randomly, it makes me think of a switch that isn’t properly pulled down/up, but that isn’t the case right now.
Here’s the code, but since it works a lot of the time, I don’t think it is code-related. I am really inclined to think it is hardware related.
// Scoreboard is wired like this:
//
// A Green
// --------------
// | |
// | B Lt | C Brown
// | Green |
// | |
// -------------- D Lt Brown
// | |
// | E Orange | F Lt Orange
// | |
// | |
// --------------
// G Blue
//
// Segments are wired in order. A (Green) is connected
// to output 0. And G (Blue) is connect to output 6.
// Output 7 is not used.
//
// A 0000 0001 -- 1
// B 0000 0010 -- 2
// C 0000 0100 -- 4
// D 0000 1000 -- 8
// E 0001 0000 -- 16
// F 0010 0000 -- 32
// G 0100 0000 -- 64
// Digits are made like this:
//
// GFE DCBA
// 0 GFE CBA 0111 0111 -- 119d 77h
// 1 F C 0010 0100 -- 36d 24h
// 2 G EDC A 0101 1101 -- 93d 5Dh
// 3 GF DC A 0110 1101 -- 109d 6Dh
// 4 F DCB 0010 1110 -- 46d 2Eh
// 5 GF D BA 0110 1011 -- 107d 6Bh
// 6 GFED BA 0111 1011 -- 123d 7Bh
// 7 F C A 0010 0101 -- 37d 25h
// 8 GFEDCBA 0111 1111 -- 127d 7Fh
// 9 GF DCBA 0110 1111 -- 111d 6Fh
int encodedSsd[] = {
119,
36,
93,
109,
46,
107,
123,
37,
127,
111
};
//Pin connected to RCK (ST_CP) of TPIC (Pin 7)
int latchPin = 8;
//Pin connected to SRCK (SH_CP) of TPIC (Pin 8)
int clockPin = 11;
////Pin connected to SER IN (DS) of TPIC (Pin 18)
int dataPin = 10;
//Pin 8, 10, 11
void setup() {
Serial.begin(9600);
//set pins to output so you can control the shift register
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void loop() {
for (int i=0; i<100; i++) {
DisplayFourDigitScore(i, i);
delay(1000);
}
}
void DisplayFourDigitScore(int homescore, int guestscore) {
int homeOnesDigit = homescore % 10;
int homeTensDigit = (homescore - homeOnesDigit) / 10;
int guestOnesDigit = guestscore % 10;
int guestTensDigit = (guestscore - guestOnesDigit) / 10;
digitalWrite(latchPin, LOW);
// shift out the bits:
shiftOut(dataPin, clockPin, MSBFIRST, encodedSsd[homeOnesDigit]);
shiftOut(dataPin, clockPin, MSBFIRST, encodedSsd[homeTensDigit]);
shiftOut(dataPin, clockPin, MSBFIRST, encodedSsd[guestOnesDigit]);
shiftOut(dataPin, clockPin, MSBFIRST, encodedSsd[guestTensDigit]);
//take the latch pin high so the LEDs will light up:
digitalWrite(latchPin, HIGH);
}