problem with 7 segment display and shift register

I'm using a 74HC595 shift register to control a 7 segment display. I'm having issue with the 1, 4, 7, and 8 displaying right. I have went through each one to test them alone and they work just find. Just when I run it in an array is when they mess up. This is how its setup up when I turn each pin on one at a time. I'm not using Q0 on the chip just Q1-7.


F=1 A=2 B=3 C=4 D=5 E=6 G=7

for 1 it light up F,B,C
for 4 it light up B,G,C
for 7 it light up F,A,B,C
for 8 it light up A,B,C,D,E,G

int dataPin = 11;
int clockPin = 12;
int latchPin = 8;

byte data;
 
byte dataArray[9];
 
void setup() {
 
  //set pins to output because they are addressed in the main loop
  pinMode(latchPin, OUTPUT);
 
  //Using Hex decimal
  dataArray[0] = 0x7E; //0111 1110   - 0
  dataArray[1] = 0x18; //0001 1000   - 1
  dataArray[2] = 0xEC; //1110 1100   - 2
  dataArray[3] = 0xBC; //1011 1100   - 3
  dataArray[4] = 0x9A; //1001 1010   - 4
  dataArray[5] = 0xB6; //1011 0110   - 5
  dataArray[6] = 0xF2; //1111 0010   - 6
  dataArray[7] = 0x1C; //0001 1100   - 7
  dataArray[8] = 0xFE; //1111 1110   - 8
}
 
void loop() {
 
for (int i = 0; i<9; i++)
{
 
  data = dataArray[i];
 
    //ground latchPin and hold low for as long as you are transmitting
 
    digitalWrite(latchPin, 0);
    //move 'em out
 
    shiftOut(dataPin, clockPin, data);
    //return the latch pin high to signal chip that it
    //no longer needs to listen for information
    digitalWrite(latchPin, 1);
    delay(300);
 
  delay(1000);
}
 
}
 
// the heart of the program
void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {
  // This shifts 8 bits out MSB first,
  //on the rising edge of the clock,
  //clock idles low
 
  //internal function setup
  int i=0;
  int pinState;
  pinMode(myClockPin, OUTPUT);
  pinMode(myDataPin, OUTPUT);
 
  //clear everything out just in case to
  //prepare shift register for bit shifting
  digitalWrite(myDataPin, 0);
  digitalWrite(myClockPin, 0);
 
  //for each bit in the byte myDataOut?
  //NOTICE THAT WE ARE COUNTING DOWN in our for loop
  //This means that %00000001 or "1" will go through such
  //that it will be pin Q0 that lights.
  for (i=7; i>0; i--)
  {
    digitalWrite(myClockPin, 0);
 
    //if the value passed to myDataOut and a bitmask result
    // true then... so if we are at i=6 and our value is
    // %11010100 it would the code compares it to %01000000
    // and proceeds to set pinState to 1.
    if (myDataOut & (1<<i))
    {
      pinState= 1;
    }
    else
    {
      pinState= 0;
    }
 
    //Sets the pin to HIGH or LOW depending on pinState
    digitalWrite(myDataPin, pinState);
    //register shifts bits on upstroke of clock pin
    digitalWrite(myClockPin, 1);
    //zero the data pin after shift to prevent bleed through
    digitalWrite(myDataPin, 0);
  }
 
  //stop shifting
  digitalWrite(myClockPin, 0);
}

The simplest way is if you just change the program to output only one segment at a time in a sort of walking one:-

dataArray[0] = 0x0; // no segments on
  dataArray[1] = 0x2; // F
  dataArray[2] = 0x4; //
  dataArray[3] = 0x8; //
  dataArray[4] = 0x10; //
  dataArray[5] = 0x20; //
  dataArray[6] = 0x40; //
  dataArray[7] = 0x80; //
  dataArray[8] = 0x00; //

To see what you have miss wired.

Normally I would expect to see:-
A=1 B=2 C=3 D=4 E=5 F=6 G=7
as the wiring

(Well actually A=0 B=1 C=2 D=3 E=4 F=5 G=6 DP=7)

I did them one at a time to see what light what up and this is what I got:

0x80 = G
0x40 = E
0x20 = D
0x10 = C
0x08 = B
0x04 = A
0x02 = F

So, now you should be able to use those values to light up the correct segments for each digit, by changing the values in dataArray.

Like I said at the first post I did all this before making this topic.
0x08 = B
0x10 = C
So 0x18 will light up B & C and that would be 1. I can go through and run each number by itself and they all work fine. Its just when I run it in an array it messes up on those number for some reason. So I'm wondering why its doing that.

So, when you pass shiftOut the valie in dataArray[7] (which should display an 8), you get the wrong segments lit?

I'd add a Serial.print(ln) statement after valuing data, to see what value it is actually getting.

Nothing jumps out at me as being wrong, so I'd keep adding debug prints until I figured out where the error was occurring.

You shift out function is a bit complex an unnecessary although it should still work. I would remove:-
//zero the data pin after shift to prevent bleed through
digitalWrite(myDataPin, 0);
and
/clear everything out just in case to
//prepare shift register for bit shifting
digitalWrite(myDataPin, 0);
digitalWrite(myClockPin, 0);
also remove
//stop shifting
digitalWrite(myClockPin, 0);

and also move this bit so it is in the setup not your shift out:-
pinMode(myClockPin, OUTPUT);
pinMode(myDataPin, OUTPUT);