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?
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.
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
}
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.
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.
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...
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.
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.
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.
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.
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.