MD max7219 issue with the font

Hello, i have two "MAX7219 dot matrix 4 in 1 module", but i have a problem, i am trying that in one module i put the score and in the other the time, so for now i only do a simulation with counters that are x and y, but i notice a problem and is that when score had a 1 it is more small that the other numbers, so the module with the time will be more to the left for every 1 that score had.

So i am thinking in two solutions, the first one that i think is to change the font of the 1 because is the only number that create problems to me, i really tried, i modify the excel files and the documents of text that contain the number 1 but nothing work, i believe that i am doing something wrong so if someone know how to change the font it will be of so much help.

The other solution that i think is to know a function in the library that let me change the size of every character or that let me set the position in the modules that i want that the time begin

So this is my code, if someone could help me i would thank you so much.

#include <MD_MAX72xx.h>
#include <SPI.h>

#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 8

#define CLK_PIN   13  // or SCK
#define DATA_PIN  11  // or MOSI
#define CS_PIN    10  // or SS

// SPI hardware interface
MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// Arbitrary pins
//MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);

// Text parameters
#define CHAR_SPACING  1 // pixels between characters

// Global message buffers shared by Serial and Scrolling functions
#define BUF_SIZE  75
char message[BUF_SIZE] = "P: 000 00:30";
int x=60;
int y=0;

void printText(uint8_t modStart, uint8_t modEnd, char *pMsg)
// Print the text string to the LED matrix modules specified.
// Message area is padded with blank columns after printing.
{
  uint8_t   state = 0;
  uint8_t   curLen;
  uint16_t  showLen;
  uint8_t   cBuf[8];
  int16_t   col = ((modEnd + 1) * COL_SIZE) - 1;

  mx.control(modStart, modEnd, MD_MAX72XX::UPDATE, MD_MAX72XX::OFF);

  do     // finite state machine to print the characters in the space available
  {
    switch(state)
    {
      case 0: // Load the next character from the font table
        // if we reached end of message, reset the message pointer
        if (*pMsg == '\0')
        {
          showLen = col - (modEnd * COL_SIZE);  // padding characters
          state = 2;
          break;
        }

        // retrieve the next character form the font file
        showLen = mx.getChar(*pMsg++, sizeof(cBuf)/sizeof(cBuf[0]), cBuf);
        curLen = 0;
        state++;
        // !! deliberately fall through to next state to start displaying

      case 1: // display the next part of the character
        mx.setColumn(col--, cBuf[curLen++]);

        // done with font character, now display the space between chars
        if (curLen == showLen)
        {
          showLen = CHAR_SPACING;
          state = 2;
        }
        break;

      case 2: // initialize state for displaying empty columns
        curLen = 0;
        state++;
        // fall through

      case 3:  // display inter-character spacing or end of message padding (blank columns)
        mx.setColumn(col--, 0);
        curLen++;
        if (curLen == showLen)
          state = 0;
        break;

      default:
        col = -1;   // this definitely ends the do loop
    }
  } while (col >= (modStart * COL_SIZE));

  mx.control(modStart, modEnd, MD_MAX72XX::UPDATE, MD_MAX72XX::ON);
}

void setup() {
  // put your setup code here, to run once:
 mx.begin();

  Serial.begin(9600);
  
}

void loop() {
  // put your main code here, to run repeatedly:
printText(0, MAX_DEVICES-1, message);

delay(1000);

x--;
y++;
sprintf_P(message, (PGM_P)F("P: %03d  %02d:%02d"),y, 0, x);
}

You need to change the font to one that is fixed width rather than variable width. The Zone_Mesg example shows the time in a fixed font so you can start there.

When you create the font file, the first byte of a character definition is the width of the character followed by that number of bytes, so you can also just change your font to suit.

Ok, so based in what you said, i decide to see the example of zone msg and i see that there is a font.h so i incorporate the same to my code and it work but only with numbers, when i want to put a letter or ":" it show points in weird place, so i am happy that now i can do my timer and score but i have curiosity of why i only can use numbers, my code is:

#include <MD_MAX72xx.h>
#include <SPI.h>
#include "Font_Data.h"




#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 8

#define CLK_PIN   13  // or SCK
#define DATA_PIN  11  // or MOSI
#define CS_PIN    10  // or SS

// SPI hardware interface
MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// Arbitrary pins
//MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);

// Text parameters
#define CHAR_SPACING  1 // pixels between characters
#define USE_LOCAL_FONT 1
// Global message buffers shared by Serial and Scrolling functions
#define BUF_SIZE  75
char message[BUF_SIZE] =  "    000        60";
//char message[BUF_SIZE] = "P 000  0030";
int x=60;
int y=0;

void printText(uint8_t modStart, uint8_t modEnd, char *pMsg)
// Print the text string to the LED matrix modules specified.
// Message area is padded with blank columns after printing.
{
  uint8_t   state = 0;
  uint8_t   curLen;
  uint16_t  showLen;
  uint8_t   cBuf[8];
  int16_t   col = ((modEnd + 1) * COL_SIZE) - 1;

  mx.control(modStart, modEnd, MD_MAX72XX::UPDATE, MD_MAX72XX::OFF);

  do     // finite state machine to print the characters in the space available
  {
    switch(state)
    {
      case 0: // Load the next character from the font table
        // if we reached end of message, reset the message pointer
        if (*pMsg == '\0')
        {
          showLen = col - (modEnd * COL_SIZE);  // padding characters
          state = 2;
          break;
        }

        // retrieve the next character form the font file
        showLen = mx.getChar(*pMsg++, sizeof(cBuf)/sizeof(cBuf[0]), cBuf);
        curLen = 0;
        state++;
        // !! deliberately fall through to next state to start displaying

      case 1: // display the next part of the character
        mx.setColumn(col--, cBuf[curLen++]);

        // done with font character, now display the space between chars
        if (curLen == showLen)
        {
          showLen = CHAR_SPACING;
          state = 2;
        }
        break;

      case 2: // initialize state for displaying empty columns
        curLen = 0;
        state++;
        // fall through

      case 3:  // display inter-character spacing or end of message padding (blank columns)
        mx.setColumn(col--, 0);
        curLen++;
        if (curLen == showLen)
          state = 0;
        break;

      default:
        col = -1;   // this definitely ends the do loop
    }
  } while (col >= (modStart * COL_SIZE));

  mx.control(modStart, modEnd, MD_MAX72XX::UPDATE, MD_MAX72XX::ON);
}

void setup() {
  // put your setup code here, to run once:
 mx.begin();
  mx.setFont(numeric7Seg);
  Serial.begin(9600);
  
}

void loop() {
  // put your main code here, to run repeatedly:
//printText(0, MAX_DEVICES-1, "    000        60");
printText(0, MAX_DEVICES-1,message);


delay(1000);
//unidadSegundos=
//message[4]=unidadSegundos;
//itoa (10,message,10);
//sprintf_P(message, (PGM_P)F("%02d:%02d:%02d"), 0, 29, 20);
x--;
y++;
sprintf_P(message, (PGM_P)F("    %03d        %02d"),y, x);
}

and my font_data.h is:

// Data file for user example user defined fonts
#ifndef FONTDATA_H
#define FONTDATA_H

MD_MAX72XX::fontType_t numeric7Seg[] PROGMEM = 
{
  0,    // 0
  0,    // 1
  0,    // 2
  0,    // 3
  0,    // 4
  0,    // 5
  0,    // 6
  0,    // 7
  0,    // 8
  0,    // 9
  0,    // 10
  0,    // 11
  0,    // 12
  0,    // 13
  0,    // 14
  0,    // 15
  0,    // 16
  0,    // 17
  0,    // 18
  0,    // 19
  0,    // 20
  0,    // 21
  0,    // 22
  0,    // 23
  0,    // 24
  0,    // 25
  0,    // 26
  0,    // 27
  0,    // 28
  0,    // 29
  0,    // 30
  0,    // 31
  1, 0,   // 32 - 'Space'
  0,    // 33 - '!'
  0,    // 34 - '"'
  0,    // 35 - '#'
  0,    // 36 - '

Thank you for your help :wink:
  0,    // 37 - '%'
  0,    // 38 - '&'
  0,    // 39 - '''
  0,    // 40 - '('
  0,    // 41 - ')'
  0,    // 42 - '*'
  0,    // 43 - '+'
  0,    // 44 - ','
  0,    // 45 - '-'
  1, 64,    // 46 - '.'
  0,    // 47 - '/'
  5, 127, 65, 65, 65, 127,  // 48 - '0'
  5, 0, 0, 127, 0, 0,    // 49 - '1'
  5, 121, 73, 73, 73, 79,  // 50 - '2'
  5, 73, 73, 73, 73, 127,  // 51 - '3'
  5, 15, 8, 8, 8, 127,    // 52 - '4'
  5, 79, 73, 73, 73, 121,  // 53 - '5'
  5, 127, 73, 73, 73, 121,  // 54 - '6'
  5, 1, 1, 1, 1, 127,    // 55 - '7'
  5, 127, 73, 73, 73, 127,  // 56 - '8'
  5, 79, 73, 73, 73, 127,  // 57 - '9'
  5, 20,    // 58 - ':'
  0,    // 59 - ';'
  0,    // 60 - '<'
  0,    // 61 - '='
  0,    // 62 - '>'
  0,    // 63 - '?'
  0,    // 64 - '@'
  5, 127, 9, 9, 9, 127,  // 65 - 'A'
  5, 127, 73, 73, 73, 54,  // 66 - 'B'
  5, 127, 65, 65, 65, 65,  // 67 - 'C'
  5, 127, 65, 65, 65, 62,  // 68 - 'D'
  5, 127, 73, 73, 73, 73,  // 69 - 'E'
  5, 127, 9, 9, 9, 9,    // 70 - 'F'
  0,    // 71 - 'G'
  0,    // 72 - 'H'
  0,    // 73 - 'I'
  0,    // 74 - 'J'
  0,    // 75 - 'K'
  0,    // 76 - 'L'
  0,    // 77 - 'M'
  0,    // 78 - 'N'
  0,    // 79 - 'O'
  5,127,  9, 9, 9, 6,    // 80 - 'P'
  0,    // 81 - 'Q'
  0,    // 82 - 'R'
  0,    // 83 - 'S'
  0,    // 84 - 'T'
  0,    // 85 - 'U'
  0,    // 86 - 'V'
  0,    // 87 - 'W'
  0,    // 88 - 'X'
  0,    // 89 - 'Y'
  0,    // 90 - 'Z'
  0,    // 91 - '['
  0,    // 92 - ''
  0,    // 93 - ']'
  0,    // 94 - '^'
  0,    // 95 - '_'
  0,    // 96 - '`'
  5, 127, 9, 9, 9, 127,  // 97 - 'a'
  5, 127, 73, 73, 73, 54,  // 98 - 'b'
  5, 127, 65, 65, 65, 65,  // 99 - 'c'
  5, 127, 65, 65, 65, 62,  // 100 - 'd'
  5, 127, 73, 73, 73, 73,  // 101 - 'e'
  5, 127, 9, 9, 9, 9,    // 102 - 'f'
  0,    // 103 - 'g'
  0,    // 104 - 'h'
  0,    // 105 - 'i'
  0,    // 106 - 'j'
  0,    // 107 - 'k'
  0,    // 108 - 'l'
  0,    // 109 - 'm'
  0,    // 110 - 'n'
  0,    // 111 - 'o'
  0,    // 112 - 'p'
  0,    // 113 - 'q'
  0,    // 114 - 'r'
  0,    // 115 - 's'
  0,    // 116 - 't'
  0,    // 117 - 'u'
  0,    // 118 - 'v'
  0,    // 119 - 'w'
  0,    // 120 - 'x'
  0,    // 121 - 'y'
  0,    // 122 - 'z'
  0,    // 123 - '{'
  1, 127,  // 124 - '|'
  0,    // 125
  0,    // 126
  0,    // 127
  0,    // 128
  0,    // 129
  0,    // 130
  0,    // 131
  0,    // 132
  0,    // 133
  0,    // 134
  0,    // 135
  0,    // 136
  0,    // 137
  0,    // 138
  0,    // 139
  0,    // 140
  0,    // 141
  0,    // 142
  0,    // 143
  0,    // 144
  0,    // 145
  0,    // 146
  0,    // 147
  0,    // 148
  0,    // 149
  0,    // 150
  0,    // 151
  0,    // 152
  0,    // 153
  0,    // 154
  0,    // 155
  0,    // 156
  0,    // 157
  0,    // 158
  0,    // 159
  0,    // 160
  0,    // 161
  0,    // 162
  0,    // 163
  0,    // 164
  0,    // 165
  0,    // 166
  0,    // 167
  0,    // 168
  0,    // 169
  0,    // 170
  0,    // 171
  0,    // 172
  0,    // 173
  0,    // 174
  0,    // 175
  0,    // 176
  0,    // 177
  0,    // 178
  0,    // 179
  0,    // 180
  0,    // 181
  0,    // 182
  0,    // 183
  0,    // 184
  0,    // 185
  0,    // 186
  0,    // 187
  0,    // 188
  0,    // 189
  0,    // 190
  0,    // 191
  0,    // 192
  0,    // 193
  0,    // 194
  0,    // 195
  0,    // 196
  0,    // 197
  0,    // 198
  0,    // 199
  0,    // 200
  0,    // 201
  0,    // 202
  0,    // 203
  0,    // 204
  0,    // 205
  0,    // 206
  0,    // 207
  0,    // 208
  0,    // 209
  0,    // 210
  0,    // 211
  0,    // 212
  0,    // 213
  0,    // 214
  0,    // 215
  0,    // 216
  0,    // 217
  0,    // 218
  0,    // 219
  0,    // 220
  0,    // 221
  0,    // 222
  0,    // 223
  0,    // 224
  0,    // 225
  0,    // 226
  0,    // 227
  0,    // 228
  0,    // 229
  0,    // 230
  0,    // 231
  0,    // 232
  0,    // 233
  0,    // 234
  0,    // 235
  0,    // 236
  0,    // 237
  0,    // 238
  0,    // 239
  0,    // 240
  0,    // 241
  0,    // 242
  0,    // 243
  0,    // 244
  0,    // 245
  0,    // 246
  0,    // 247
  0,    // 248
  0,    // 249
  0,    // 250
  0,    // 251
  0,    // 252
  0,    // 253
  0,    // 254
  0,    // 255
};

#endif


Thank you for your help ;)

The font you are using only has the definition for the numbers 0-9, hex digits a-f and some punctuation marks. The other letters that look like this
0, // 71 - 'G'
are not defined.

If you want those other letters, copy the standard font definition into the same sequential location position in your new font file.

You may also want to read these, although the second only applies if you are using MD_Parola:

Thank you so much, its works! so i only modify the font.h with the help of the excel font builder, below is the code if someone is interested

// Data file for user example user defined fonts
#ifndef FONTDATA_H
#define FONTDATA_H

MD_MAX72XX::fontType_t numeric7Seg[] PROGMEM = 
{
  0,    // 0
  0,    // 1
  0,    // 2
  0,    // 3
  0,    // 4
  0,    // 5
  0,    // 6
  0,    // 7
  0,    // 8
  0,    // 9
  0,    // 10
  0,    // 11
  0,    // 12
  0,    // 13
  0,    // 14
  0,    // 15
  0,    // 16
  0,    // 17
  0,    // 18
  0,    // 19
  0,    // 20
  0,    // 21
  0,    // 22
  0,    // 23
  0,    // 24
  0,    // 25
  0,    // 26
  0,    // 27
  0,    // 28
  0,    // 29
  0,    // 30
  0,    // 31
  1, 0,   // 32 - 'Space'
  0,    // 33 - '!'
  0,    // 34 - '"'
  0,    // 35 - '#'
  0,    // 36 - '

0,    // 37 - '%'
  0,    // 38 - '&'
  0,    // 39 - '''
  0,    // 40 - '('
  0,    // 41 - ')'
  0,    // 42 - '*'
  0,    // 43 - '+'
  0,    // 44 - ','
  4,8,8,8,8,    // 45 - '-'
  1, 64,    // 46 - '.'
  0,    // 47 - '/'
  5, 127, 65, 65, 65, 127,  // 48 - '0'
  5, 0, 0, 127, 0, 0,    // 49 - '1'
  5, 121, 73, 73, 73, 79,  // 50 - '2'
  5, 73, 73, 73, 73, 127,  // 51 - '3'
  5, 15, 8, 8, 8, 127,    // 52 - '4'
  5, 79, 73, 73, 73, 121,  // 53 - '5'
  5, 127, 73, 73, 73, 121,  // 54 - '6'
  5, 1, 1, 1, 1, 127,    // 55 - '7'
  5, 127, 73, 73, 73, 127,  // 56 - '8'
  5, 79, 73, 73, 73, 127,  // 57 - '9'
  2, 108,  108,  // 58 - ':'
  0,    // 59 - ';'
  0,    // 60 - '<'
  0,    // 61 - '='
  0,    // 62 - '>'
  0,    // 63 - '?'
  0,    // 64 - '@'
  5, 127, 9, 9, 9, 127,  // 65 - 'A'
  5, 127, 73, 73, 73, 54,  // 66 - 'B'
  5, 127, 65, 65, 65, 65,  // 67 - 'C'
  5, 127, 65, 65, 65, 62,  // 68 - 'D'
  5, 127, 73, 73, 73, 73,  // 69 - 'E'
  5, 127, 9, 9, 9, 9,    // 70 - 'F'
  0,    // 71 - 'G'
  0,    // 72 - 'H'
  0,    // 73 - 'I'
  0,    // 74 - 'J'
  0,    // 75 - 'K'
  0,    // 76 - 'L'
  0,    // 77 - 'M'
  0,    // 78 - 'N'
  0,    // 79 - 'O'
  5,127,  9, 9, 9, 6,    // 80 - 'P'
  0,    // 81 - 'Q'
  0,    // 82 - 'R'
  0,    // 83 - 'S'
  5,1,1,127,1,1,    // 84 - 'T'
  0,    // 85 - 'U'
  0,    // 86 - 'V'
  0,    // 87 - 'W'
  0,    // 88 - 'X'
  0,    // 89 - 'Y'
  0,    // 90 - 'Z'
  0,    // 91 - '['
  0,    // 92 - ''
  0,    // 93 - ']'
  0,    // 94 - '^'
  0,    // 95 - '_'
  0,    // 96 - '`'
  5, 127, 9, 9, 9, 127,  // 97 - 'a'
  5, 127, 73, 73, 73, 54,  // 98 - 'b'
  5, 127, 65, 65, 65, 65,  // 99 - 'c'
  5, 127, 65, 65, 65, 62,  // 100 - 'd'
  5, 127, 73, 73, 73, 73,  // 101 - 'e'
  5, 127, 9, 9, 9, 9,    // 102 - 'f'
  0,    // 103 - 'g'
  0,    // 104 - 'h'
  0,    // 105 - 'i'
  0,    // 106 - 'j'
  0,    // 107 - 'k'
  0,    // 108 - 'l'
  0,    // 109 - 'm'
  0,    // 110 - 'n'
  0,    // 111 - 'o'
  0,    // 112 - 'p'
  0,    // 113 - 'q'
  0,    // 114 - 'r'
  0,    // 115 - 's'
  0,    // 116 - 't'
  0,    // 117 - 'u'
  0,    // 118 - 'v'
  0,    // 119 - 'w'
  0,    // 120 - 'x'
  0,    // 121 - 'y'
  0,    // 122 - 'z'
  0,    // 123 - '{'
  1, 127,  // 124 - '|'
  0,    // 125
  0,    // 126
  0,    // 127
  0,    // 128
  0,    // 129
  0,    // 130
  0,    // 131
  0,    // 132
  0,    // 133
  0,    // 134
  0,    // 135
  0,    // 136
  0,    // 137
  0,    // 138
  0,    // 139
  0,    // 140
  0,    // 141
  0,    // 142
  0,    // 143
  0,    // 144
  0,    // 145
  0,    // 146
  0,    // 147
  0,    // 148
  0,    // 149
  0,    // 150
  0,    // 151
  0,    // 152
  0,    // 153
  0,    // 154
  0,    // 155
  0,    // 156
  0,    // 157
  0,    // 158
  0,    // 159
  0,    // 160
  0,    // 161
  0,    // 162
  0,    // 163
  0,    // 164
  0,    // 165
  0,    // 166
  0,    // 167
  0,    // 168
  0,    // 169
  0,    // 170
  0,    // 171
  0,    // 172
  0,    // 173
  0,    // 174
  0,    // 175
  0,    // 176
  0,    // 177
  0,    // 178
  0,    // 179
  0,    // 180
  0,    // 181
  0,    // 182
  0,    // 183
  0,    // 184
  0,    // 185
  0,    // 186
  0,    // 187
  0,    // 188
  0,    // 189
  0,    // 190
  0,    // 191
  0,    // 192
  0,    // 193
  0,    // 194
  0,    // 195
  0,    // 196
  0,    // 197
  0,    // 198
  0,    // 199
  0,    // 200
  0,    // 201
  0,    // 202
  0,    // 203
  0,    // 204
  0,    // 205
  0,    // 206
  0,    // 207
  0,    // 208
  0,    // 209
  0,    // 210
  0,    // 211
  0,    // 212
  0,    // 213
  0,    // 214
  0,    // 215
  0,    // 216
  0,    // 217
  0,    // 218
  0,    // 219
  0,    // 220
  0,    // 221
  0,    // 222
  0,    // 223
  0,    // 224
  0,    // 225
  0,    // 226
  0,    // 227
  0,    // 228
  0,    // 229
  0,    // 230
  0,    // 231
  0,    // 232
  0,    // 233
  0,    // 234
  0,    // 235
  0,    // 236
  0,    // 237
  0,    // 238
  0,    // 239
  0,    // 240
  0,    // 241
  0,    // 242
  0,    // 243
  0,    // 244
  0,    // 245
  0,    // 246
  0,    // 247
  0,    // 248
  0,    // 249
  0,    // 250
  0,    // 251
  0,    // 252
  0,    // 253
  0,    // 254
  0,    // 255
};

#endif