Matrix problem

OK, I copied the font data from your old sketch and re-organised it into a single array, with the characters appearing in the exact same order as the ASCII set above.

[code] byte font[][6] = {  {B11111111, B11111111, B11111111, B11111111, B11111111, B11111111 },    // SPACE ' '  {B11111111, B11111111, B00000101, B11111111, B11111111, B11111111 },    // EXCLAMATION MARK '!'  {B11111111, B11111111, B11111111, B11111111, B11111111, B11111111 },    // QUOTATION MARK '"'  {B11111111, B11111111, B11111111, B11111111, B11111111, B11111111 },    // NUMBER SIGN '#'  {B11111111, B10011101, B01101101, B00000001, B01101101, B01110011 },    // DOLLER ' [/code]

Can you check this please? Have I got the sequence exactly the same as the ASCII set, not missing or inserting any?  {B11111111, B10111011, B11110111, B11101111, B11011111, B10111011 },    // PERCENT '%'  {B11111111, B10010011, B01101101, B01100101, B10011011, B11110101 },    // AND '&'  {B11111111, B11111111, B11111111, B11111111, B11111111, B11111111 },    // APOSTROPHE '''  {B11111111, B11111111, B11111111, B10000011, B01111101, B11111111 },    // BRACKET START '('  {B11111111, B11111111, B01111101, B10000011, B11111111, B11111111 },    // BRACKET END ')'  {B11111111, B10111011, B11010111, B11101111, B11010111, B10111011 },    // MULTIPLY '*'  {B11111111, B11101111, B11101111, B10000011, B11101111, B11101111 },    // PLUS '+'  {B11111111, B11111111, B11111111, B11111111, B11111111, B11111111 },    // COMMA ','  {B11111111, B11101111, B11101111, B11101111, B11101111, B11101111 },    // MINUS '-'    {B11111111, B11111111, B11111111, B11111111, B11111111, B11111111 },    // PERIOD '.'  {B11111111, B11111011, B11110111, B11101111, B11011111, B10111111 },    // DIVIDE '/'  {B11111111, B10000011, B01111101, B01111101, B01111101, B10000011 },    // NUMBER 0  {B11111111, B11111111, B10111101, B00000001, B11111101, B11111111 },  {B11111111, B10111001, B01110101, B01101101, B01011101, B10111101 },  {B11111111, B10111011, B01111101, B01101101, B01101101, B10010011 },  {B11111111, B11100111, B11010111, B10110111, B00000001, B11110111 },  {B11111111, B00011011, B01101101, B01101101, B01101101, B01110011 },  {B11111111, B10010011, B01101101, B01101101, B01101101, B11110011 },  {B11111111, B01111111, B01110001, B01101111, B01011111, B00111111 },  {B11111111, B10010011, B01101101, B01101101, B01101101, B10010011 },  {B11111111, B10011111, B01101101, B01101101, B01101101, B10010011 },    // NUMBER 9  {B11111111, B11111111, B11111111, B10111011, B11111111, B11111111 },    // COLON ':'  {B11111111, B11111111, B11111111, B11111111, B11111111, B11111111 },    // SEMICOLON ';'  {B11111111, B11111111, B11110111, B11101011, B11011101, B11111111 },    // LESS THAN '<'  {B11111111, B11010111, B11010111, B11010111, B11010111, B11111111 },    // EQUAL '='  {B11111111, B11111111, B11011101, B11101011, B11110111, B11111111 },    // GREATER THAN '>'  {B11111111, B10111111, B01111111, B01110101, B01101111, B10011111 },    // QUESTION MARK '?'  {B11111111, B11111111, B11111111, B11111111, B11111111, B11111111 },    // AT SIGN '@'  {B11111111, B10000001, B01110111, B01110111, B01110111, B10000001 },     // LETTER A  {B11111111, B00000001, B01101101, B01101101, B01101101, B10010011 },  {B11111111, B10000011, B01111101, B01111101, B01111101, B10111011 },  {B11111111, B00000001, B01111101, B01111101, B01111101, B10000011 },  {B11111111, B00000001, B01101101, B01101101, B01101101, B01111101 },  {B11111111, B00000001, B01101111, B01101111, B01101111, B01111111 },  {B11111111, B10000011, B01111101, B01111101, B01110101, B10110011 },  {B11111111, B00000001, B11101111, B11101111, B11101111, B00000001 },  {B11111111, B11111111, B01111101, B00000001, B01111101, B11111111 },  {B11111111, B11111011, B11111101, B01111101, B00000011, B01111111 },  {B11111111, B00000001, B11101111, B11010111, B10111011, B01111101 },  {B11111111, B00000001, B11111101, B11111101, B11111101, B11111101 },  {B11111111, B00000001, B10111111, B11001111, B10111111, B00000001 },  {B11111111, B00000001, B11011111, B11101111, B11110111, B00000001 },  {B11111111, B10000011, B01111101, B01111101, B01111101, B10000011 },  {B11111111, B00000001, B01101111, B01101111, B01101111, B10011111 },  {B11111111, B10000011, B01111101, B01110101, B01111011, B10000101 },  {B11111111, B00000001, B01101111, B01100111, B01101011, B10011101 },  {B11111111, B10011101, B01101101, B01101101, B01101101, B01110011 },  {B11111111, B01111111, B01111111, B00000001, B01111111, B01111111 },  {B11111111, B00000011, B11111101, B11111101, B11111101, B00000011 },  {B11111111, B00000111, B11111011, B11111101, B11111011, B00000111 },  {B11111111, B00000001, B11111011, B11100111, B11111011, B00000001 },  {B11111111, B00111001, B11010111, B11101111, B11010111, B00111001 },  {B11111111, B00011111, B11101111, B11110001, B11101111, B00011111 },  {B11111111, B01111001, B01110101, B01101101, B01011101, B00111101 },     // LETTER Z  {B11111111, B11111111, B11111111, B11111111, B11111111, B11111111 },    // LEFT SQUARE BRACKET '['  {B11111111, B11111111, B11111111, B11111111, B11111111, B11111111 },    // BACKSLASH '\'  {B11111111, B11111111, B11111111, B11111111, B11111111, B11111111 },    // RIGHT SQUARE BRACKET ']'  {B11111111, B11011111, B10111111, B01111111, B10111111, B11011111 },    // POWER '^'  {B11111111, B11111111, B11111111, B11111111, B11111111, B11111111 },    // UNDERSCORE '_'  {B11111111, B11111111, B11111111, B11111111, B11111111, B11111111 },    // GRAVE ACCENT '`'  {B10000001, B01111111, B01000011, B11111111, B10000011, B11111111 },    // LETTER a  {B10000001, B01111111, B01000011, B01111111, B10011111, B10111111 },  {B11111111, B10000011, B11111111, B10000001, B01111111, B01000011 },  {B11111111, B10000011, B11111111, B10000011, B01111111, B01111111 },  {B10000111, B01111111, B01111111, B10000011, B11100111, B11101111 },  {B11111111, B11101001, B11001001, B00100111, B00101111, B01111111 },  {B00011111, B01111111, B01111111, B11111111, B10011111, B01111111 },  {B11100111, B11101111, B11100111, B11101111, B11100111, B00001111 },  {B01001111, B01111111, B10000001, B01111111, B01111111, B10011111 },  {B11111111, B10000011, B11111111, B10000011, B01111111, B01111111 },  {B10000111, B01111111, B01111111, B10000011, B11100111, B11101111 },  {B11111111, B00000001, B11111101, B11111101, B11111101, B11111101 },  {B11111111, B00000001, B10111111, B11001111, B10111111, B00000001 },  {B11111111, B00000001, B11011111, B11101111, B11110111, B00000001 },  {B11111111, B10000011, B01111101, B01111101, B01111101, B10000011 },  {B11111111, B00000001, B01101111, B01101111, B01101111, B10011111 },  {B11111111, B10000011, B01111101, B01110101, B01111011, B10000101 },  {B11111111, B00000001, B01101111, B01100111, B01101011, B10011101 },  {B11111111, B10011101, B01101101, B01101101, B01101101, B01110011 },  {B11111111, B01111111, B01111111, B00000001, B01111111, B01111111 },  {B11111111, B00000011, B11111101, B11111101, B11111101, B00000011 },  {B11111111, B00000111, B11111011, B11111101, B11111011, B00000111 },  {B11111111, B00000001, B11111011, B11100111, B11111011, B00000001 },  {B11111111, B00111001, B11010111, B11101111, B11010111, B00111001 },  {B11111111, B00011111, B11101111, B11110001, B11101111, B00011111 },  {B11111111, B01111001, B01110101, B01101101, B01011101, B00111101 },    // LETTER z  {B11111111, B11111111, B11111111, B11111111, B11111111, B11111111 },    // LEFT BRACE '{'  {B11111111, B11111111, B11111111, B11111111, B11111111, B11111111 },    // VERTICAL LINE, '|'  {B11111111, B11111111, B11111111, B11111111, B11111111, B11111111 },    // RIGHT BRACE '}'  {B11111111, B11110111, B11101111, B11110111, B11111011, B11110111 },    // APPROXIMATELY '~'  {B11111111, B11111111, B11000011, B10111101, B01010110, B01111010 },    // HAPPY FACE '[]'  {B01111010, B01010110, B10111101, B11000011, B11111111, B11111111 },  {B11111111, B11111111, B11000011, B10111101, B01011010, B01110110 },    // SAD FACE '{}'  {B01110110, B01011010, B10111101, B11000011, B11111111, B11111111 },  {B11111111, B11111111, B10001111, B00000111, B00000011, B10000001 },    // HEART ',.'  {B10000001, B00000011, B00000111, B10001111, B11111111, B11111111 } }; [/code]

Can you check this please? Have I got the sequence exactly the same as the ASCII set, not missing or inserting any?

they are the same, except for happy face, sad face and the heart, which we don't care too much.

Thanks, lets pick up again tomorrow.

No problem, my bench power supply is broken and i can't seem to find what's wrong with it, so i am distracted and it's kinda my priority because i feel like without hands.

Sorry to hear that, hope you get it fixed.

I’ve attempted to get the text scrolling:

#include <SPI.h>
#include "font.h"

#define LATCH 10
#define MULTIPLEX_PERIOD 1
#define SCROLL_PERIOD 200

SPISettings shiftRegister(10000000UL, LSBFIRST, SPI_MODE0);

unsigned int image[8];

char message[] = "BOGODAN666   ";

void setup() {
  SPI.begin(); //Start up the SPI hardware
  SPI.beginTransaction(shiftRegister); //Prepare to send data to shift registers
  pinMode(LATCH, OUTPUT);
}

void multiplexDisplay() {
  //"static" means these variables does not loose their value when multiplexDisplay() ends
  static byte currRow; //the row, 0 to 7, of the matrix that is currently lit
  static unsigned long lastUpdate; //time when this row was lit
  unsigned long millisNow = millis(); //Get time now
  if (millisNow - lastUpdate >= MULTIPLEX_PERIOD) { //Is it time to light next row of matrix?
    lastUpdate = millisNow; //Record time this row was lit
    SPI.transfer(128 >> currRow); //Send a byte indicating which row to light
    SPI.transfer(highByte(image[currRow])); //Send the required pattern for this row of the matrix
    SPI.transfer(lowByte(image[currRow]));
    digitalWrite(LATCH, LOW);
    digitalWrite(LATCH, HIGH); //Latch the data into the shift register outputs
    if (++currRow > 7) currRow = 0; //Get ready to light next row of matrix
  }
}

void scrollDisplay() {
  static unsigned long lastUpdate; //time when matrix was last scrolled
  static byte charPos;
  static byte dataPos;
  unsigned long millisNow = millis(); //Get time now
  if (millisNow - lastUpdate >= SCROLL_PERIOD) { //Is it time to scroll the matrix?
    lastUpdate = millisNow; //Record time the matrix was scrolled
    byte newData = font[message[charPos] - ' '][dataPos]; //Get new character pattern to be scrolled onto matrix
    for (byte row = 0; row < 8; row++) {
      image[row] <<= 1; //Scroll this line of the matrix
      bitWrite(image[row], 0, bitRead(newData, row)); //add in the bit of the character pattern to this row
    }
    if (++dataPos > 6) { //Move to next column of character pattern
      dataPos = 0;
      if (++charPos >= strlen(message)) charPos = 0; //Move to next character of message
    }
  }
}

void loop() {
  multiplexDisplay();
  scrollDisplay();
}

I put the font array from the last post into the “font.h” tab. To make the new tab in your IDE, press ctrl-shift-N and enter the name “font.h”. Then paste the big array from the previous post into the new tab.

Ok, weird things are happening, the text begin to scroll from the middle, and is upside down.

bogdan666: the text begin to scroll from the middle

Can you explain more or post a youtube vid?

bogdan666: and is upside down.

Change this line as below:

      bitWrite(image[row], 0, bitRead(newData, 7 - row)); //add in the bit of the character pattern to this row

the change for the flip worked, what i meant by: it starts from the middle was this the letter B starts from the 8th column and moves towards left after it reaches column 1 it goes to column 16th and goes towards left and it fades in column 9 basically, if i break my matrix in half, in order to make it work i have to put the right matrix in front of the left matrix. I think that the the data from 1st 595 should go to 2nd, and the data from 2nd 595 should go to 1st.

bogdan666: the letter B starts from the 8th column and moves towards left after it reaches column 1 it goes to column 16th and goes towards left and it fades in column 9 basically, if i break my matrix in half, in order to make it work i have to put the right matrix in front of the left matrix. I think that the the data from 1st 595 should go to 2nd, and the data from 2nd 595 should go to 1st.

And you did not see the same thing with the scrolling arrow? Did you change the wiring? If not, try swaping the highByte() and lowByte() functions again.

With the arrow it worked perfectly, for this i changed the highbyte and lowbyte and it works. Only problem is that the matrix starts with every led on, then as the letters scrolls they turn off(the unwanted leds), so at the 2nd time the text scrolls it's ok. Question, how does the code knows which is letter "B" , because i see no way of knowing this? the font.h tab has nowhere written that "this" is letter B.

Change this line

unsigned int image[8] = {~0, ~0, ~0, ~0, ~0, ~0, ~0, ~0};

The code knows where to find B in the font array because the array is in ASCII order. Characters are stored in the sketch as ASCII codes. But the font array starts with the space character at index zero, and the ASCII code for a space is 32. So when the code goes to find B in the array, it first subtracts the code for a space (32) from the code for B (66) giving an index of 66 - 32 = 34.

ok, i get it, also very tidy since the fonts are in a different tab

So, I think we got to the functions you wanted? Do you have any other questions about how the code works? Do you still think the matrix is bright enough? Can you post a youtube video? I would like to see it.

link to video

Yes, it works perfectly, now obviously in real life it looks better than on camera, i still have to test the current draw from leds and settle to a value, i can make it a bit brighter i think, the resistors on the right are shorted(it was easier for me to cancel them) About the code, i understand how it works now, i will play with it more to see what changes in order to understand it better. Paul i cannot thank you enough, you have been very patient with me and helped me a lot, the world needs more people like you. As you can see, i have 2 potentiometers and one button soldered on the board, so i am guessing i could do the speed of scrolling with one potentiometer, and with the button, maybe go to next text

I can't see the resistors on the columns. What value are they? You need to limit the current to around 2mA per led, because of the 35mA limit of the individual '595 pins. So these resistors need to be around 1.5K.

Have you got room for 8 transistors where those shorted row resistors are now? You could use 8 bc337 transistors as emitter-followers. No base resistors would be needed. Then you could use lower resistors on the columns. You could allow 8mA per led, 4 times brighter than the current circuit. The column resistors could be much lower at (5 - 2 - 0.7) / 0.008 = 288R

The resistors are on the back side, 1.5k, i didn't have much room on front, as for the transistors, maybe if i remove the resistors i could get them in there, it would be very crowded

The transistors are only slightly larger than those resistors, but they have 3 leads rather than 2. You would connect the base lead to the '595 output pin, the emitter to the led row and the collector to 5V.

ok, i will try to get them on the board next week, but i will use 2n2222, they are similar, and i have a bunch of them

2n2222 is fine. Before you change the column resistors, add a transistor to one row and check that the display works as before. Then add the other 7 transistors and test again. Finally, change the column resistors to 300R or 330R.

ok, i will, happy Easter Paul.