Questions about 8x8 Dot Matrix Display

Hello everyone,

I'm currently working on Project 19(Led Dot Matrix Display - Basic Animation) with the Beginning Arduino book, but I have a few questions:
The matrix display that I am using is this one: LED Matrix - Dual Color - Medium - COM-00682 - SparkFun Electronics

  1. In the book they mention in the parts list to use a common anode matrix display, but I have a common cathode. Does this matter?
  2. I don't understand the wiring of the dot matrix display, and the datasheet of it does not show the information for the wiring.
    So I seached on google for some information, and found the following: http://www.glowseed.com/mindmash/wp-content/uploads/2009/05/pins-led-matrix-dual-color-medium.pdf , but this seems not to work with the code from the book. Maybe because I wire it wrong or because it's a dual color display, and in the book they use a single color display.
  3. In the book they use a single color matrix display, but I have a dual color display. Does this matter and will the following code work then?:
// Project 19
#include <TimerOne.h>

int latchPin = 8; //Pin connected to Pin 12 of 74HC595 (Latch)
int clockPin = 12; //Pin connected to Pin 11 of 74HC595 (Clock)
int dataPin = 11; //Pin connected to Pin 14 of 74HC595 (Data)

byte led[8];  // 8 element unsigned integer array to store the sprite

void setup() {
        pinMode(latchPin, OUTPUT);  // set the 3 digital pins to outputs
        pinMode(clockPin, OUTPUT);
        pinMode(dataPin, OUTPUT);
        led[0] = B11111111;  // enter the binary representation of the image
        led[1] = B10000001;  // into the array
        led[2] = B10111101;
        led[3] = B10100101;
        led[4] = B10100101;
        led[5] = B10111101;
        led[6] = B10000001;
        led[7] = B11111111;
        // set a timer of length 10000 microseconds (1/100th of a second)
        Timer1.initialize(10000); 
        // attach the screenUpdate function to the interrupt timer
        Timer1.attachInterrupt(screenUpdate); 
}

void loop() {
        for (int i=0; i<8; i++) {
                led[i]= ~led[i]; // invert each row of the binary image
        }
        delay(500);
}

void screenUpdate() { // function to display image
        byte row = B10000000; // row 1
        for (byte k = 0; k < 9; k++) {
                digitalWrite(latchPin, LOW); // open latch ready to receive data
        shiftIt(~led[k] ); // shift out the LED array (inverted)
        shiftIt(row ); // shift out row binary number 

        // Close the latch, sending the data in the registers out to the matrix
        digitalWrite(latchPin, HIGH);     
        row = row << 1; // bitshift left
        }
}

void shiftIt(byte dataOut) {    // Shift out 8 bits LSB first, on rising edge of clock

        boolean pinState; 
        digitalWrite(dataPin, LOW); //clear shift register read for sending data

        for (int i=0; i<8; i++)  {    // for each bit in dataOut send out a bit
                digitalWrite(clockPin, LOW); //set clockPin to LOW prior to sending bit

                // if the value of DataOut and (logical AND) a bitmask
                // are true, set pinState to 1 (HIGH)
                if ( dataOut & (1<<i) ) {
                               pinState = HIGH;
                }
                else {
                        pinState = LOW;
                }
                //sets dataPin to HIGH or LOW depending on pinState
                digitalWrite(dataPin, pinState); 
                digitalWrite(clockPin, HIGH); //send bit out on rising edge of clock 
                digitalWrite(dataPin, LOW);
        }
digitalWrite(clockPin, LOW); //stop shifting
}

I'm using 2x 74HC595 Shift registers.

Regards,
Tibo

  1. It's a matrix so (for each color) it has 8 common anodes and 8 common cathodes.

  2. The wiring diagram is in the data sheet: http://www.sparkfun.com/datasheets/Components/SanYoung-Medium-RG.pdf

Cathode (-) pins: 1 2 3 4 21 22 23 14
Anode (+) pins: 5 6 7 8 9 10 11 12 or 20 19 18 17 16 15 14 13

To use both colors you will need another shift register for the 8 additional anodes.

I'm surprised the code works with 'row' initialized to B10000000 and using << 1 to get to the next row. I would think that initializing to 1 OR using >> instead of << would be the only way to get more than one row working.

  1. In the book they mention in the parts list to use a common anode matrix display, but I have a common cathode. Does this matter?

Yes, it matters. At a minimum, you have to wire the cathode to ground (instead of anode to 5V) and the signal pins to digital outs that go HIGH to turn on the segment (not low, as with common anode)
If the dot-matrix is also matrixed, you may get a similar switch in the row/column control, too.
Thus, both wiring and code should change to adjust for the difference.

Then it's maybe better to buy a new common anode display, because I don't have the experience to change the code.

shiftIt(~led[k] ); // shift out the LED array (inverted)

I believe taking out the "~" is the only change that needs to be made. The ~ inverts the bits so that the image you had up top will be low for a 1 and high for a 0. For the common cathode, they will need to be driven high for 1 and low for 0 for you to get the desired image.

TiboJ:
Then it's maybe better to buy a new common anode display, because I don't have the experience to change the code.

Can't learn if you just copy the examples can you?

I believe taking out the "~" is the only change that needs to be made.  The ~ inverts the bits so that the image you had up top will be low for a 1 and high for a 0.  For the common cathode, they will need to be driven high for 1 and low for 0 for you to get the desired image.

I will try this after I got the display wired the right way, because that is a big challenge... :slight_smile:

Can't learn if you just copy the examples can you?

What do you mean?
I always type them from the book by myself, and then try to understand each line. That way I learn very much.

I still not have it working...

The code should display an animated hearth, but only the half of the display lights up now and the leds are just flickering a little. They're also not bright.

Are you sure it's not supposed to be

byte row = B10000000;
.
.
.
row = row >> 1;

or

byte row = B00000001;
.
.
.
row = row << 1;

(basically what johnwasser said at the end of his post)

I will try this after I've finished my exams :wink:

war_spigot:
Are you sure it's not supposed to be

byte row = B10000000;

.
.
.
row = row >> 1;




or


byte row = B00000001;
.
.
.
row = row << 1;




(basically what johnwasser said at the end of his post)

That also doesn't work, even when removing the '~'.
So my wiring is probably wrong.

I will make a wiring diagram with Fritzing of the wiring and post it soon.

Here is my wiring:

I may be wrong, but if there's two shift registers do you not need either two latch or two clock pins? I haven't really worked with them before, but from my understanding, wiring like this would make both registers shift out the same thing. Wouldn't that mean LEDs that should be on (high on anode, low on cathode) would really still be off(high on both or low on both)?
Also, are you sure the matrix is in the correct orientation, looking at the data sheet, the outward notches should be on the left and top side while looking down from above.

@TiboJ

I also did a led matrix project using 3 74HC595. But before I connect the matrix to the shift register and coding, I test the connection first to see if it is working by at least lighting one led to test it.

The matrix I was using is a commun anode type, I did not have a datasheet, so I make one. So in your case, it will be different pinout or maybe the same... you have to test your to see what leds is what.

And the moment you draw a datasheet, than you will be able to connected properly the matrix and use the 74HC595's.

I may be wrong, but if there's two shift registers do you not need either two latch or two clock pins?

In the book the two shift registers are connected to each other, so I assume it would be the same here because I'm also using the same code.

Also, are you sure the matrix is in the correct orientation, looking at the data sheet, the outward notches should be on the left and top side while looking down from above

It is in the correct orientation, but it is possbible that my wiring is incorrect.

I also did a led matrix project using 3 74HC595. But before I connect the matrix to the shift register and coding, I test the connection first to see if it is working by at least lighting one led to test it.

The matrix I was using is a commun anode type, I did not have a datasheet, so I make one. So in your case, it will be different pinout or maybe the same... you have to test your to see what leds is what.

And the moment you draw a datasheet, than you will be able to connected properly the matrix and use the 74HC595's.

What code should I use to test the leds?
Maybe this is all a bit to difficult for me and should I start with an easier project with shift registers.

I already would like to thank you all for the help!

Testing a Matrix .... with a code... <---- After I check all the pins.

First. I don't use a code. I use 1 470 ohm resistor, +5 V, gnd, some wires. I connect the 5 V to a resistor, a wire to a led pin, and a wire to a another led pin to gnd. I move the resitor wire to EACH pins to see a light. If not, I reversed the polarity, do the same procedure until I see a led on. If found, check for a commun pin <-- A CC or CA. Than I know the polarity, I check every pin for each leds. I marked down the led pin on paper.

Techone:
Testing a Matrix .... with a code... <---- After I check all the pins.

First. I don't use a code. I use 1 470 ohm resistor, +5 V, gnd, some wires. I connect the 5 V to a resistor, a wire to a led pin, and a wire to a another led pin to gnd. I move the resitor wire to EACH pins to see a light. If not, I reversed the polarity, do the same procedure until I see a led on. If found, check for a commun pin <-- A CC or CA. Than I know the polarity, I check every pin for each leds. I marked down the led pin on paper.

Thank you! I managed to find all the right pins!
Now I'm going to put the result into a nice datasheet and then wire it all up again, and try the code.

I finally managed to make it work.
The code from the book was not working right, so I used another code.
And now it is working!

Thank you all for the help :slight_smile:

Hi, I am having the exact same problem as you are having with project 19 in the same book!!!
You say the code in the book is wrong and you used another code that works.
My question to you is what code did you use to make this work. This is the only chapter (so far) that I have had problems with. Please post the code.

Thanks,
GIC1

Sorry, but I don't remember which code I used.
I just searched on Google for some tutorials.
Good luck!