When I first started using the display I multiplexed it and it would print different digits on the respective area with no issue. But now it won't display the digits correctly anymore even with the same code that worked before. I wasn't using resistors at first but now I am using 220 ohms, could that point without the resistors have fried the IC to not work properly anymore?
int latch=10; //74HC595 pin 9 STCP
int clock=11; //74HC595 pin 10 SHCP
int data=9; //74HC595 pin 8 DS
const int digit1 = 7;
const int digit2 = 8;
const int digit3 = 12;
const int digit4 = 13;
const int digitPins[4] = {7, 8, 12, 13};
unsigned char table[]=
{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c
,0x39,0x5e,0x79,0x71,0x00};
void setup() {
pinMode(latch,OUTPUT);
pinMode(clock,OUTPUT);
pinMode(data,OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
}
void Display(unsigned char num, int digitDisplay)
{
digitalWrite(latch,LOW);
shiftOut(data,clock,MSBFIRST,table[num]);
digitalWrite(latch,HIGH);
digitalWrite(digitPins[digitDisplay], LOW);
for(int k = 0; k < 4; k ++){
if (k == digitDisplay)
continue;
else
digitalWrite(digitPins[k], HIGH);
}
}
void loop() {
// integerSensor = 222;
Display(2/*integerSensor%10*/, 3);
delay(1);
Display(4/*integerSensor%100*/, 2);
delay(1);
Display(3/*integerSensor % 1000*/, 1);
delay(1);
Display(12, 0);
delay(1);
}
Yes,
This is a classic example of damage being done but not sufficient damage so that it appears immediately. You are in the grey area where the damage results in not immediate failure but a shortening of the life expectancy of the device.
Think of what happens when you get an over exposure to radioactive radiation. Depending on the dose you might die in two weeks, or two years, or indeed 20 years.
Do you mean that segments are lighting up ok, just not the correct segments? That sounds like wiring errors, rather than chip damage.
Using hexadecimal for the bit patterns isn't very helpful, binary is much more useful, then you can see the 1s and 0s that indicate if each segment will be lit.
unsigned char table[]= {
// AAA
// F B
// F B
// F B
// GGG
// E C
// E C
// E C
// DDD
// GFEDCBA
0b00111111, // 0
0b00000110, // 1
0b01011011, // 2
0b01001111, // 3
...
};
Now it is converted from hex to binary, I can see that your code is using the standard encoding for 7-seg displays, with bit 0 for the A segment and bit 6 for the G segment. Bit 7 is not used, you may have it connected to the decimal points on your displays?
Your code is shifting out the Most-Significant-Bit-FIRST, which means first will be bit 7 (unused or decimal point), followed by bit 6 (G segment) and so on until finally bit 0 (A segment).
We can see that the first bit to be shifted in will appear at output Q7 once all 8 bits have been shifted. So in terms of wiring, you should connect segment A of your display to Q0, segment B to Q1 and so on, so that segment G is connected to Q6. Q7 can be left unconnected or connected to the decimal point if you want that.
As had been pointed out, these may be too low. If we assume your displays are red LEDs and have a forward voltage of around 1.8V, and the supply voltage is 5V, then the current that will flow through each segment would be (5-1.8)/220 = 14.5mA.
If 7 segments are lit, like when a "8" is displayed, the total current flowing out of the shift register would be 102mA. The maximum allowed, according to the data sheet, is 70mA. More than that will cause damage, which as Mike said, could be sudden and total, or could be slow and gradual.
For long life of components, it's always wise to steer clear of maximum ratings. I like to keep to 80% or less. For 74hc595, that means 56mA in total, or 8mA for each of 7 segments. For this, the resistors need to be (5-1.8)/0.08 = 400R. The nearest standard resistor value above that is 470R. With 470R, the current through each segment would be (5-1.8)/470 = 6.8mA
But what about the Arduino pins connected to the digit commons? Are they within their maximum current? If a digit is showing an "8", then the Arduino pin must have 7*6.8 = 47mA. The maximum current for an Arduino pin depends on the type of Arduino, but for most 5V Arduino, it's 40mA. So, again, damage to the arduino chip.
To get to 80% or below, which is 32mA, you can only have about 32/7 = 4.6mA per segment.
None of this maths is difficult, you can do it easily. So what value of series resistor would you calculate to achieve 4.6mA?