Hello!
I've got a problem with interfacing my 5x7 Matrix. It is cotrolled by two 595 shiftregisters (one for the columns,one for the rows).
I wrote some code, that scrolls through a given message (though I removed the scrolling part for this thread, as the problem also occurs without it):
#define resolution_x 5 //x pixels of matrix
#define resolution_y 7 //y pixels of matrix
byte spacing = 1;
int textspeed = 500; //smaller is faster! determines speed of scrolling
byte latch = 2; //common latchpin
byte data_c = 3; //data Pin for columns
byte clock_c = 4; //clock Pin for columns
byte data_r = 5; //data Pin for rows
byte clock_r = 6; //clock Pin for rows
byte array_c[resolution_x]; //initialization for column mask
byte A[] = {0x7E, 0x09, 0x09, 0x09, 0x7E}; //byte arrays for letters and symbols
byte B[] = {0x7F, 0x49, 0x49, 0x49, 0x36};
byte C[] = {0x3E, 0x41, 0x41, 0x41, 0x41};
byte D[] = {0x7F, 0x41, 0x41, 0x41, 0x3E};
byte E[] = {0x7F, 0x49, 0x49, 0x49, 0x41};
byte F[] = {0x7F, 0x09, 0x09, 0x09, 0x01};
byte G[] = {0x7E, 0x41, 0x49, 0x49, 0x39};
byte H[] = {0x7F, 0x08, 0x08, 0x08, 0x7F};
byte I[] = {0x00, 0x41, 0x7F, 0x41, 0x00};
byte J[] = {0x21, 0x41, 0x41, 0x41, 0x3F};
byte K[] = {0x7F, 0x08, 0x08, 0x14, 0x63};
byte L[] = {0x7F, 0x40, 0x40, 0x40, 0x40};
byte M[] = {0x7F, 0x02, 0x04, 0x02, 0x7F};
byte N[] = {0x7F, 0x04, 0x08, 0x10, 0x7F};
byte O[] = {0x3E, 0x41, 0x41, 0x41, 0x3E};
byte P[] = {0x7F, 0x09, 0x09, 0x09, 0x06};
byte Q[] = {0x3E, 0x41, 0x51, 0x21, 0x5E};
byte R[] = {0x7F, 0x09, 0x09, 0x09, 0x76};
byte S[] = {0x46, 0x49, 0x49, 0x49, 0x31};
byte T[] = {0x01, 0x01, 0x7F, 0x01, 0x01};
byte U[] = {0x3F, 0x40, 0x40, 0x40, 0x3F};
byte V[] = {0x1F, 0x20, 0x40, 0x20, 0x1F};
byte W[] = {0x7F, 0x20, 0x10, 0x20, 0x7F};
byte X[] = {0x63, 0x14, 0x08, 0x14, 0x63};
byte Y[] = {0x03, 0x04, 0x78, 0x04, 0x03};
byte Z[] = {0x61, 0x51, 0x49, 0x45, 0x43};
byte _[] = {0x00, 0x00, 0x00, 0x00, 0x00};
byte OFF[] = {0x00, 0x00, 0x00, 0x00, 0x00};
byte ONE[] = {0x00, 0x01, 0x7F, 0x00, 0x00};
byte TWO[] = {0x79, 0x49, 0x49, 0x49, 0x4F};
byte THREE[] = {0x49, 0x49, 0x49, 0x49, 0x7F};
byte FOUR[] = {0x0F, 0x08, 0x08, 0x08, 0x7F};
byte FIVE[] = {0x4F, 0x49, 0x49, 0x49, 0x79};
byte SIX[] = {0x7F, 0x49, 0x49, 0x49, 0x79};
byte SEVEN[] = {0x01, 0x01, 0x09, 0x09, 0x7F};
byte EIGHT[] = {0x7F, 0x49, 0x49, 0x49, 0x7F};
byte NINE[] = {0x4F, 0x49, 0x49, 0x49, 0x7F};
byte ZERO[] = {0x7F, 0x45, 0x49, 0x51, 0x7F};
byte EXCL[] = {0x00, 0x00, 0x5F, 0x00, 0x00}; //exclamation mark("!")
byte FSTOP[] = {0x00, 0x60, 0x60, 0x00, 0x00}; //full stop (".")
byte KOMMA[] = {0x00, 0x20, 0x60, 0x00, 0x00}; //komma (",")
byte HEART[] = {0x0C, 0x12, 0x24, 0x12, 0x0C}; //heart symbol
byte* message[] = {OFF, A, B, C, D, E, OFF, _, F, G, H, I, OFF, _};
void setup(){
pinMode(data_c, OUTPUT); //set pins to output (data, clock and latch for row- and column-shift-registers
pinMode(latch, OUTPUT); //(could obviously be reduced to 5 pins: data1, data2, clock1, clock2 and a common latch)
pinMode(clock_c, OUTPUT);
pinMode(data_r, OUTPUT);
pinMode(clock_r, OUTPUT);
array_c[0] = 0xFE; //1111 1110 //masking array to always just let one column at a time conduct
array_c[1] = 0xFD; //1111 1101 //(these are sinking current, so 0 is on and 1 is off)
array_c[2] = 0xFB; //1111 1011
array_c[3] = 0xF7; //1111 0111
array_c[4] = 0xEF; //1110 1111
array_c[5] = 0xDF; //1101 1111
array_c[6] = 0xBF; //1011 1111
array_c[7] = 0x7F; //0111 1111
}
void loop(){
for(int j=0; j<14; j++){
for(int counter=0; counter<textspeed; counter++){
for(int i=0; i<resolution_x; i++){ //cycle through columns 1 to 5 (0 to 4 in the array)
digitalWrite(latch, LOW); //pull latches down for shifting data in
shiftOut(data_c, clock_c, MSBFIRST, array_c[i]);
shiftOut(data_r, clock_r, MSBFIRST, message[j][i]);
digitalWrite(latch, HIGH);
}
}
}
}
Every character is written fine, everything works like a charm, besides one thing: the space character ("_[]"). There's garbage displayed in the first three columns, the last 2 are empty as they should:
You noticed I doubled the space character, right? I put in another one ("OFF[]"), which works fine (all 5 columns are empty as they should). Strange enough, this only works if I have _[] declared, too, and included somewhere in my message[] pointer.
Furthermore, if i replace one of the letters declared before _[] and OFF[] by 0x00 (say, for example: A[] = {0x00, 0x00, 0x00, 0x00, 0x00}), then this space character is the same garbage, but both _[] and OFF[] work fine.
To summarize it up: the first character in the sketch to be declared as {0x00, 0x00, 0x00, 0x00, 0x00} gets messed up, every space character after that first one works fine.
This drives me crazy! I've been trying to solve the problem for hours now.
Is there a problem with declaring arrays as only containing 0x00?
Is it a RAM-problem? (I don't think so, because this sketch is significantly smaller than the original one and the problem occurs nonetheless...).
Any ideas anyone?
Thanks, Otacon2k