HCMAX7219 Library update – Now you can create a moving dot matrix display!

We’ve now updated our HCMAX7219 led driver library to support serial dot matrix displays such as our dot matrix module shown in the above image. The library supports multiple drivers connected in series and a built-in alphanumeric font to make displaying text and numbers simple. With the new added commands it is easy to make a scrolling message display!

An additional update includes using the hardware SPI interface for faster updates.

You can download the new V0.2 of the library from our support forum here.

There are 3 new added commands for led matrix displays. See the example sketch below for an example of how to use them:

HCMAX7219.printMatrix("TEXT STRING", Offset)

Writes a string of text to the output buffer at position starting at Offset. A value of 1 for offset starts the text at column 1 on the display of driver 1, 8 will start the text from column 8 of driver one, 9 will start the text from column 1 of driver 2 etc. Offset numbers beyond the maximum column number can be set to allow for text to be positioned beyond the ends of the display.

HCMAX7219.printMatrix(Value, Offset)

Writes a positive or negative integer to the display. If negative a ‘-‘ sign will be appended to the beginning of the number. See above of description of Offset.

HCMAX7219.printMatrix(Value, Decimal_Position, Offset)

Writes a positive or negative integer to the display. If negative a ‘-‘ sign will be appended to the beginning of the number. Decimal_Position allows the option to specify the position of a decimal point.
See above of description of Offset.

HCMAX7219.Invert(Mode);

Turns inverted text on or off. Mode is of type boolean and can be one of the following pre-defined values:
INVERTOFF
INVERTON

HCOPTO0014 Arduino Diagram

Example sketch:

/* FILE: HCMODU0082_Serial_Dot_Matrix_Example
DATE: 19/03/15
VERSION: 0.1
AUTHOR: Andrew Davies
REVISIONS:
19/03/15 Created version 0.1
This is an example of how to use the Hobby Components 8x8 serial dot matrix
module (HCOPTO0014). To use this example sketch you will need to download
and install the HCMAX7921 library available from the software section of our
support forum (forum.hobbycomponents.com) or on github:
(https://github.com/HobbyComponents)
The library assumes you are using one module. If you have more than one module
connected together then you will need to change the following line in the
libraries HCMAX7219.h header file to the number of drivers you have connected:
#define NUMBEROFDRIVERS 1 <- Change this number
PINOUT:
MODULE.....UNO/NANO.....MEGA
VCC........+5V..........+5V
GND........GND..........GND
DIN........11...........51
CS (LOAD)..10...........10
CLK........13...........52
You may copy, alter and reuse this code in any way you like, but please leave
reference to HobbyComponents.com in your comments if you redistribute this code.
This software may not be used directly for the purpose of promoting products that
directly compete with Hobby Components Ltd's own range of products.
THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES,
WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR
LACK OF NEGLIGENCE. HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE
FOR ANY DAMAGES INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES FOR ANY REASON WHATSOEVER. */
/* Include the HCMAX7219 and SPI library */
#include <HCMAX7219.h>
#include "SPI.h"
/* Set the LOAD (CS) digital pin number*/
#define LOAD 10
/* Create an instance of the library */
HCMAX7219 HCMAX7219(LOAD);
void setup()
{
}
/* Main program */
void loop()
{
byte Loopcounter;
int Position;
/* Clear the output buffer */
HCMAX7219.Clear();
/* SCROLL SOME TEXT 2 TIMES BEFORE MOVING ON */
for (Loopcounter = 0; Loopcounter <= 2; Loopcounter++)
{
for(Position=0; Position <= 64; Position++)
{
HCMAX7219.printMatrix("HELLO!! ", Position);
HCMAX7219.Refresh();
delay(80);
}
}
/* SCROLL SOME INVERTED TEXT 2 TIMES BEFORE MOVING ON */
HCMAX7219.Invert(INVERTON);
for (Loopcounter = 0; Loopcounter <= 2; Loopcounter++)
{
for(Position=0; Position <= 64; Position++)
{
HCMAX7219.Clear();
HCMAX7219.printMatrix("HELLO!! ", Position);
HCMAX7219.Refresh();
delay(80);
}
}
HCMAX7219.Invert(INVERTOFF);
/* SCROLL AN INTEGER NUMBER */
for(Position=0; Position <= 80; Position++)
{
HCMAX7219.Clear();
HCMAX7219.printMatrix(-12345678, Position);
HCMAX7219.Refresh();
delay(80);
}
/* SCROLL AN INTEGER NUMBER WITH DECIMAL PLACE */
for(Position=0; Position <= 96; Position++)
{
HCMAX7219.Clear();
HCMAX7219.printMatrix(-12345678, 2, Position);
HCMAX7219.Refresh();
delay(80);
}
}

About The Author

Andrew

thank you for the good description.
but the connections in the picture HCOPTO0014_Arduino_Diagram.png are not correct:
the arduino D11 must be connected to the DIN of the first module, the DOUT goes to DIN of the second module,…

I’ve just given it a check but I’m not seeing any problems with. One thing I should point out is that if set NUMBEROFDRIVERS to a lower number than the amount of modules you have connected the extra modules will still do something but they will just mirror first few. If you still have no luck can you give me a little more information about what you mean when you say it doesn’t work, i.e. is changing it having no effect or if it is what exactly is it doing? Also how many modules do you have connected and what are you setting NUMBEROFDRIVERS to ?

hi, maybe you have to connect an external power supply (7.5V to 10V) to your arduino. if it is only connected to usb, the required current of more than 4 modules is too much…
i hope this info will help you.

Maddi is correct in that 8 modules may be overloading your Arduino’s 5V supply. Try connecting less modules and reducing the value for NUMBEROFDRIVERS to match.

In the picture for this post you can see we have 5 modules connected. Try this amount or less. If it works with less then this is the problem and you will need an external power supply to power your 8 modules.

You can add as many modules as you like, there is no fixed amount. The only requirement is that you need too change the value of NUMBEROFDRIVERS (see comments in sketches) to match the number of modules you have.

I would suggest having a play with this library and sketch to try and understand how it works. Once you figure it out you can do the same with the HCMAX7219 library and example in this blog post. If you can understand the example sketches you can try to combine the two so that you can read the time from the DS3231 and display it on the dot matrix modules.

Can you please elaborate this function??
I am using 2 drivers and when i give the offset value as 16, the display gets stucked with the 2nd character of the String.
I also changed the number of drivers in the .h library file.

With two drivers and an offset of 16 you should see the first character displayed on the first driver and the second character on the second driver. Although I may be misunderstanding what you mean by stuck on the second character, if the number of drivers in the .h file was still somehow set to 1 you would see the second character on both displays.

Are you absolutely sure that you have changed and saved the the value in the .h header file?

yeah I am absolutely sure that i have changed the number from 1 to 2 in the .h file.
Stuck in the sense, the string of characters, which i place inside the function HCMAX7219.printMatrix(“HELLO!! “, Position);
Now if i replace the position value with 16(since 2 Drivers = (8 * 2) = 16 Columns. So starting from 16th Column, it should scroll to 1st column of 1st Driver right???

But when i replace the Position value with 16, i am getting the output as ‘E’ displayed on both driver..

If you replace the position variable with a fixed number then the text will not scroll, it will just stay in a fixed position. In the example sketch in this blog post you will see that the printMaxtric() function is inside a loop where the position variable ticks up by one each time it runs through the loop.

This still doesn’t explain why you see the same character on both drivers but this is probably a separate issue.

Example sketch works fine but the String is repeated in the same manner. not one character after the other.
i just want to scroll the name on my matrix driver. it also worked fine once. i just made some logic in it. But now its not working fine.
Can u guide me how do i scroll my name from one driver to other using 2 drivers??

i already changed the NUMBEROFDRIVERS as 2 in .h file.

my query is what value should i change the position to or shouldn’t i change it???

With the example sketch you should defiantly see the text scroll across both displays, each character passing from one display to the other. Sorry to be persistent but the NUMBEROFDRIVERS not being set is the only thing I can think of at the moment that would cause exactly what you are reporting. Could you just try uploading this sketch to confirm it is set correctly:

Once uploaded, open the monitor window in the Arduino IDE (Tools->Serial Monitor). In the monitor window make sure the BAUD rate is set to 9600 and tell me what value it reports for the number of drivers.

You are correct. It is displaying NUMBEROFDRIVERS in my Serial monitor as 1 only.
But as soon as I open my .h file, when i scroll down to the #define NUMBEROFLINES, I find it already to be 2. I am also saving that file again…

Ok that makes sense then. It’s probably one of two things, the file you’re editing is either not being saved to your Arduino library folder, or you have two copies of the library in your Library folder and it’s using the other one.

Assuming you are using windows go to your Library folder:

C:\Users\username\Documents\Arduino\libraries\HCMAX7219\

Open the .h file from there with a text editor and change the NUMBEROFDRIVERS value.

If that doesn’t work go to the \Arduino\libraries\ folder and check you don’t have any other copies.

No problem. With regards to the issue it’s very likely you have more than one copy of the library. Just do a file search on your computer for the HCMAX7219.h header file and see if it finds more than one copy.

SunMarch 19, 2016

yeah!! you are correct. The Problem is solved now. Once again Thanking you for the right guidance 🙂

If you’re using the Serial.read() function then this returns each received ASCII character as an integer whereas the dot matrix print function expects any text to be passed to it as a null terminated character array. This is untested but should work:

At the top of your sketch or main loop define this two character array:

char a[2] = {'0','\0'};

The first character of this array will hold the value received by the Serial.Read() function, the second character is a null termination which signifies that this is the end of the string of text.

To display the text received from the Serial.print() function do this:

a[0] = ReceivedCharacter;
HCMAX7219.printMatrix(a, 8);

Where ReceivedCharacter is the integer variable that holds the character received by the Serial.print function. remember that the Serial.print function can return a ‘-1’ if no characters are received so you should test for this before passing it to the HCMAX7219.printMatrix() function.

It shouldn’t be able to do that as it can only pass one character (digit) at a time and the decimal equivalent will be at least two digits. Something else must be going on. Either your passing the received value and not the array ‘a’ to the HCMAX7219.printMatrix() function or you are receiving something else. In the monitor window do you have the same Baud rate set as in your sketch and have you disabled the New Line & Cartridge Return (NL+CR) ?

Each index of the array writes to one column on the display. To write to the second display just use array indexes of 8 to 15 instead of 0 to 7. Be careful not to index outside of the array though. Its maximum index will be (NUMBEROFDRIVERS * 8) – 1.

Alternatively you could modify one of the less useful characters in the font that you don’t need.

Actually I am reading the character through Serial.read() function and loading that character inside a ReceivedCharacter variable of integer type. Then i am printing that character whatever i type on my keyboard to my serial monitor through Serial.print(RecievedCharacter); statement.
Then.. i am doing the same as in you told me….
a[0] = ReceivedCharacter;
HCMAX7219.printMatrix(a, 8);

Yes that is correct. Just remember to make it a character array (char) and that you need to make the array (dimension it) one character longer than the text you need to hold and make sure that last value is a null character. I would recommend googling how arrays work in c++ and how strings can be stored within them. It will give you a much better understanding of what is going on. Here are a good couple of examples:

Hello Andrew;
Thank you for this library, it’s very useful,
I am using the Arduino UNO,(Atmel368p)
But its memory is not enough, when I use “hcmax7219.printmatrix”
Memory is not enough to give the error,
Because there are a lot of libraries and approximately 900 lines code
I had to use the Arduino UNO.

1. I just want to use these characters. (A, D, E, F, N, R, S, T, U, 0,1,2,3,4,5,6,7,8,9,.,-)
2. How can I change the font, (thinner)
thank you.

The fonts can be found in the HCMAX7219.h header file. There are two of them, one for the seven segment displays and one for dot matrix displays. The fonts are stored in two character arrays called SevenSegChar[] and Font8x8[][8] respectively. Each row of data in the arrays represent a single character. The SevenSegChar[] array is labeled so you can see which line represents which character. The SevenSegChar[] array isn’t labeled but the order should be the same. You can simply delete the lines for characters you don’t need. The only problem is that the remaining characters no longer be mapped correctly to your text. I.e. printing a space will display probably display a 0 after you have modified the arrays.

What memory are you running out of btw,? Program storage or dynamic memory? It should tell you which in the bottom of the Arduno IDE when you compile your sketch.

Hello Andrew;
SRAM insufficient,
I solved,
I deleted the space characters lines,
I made a new characters recognition with Pixel font editor.
Because the characters were printed at 90 degrees and bold.
Fix both, the characters and memory usage
Thank you