Having trouble controlling 3 Row Seven Segment with 4 shift register 74hc595

paulRb, one more question of new case,

how to hold the first number in first digit, and the second digit show a second number, i've a trouble to keep first digit. show only a second digit from two number. can u give me simple code to keep/hold that first number in first digit?

or

maybe can you show me the code if the case is:

Row 1 (top, with 6 digits) show number "123.456"
Row 2 (middle with 4 digit) show "78.90"
Row 3 (bottom, with 5 digit) show "12.456"

I'm trying to learn the code.

zifank:
I've changed the code in the post #25,
and add the code in the post #33. the result is like in the video above

No, it is not. I am not stupid. I can see that the video is not my code running. It is your code running. I said that in post #35. I asked you to describe what happens when you run my code. Until you do as I ask, I will give you no more help.

sorry paul, Why should I lie to you?

int latchPin = 4;
int clockPin = 3;
int dataPin = 2;

// digits from the right
const byte digit[10] =      //seven segment digits in bits
{
  B10000001,  // 0
  B11110011,  // 1
  B01001001,  // 2
  B01100001,  // 3
  B00110011,  // 4
  B00100101,  // 5
  B00000101,  // 6
  B11110001,  // 7
  B00000001,  // 8  fix
  B00100001,  // 9
};

byte displayBuffer[3][6] =    //digit to display in each position
{
  {0, 1, 2, 3, 4, 5},
  {0, 1, 2, 3, 4, 5},
 {0, 1, 2, 3, 4, 5},
};



void setup()
{
  Serial.begin(9600);
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  
}

void loop()
{
  
  updateShiftRegister();

}

void sevoff() {
  static byte column; // the column currently being lit
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, 1 << (column + 5)); // send the column enable mask
  for (byte row = 0; row < 3; row++) // update each row for the current column
  {
    shiftOut(dataPin, clockPin, MSBFIRST, B00000000);// send the segment data for each row

  }
  digitalWrite(latchPin, HIGH);
}


void updateShiftRegister()
{
  // "static" variables do not loose their value when the function ends
  static unsigned long lastUpdateTime; // time from millis() when the dispaly was last updated
  static byte column; // the column currently being lit

  if (millis() - lastUpdateTime > 3)  // is it time to light the next column?
  {
    // form code post#25
    //digitalWrite(latchPin, LOW);
    //for (byte row = 0; row < 3; row++) // update each row for the current column
    //{
      //byte d = displayBuffer[row][column]; // get the required digit for this row & column
      //shiftOut(dataPin, clockPin, MSBFIRST, digit[d]); // send the segment data for each row
    //}
    //shiftOut(dataPin, clockPin, MSBFIRST, 1 << column); // send the column enable mask
    //digitalWrite(latchPin, HIGH);
    //end code post #25

    //from code post #33
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, 1 << (column+1)); // send the column enable mask
    for (byte row = 0; row < 3; row++) // update each row for the current column
    {
      byte d = displayBuffer[row][column]; // get the required digit for this row & column
      shiftOut(dataPin, clockPin, MSBFIRST, digit[d]); // send the segment data for each row
    }
    digitalWrite(latchPin, HIGH);
    //end code post #3
    delay(1000); 

    column++; // next time, we will light the next column
    if (column > 5) column = 0;
    lastUpdateTime = millis();
  }
}

video test 3
- YouTube?

Ok.

Change this line:

    shiftOut(dataPin, clockPin, MSBFIRST, 1 << (column+2)); // send the column enable mask

this is the test 5, i changed from post#42

int latchPin = 4;
int clockPin = 3;
int dataPin = 2;

// digits from the right
const byte digit[10] =      //seven segment digits in bits
{
  B10000001,  // 0
  B11110011,  // 1
  B01001001,  // 2
  B01100001,  // 3
  B00110011,  // 4
  B00100101,  // 5
  B00000101,  // 6
  B11110001,  // 7
  B00000001,  // 8  fix
  B00100001,  // 9
};

byte displayBuffer[3][6] =    //digit to display in each position
{
  {1, 1, 1, 1, 1, 1},
  {2, 2, 2, 2, 2, 2},
  {3, 3, 3, 3, 3, 3},
};



void setup()
{
  Serial.begin(9600);
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(clockPin, OUTPUT);


}

void loop()
{
  updateShiftRegister();
}


void updateShiftRegister()
{
  // "static" variables do not loose their value when the function ends
  static unsigned long lastUpdateTime; // time from millis() when the dispaly was last updated
  static byte column; // the column currently being lit

  if (millis() - lastUpdateTime > 3)  // is it time to light the next column?
  {
    //from code post #33
    digitalWrite(latchPin, LOW);
    //from code post #42
    shiftOut(dataPin, clockPin, MSBFIRST, 1 << (column+2)); // send the column enable mask //coloum
    for (byte row = 0; row < 3; row++) // update each row for the current column
    {
      byte d = displayBuffer[row][column]; // get the required digit for this row & column
      shiftOut(dataPin, clockPin, MSBFIRST, digit[d]); // send the segment data for each row
    }
    digitalWrite(latchPin, HIGH);
    //end code post #33

    column++; // next time, we will light the next column
    if (column > 6) column = 0;
    lastUpdateTime = millis();
  }
}

the video result is

You changed this line:

    if (column > 6) column = 0;

but I do not think correcting that will fix the display.

Did you make other changes that I have not detected?

Put that delay(1000) back into updateShiftRegister(). Check that each column lights in turn, on all 3 rows. Then reduce to delay(500), then delay(250), delay(125), delay(63) and so on. At what point does the display to crazy like in your last video?

yes i change, length of digit is 6 digit/rows,
and i change to this value too:

byte displayBuffer[3][6] =    //digit to display in each position
{
  {1, 1, 1, 1, 1, 1},
  {2, 2, 2, 2, 2, 2},
  {3, 3, 3, 3, 3, 3}, 
};

I said, in a much easier post, that I think there are components missing from your board. I am beginning to think that might be part of the problem. Very close to each shift register chip, there are two holes. Can you solder 0.1uF ceramic capacitors there?

PaulRB:
Put that delay(1000) back into updateShiftRegister(). Check that each column lights in turn, on all 3 rows. Then reduce to delay(500), then delay(250), delay(125), delay(63) and so on. At what point does the display to crazy like in your last video?

What this case is called the flicker/ghosting/dimming?

oke. i'll try your advise to add delay for each column

zifank:
yes i change, length of digit is 6 digit/rows,

The length of the array is 6 but the indexes are 0 to 5. So 6 is not a valid index.

PaulRB:
I said, in a much easier post, that I think there are components missing from your board. I am beginning to think that might be part of the problem. Very close to each shift register chip, there are two holes. Can you solder 0.1uF ceramic capacitors there?

oke, i'll do that

hi PaulRB, All Problem Solved. flicker solved by change a power+Gnd to 5V from Arduino power pin :slight_smile:

result pic:

and the working code is from you.

int latchPin = 4;
int clockPin = 3;
int dataPin = 2;

const byte digit[11] =      //seven segment digits in bits
{
  B10000001,  // 0  129 0x81
  B11110011,  // 1  243 0xF3
  B01001001,  // 2   73 0x49
  B01100001,  // 3  97 0x61
  B00110011,  // 4  51 0x33
  B00100101,  // 5  37 0x25
  B00000101,  // 6  5 0x5
  B11110001,  // 7  241 0xF1
  B00000001,  // 8  1 0x1
  B00100001,  // 9  33 0x21
  B11111111,  // BLANK
};

byte displayBuffer[3][6] =    //digit to display in each position
{
  {2, 2, 2, 2, 2, 2},
  {0, 0, 6, 7, 8, 9},
  {0, 1, 2, 3, 4, 5},
};

void setup()
{
  Serial.begin(9600);
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
}

void loop()
{
  updateShiftRegister();
}
static unsigned long lastUpdateTime; // time from millis() when the dispaly was last updated
static byte column; // the column currently being lit

void updateShiftRegister()
{
  if (millis() - lastUpdateTime > 0)
  {

    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, 1 << (column));
    for (byte row = 0; row < 3; row++)
    {
      byte d = displayBuffer[row][column];
      shiftOut(dataPin, clockPin, MSBFIRST, digit[d]);
    }
    digitalWrite(latchPin, HIGH);
    column++;
    if (column > 5) column = 0;
    lastUpdateTime = millis();
  }
}

thanks for God and you PaulRB...


Great news.

So what power supply was it using when the flickering was happening?

i used this paul, the site tell the 9V 1A Power Adapter for Arduino (2-Flat-Pin Plug / 100CM Cable)

Was that powering the display directly when it was flickering? The display does not seem to have its own voltage regulator. 9V could have fried it. Or did you power the Arduino with that PSU and then power the display from the 5V pin on the Arduino? The Arduino's regulator may have been overloaded.

And you are powering the Arduino and display from USB power now?

PaulRB:
Was that powering the display directly when it was flickering? The display does not seem to have its own voltage regulator. 9V could have fried it. Or did you power the Arduino with that PSU and then power the display from the 5V pin on the Arduino? The Arduino's regulator may have been overloaded.

And you are powering the Arduino and display from USB power now?

yes, the display flickering when connect to Adapter 9V. now, i don't use that adapter. Arduino only use USB cable power from my USB Laptop.

zifank:
yes, the display flickering when connect to Adapter 9V.

Yes, you must use a regulated 5V supply with the display. I think you were very lucky that the display was not permanently damaged by connecting it to a 9V supply. 9V exceeds the safe limit for the chips and leds on the display.

Ok PaulRB. thanks for everything..

but I've one problem again, i've a one Water Flow sensor connect to Arduino with pin 11, the sensor result is work perfectly on arduino uno or mega.
but when i try to upload with USBasp to Atmega32 in pin PD3. the sensor can't show the flow sensor result.
how to solved this? this problem stuck from two month ago. :confused:

(maybe, i must change/move this post to sensor category post)