HCMAX7219 - LED driver library

Useful guides, libraries, and example sketches to support our Arduino based products.
admin
Site Admin
Posts: 865
Joined: Sun Aug 05, 2012 4:02 pm

HCMAX7219 - LED driver library

Post by admin » Thu Mar 12, 2015 4:17 pm

Image

Image

This Arduino library is written to work with the MAX7219 LED driver IC. The library will allow you to control one or more of these IC's that have been serially connected together.

The library also currently supports the 8 digit 7 segment display module (HCMODU0082) and provides compatible commands and an alphanumeric character set. Future updates are planned to include other MAX7219 based products.

You will need to download (please log in to download the library) and unzip this library to the Arduino development environments library area

On Windows:
My Documents\Arduino\libraries\

On Mac:
Documents/Arduino/libraries/
or similarly for Linux.


To use the library just include the HCMAX7219.h header file and create an instance of the library. E.g:

Code: Select all

#include <HCMAX7219.h>
HCMAX7219 HCMAX7219(LOAD);
Where:
LOAD is the number for the digital pin connected to the first MAX7219 's LOAD (CS) pin.


The following functions are available with this library:

Code: Select all

HCMAX7219.Init();
Initialises the library. This function should be executed once before any other library function.


Code: Select all

HCMAX7219.Write(Address, Data, Driver)
Writes to a register within the one of the connected drivers where:

Address is the address of the register to write to and can be one of the following pre-defined values:

MAX7219NOOP
MAX7219DIGIT1
MAX7219DIGIT2
MAX7219DIGIT3
MAX7219DIGIT4
MAX7219DIGIT5
MAX7219DIGIT6
MAX7219DIGIT7
MAX7219DIGIT8
MAX7219DECODE
MAX7219INTESITY
MAX7219SCANLIMIT
MAX7219SHUTDOWN
MAX7219TEST

Data is a value of type Byte to write to the register.
Driver is a value of type Byte which driver in the chain to access. 0 being the first.

Code: Select all

HCMAX7219.Shutdown(Mode, Driver)
Puts the driver into low power shutdown mode where:

Mode is of type boolean and can be one of the following pre-defined values:
MAX7219OFF
MAX7219ON

Driver is a value of type Byte which driver in the chain to access. 0 being the first.

Code: Select all

HCMAX7219.TestMode(Mode, Driver)
Puts the driver into its test mode and turns all driven LED's on:

Mode is of type boolean and can be one of the following pre-defined values:
TESTMODEOFF
TESTMODEON

Driver is a value of type Byte which driver in the chain to access. 0 being the first.

Code: Select all

HCMAX7219.SevenSegDigits(Digits, Driver)
Sets the number of digits to drive in each driver. Valid values for Digits are:
0 (Digit 0)
1 (Digit 0 & 1)
2 (Digit 0, 1 & 2)
3 (Digit 0, 1, 2, & 3)
4 (Digit 0, 1, 2, 3 & 4)
5 (Digit 0, 1, 2, 3, 4 & 5)
6 (Digit 0, 1, 2, 3, 4, 5, & 6)
7 (Digit 0, 1, 2, 3, 4, 5,, 6 & 7)

Driver is a value of type Byte which driver in the chain to access. 0 being the first.

Code: Select all

HCMAX7219.Intensity(Level, Driver)
Sets the intensity of the LED's. Valid values for Level are 0 (min) to 0x0F (max)

Driver is a value of type Byte which driver in the chain to access. 0 being the first.

Code: Select all

HCMAX7219.Clear()
Clears the contents of the output buffer. Executing the refresh library command after a clear command will write the empty buffer to the driver thereby clearing (turning off) all the LED's.

Code: Select all

HCMAX7219.Refresh()
Update all connected drivers with the contents of the output buffer.

Code: Select all

HCMAX7219.DisplayBuffer[]
An array of type Byte holding the display buffer which is written to the driver(s) digit registers when the refresh() command is executed. The size of the buffer is 8 x the number of drivers (default 8). The fist 8 bytes (0 to 7) represent the digit registers in the first driver. The second group of 8 bytes (8 to 15) represent the digit registers in the second driver etc.


Setting the number off drivers:

By default the library assumes that you only have one driver connected. If you are connecting multiple drivers together you can set the number of drivers you have by changing the following line in the HCMAX7219.h header file:

Code: Select all

#define NUMBEROFDRIVERS 1

8 digit 7 segment display module (HCMODU0082) specific commands:

Code: Select all

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

Code: Select all

HCMAX7219.print7Seg(Value, DP, Digits, Offset)
Prints a floating point number to the display starting at the current cursor coordinate where:
Value is the number to print.

DP specifies the number of decimal places to display the floating point number to.

Digits is the total number of digits to display. If the number is smaller than the specified number of digits it will pad
the left side of the number with spaces.

Offset is the column position from where the value will start from. Valid values are from 0 to 65535 (Uno/Nano etc) where:
1 = right most column
8 = left most column

Values above 8 will start the text at a column beyond the left most column.

Code: Select all

HCMAX7219.print7Seg(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.

Code: Select all

HCMAX7219.print7Seg(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.



8x8 serial dot matrix module (HCOPTO0014) specific commands:

Code: Select all

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 start 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.


Code: Select all

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.

Code: Select all

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.

Code: Select all

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



Image

Code: Select all

/* FILE:    HCMODU0082_Serial_7_Segment_Module_Example1
   DATE:    19/03/15
   VERSION: 0.2
   
REVISIONS:

12/03/15 Created version 0.1
19/03/15 Updated to work with V0.2 of the HCMAX7219 library

This is an example of how to use the Hobby Components serial 8 digit seven 7 
segment display module (HCMODU0082). 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() 
{
  HCMAX7219.Init();        
}

/* Main program */
void loop() 
{
  /* Clear the output buffer */
  HCMAX7219.Clear();
  /* Write some text to the output buffer */
  HCMAX7219.print7Seg("HELLO !!",8);
  /* Send the output buffer to the display */
  HCMAX7219.Refresh();  
  
  while(1);

}

Code: Select all

/* FILE:    HCMODU0082_Serial_7_Segment_Module_Example2
   DATE:    19/03/15
   VERSION: 0.2
   
REVISIONS:

12/03/15 Created version 0.1
19/03/15 Updated to work with V0.2 of the HCMAX7219 library

This is an example of how to use the Hobby Components serial 8 digit seven 7 
segment display module (HCMODU0082). 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() 
{
  HCMAX7219.Init();        
}

/* Main program */
void loop() 
{
  byte Loopcounter;
  byte Position;
  
  /* SCROLL SOME TEXT 5 TIMES BEFORE MOVING ON */
  for (Loopcounter = 0; Loopcounter <= 5; Loopcounter++)
  {
    /* We are scrolling 30 characters of text across the entire display */
    for (Position = 0; Position <= DISPLAYBUFFERSIZE + 30; Position++)
    { 
      /* Write the test to the output buffer at the position we require */
      HCMAX7219.print7Seg("HCMAX7219 SCROLLING TEXT DEMO ",Position);
      /* Send the output buffer to the display */
      HCMAX7219.Refresh();  
      delay(200);
    }
  }
  
  
  /* WE CAN ALSO DISPLAY INTEGER NUMBERS */
  
  /* Clear the output buffer */
  HCMAX7219.Clear();
  /* Write some text and output it*/
  HCMAX7219.print7Seg("INT NUM.",8);
  HCMAX7219.Refresh();
  delay(2000);
  
  /* display an example of a negative integer number */
  HCMAX7219.Clear();
  HCMAX7219.print7Seg(-1234567,8);
  HCMAX7219.Refresh();
  delay(2000);
  
  /* Clear the output buffer */ 
  HCMAX7219.Clear();
  /* Write some text and output it*/
  HCMAX7219.print7Seg("WITH DP.",8);
  HCMAX7219.Refresh();
  delay(2000);
  
  /* Show the DP in different places. Notice when the DP is at the 
    beginning the number is padded with a zero */
  HCMAX7219.Clear();
  for (Position = 1; Position <= 7; Position++)
  { 
    HCMAX7219.print7Seg(-1234567,Position,8);
    HCMAX7219.Refresh();
    delay(1000);
  }
}

Code: Select all

/* FILE:    HCMODU0082_Serial_Dot_Matrix_Example
   DATE:    19/03/15
   VERSION: 0.1
   
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() 
{
  HCMAX7219.Init();       
}


/* 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 AND INTEGER NUMBER */
  for(Position=0; Position <= 80; Position++)
  {
    HCMAX7219.Clear();
    HCMAX7219.printMatrix(-12345678, Position);
    HCMAX7219.Refresh();
    delay(80);
  }
  
  
  
  /* SCROLL AND INTEGER NUMBER WITH DECIMAL PLACE */
  for(Position=0; Position <= 96; Position++)
  {
    HCMAX7219.Clear();
    HCMAX7219.printMatrix(-12345678, 2, Position);
    HCMAX7219.Refresh();
    delay(80);
  }
  
}


Image

The library files can be downloaded below:

Latest Version (0.5)
HCMAX7219_V0_5.zip

Older version (0.4)
HCMAX7219_V0_4.zip

Older version (0.3)
HCMAX7219_V0_3.zip

Older version 0.2
HCMAX7219.zip
You do not have the required permissions to view the files attached to this post.

Kolki
Posts: 10
Joined: Mon Oct 09, 2017 8:31 pm

Re: HCMAX7219 - LED driver library

Post by Kolki » Tue Oct 10, 2017 12:31 pm

How many HCMAX7219 can the LED driver library handle?
I have 12 8x7segment display"s to handle.
The Arduino Led control library can only handle 8 display's on 1 instance.

andrew
Site Admin
Posts: 1374
Joined: Sun Aug 05, 2012 4:15 pm

Re: HCMAX7219 - LED driver library

Post by andrew » Tue Oct 10, 2017 4:08 pm

It's only limited by the amount of available memory in your Arduino. 12 drivers shouldn't be an issue. Just remember to change the #define NUMBEROFDRIVERS in the HCMAX7219.h file to 12
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

jeremixogg
Posts: 2
Joined: Tue Oct 10, 2017 5:03 pm

Re: HCMAX7219 - LED driver library

Post by jeremixogg » Tue Oct 10, 2017 5:08 pm

Do you think the memory of an arduino Uno will handle 24 modules ?

I also project to use real-time controllers, like buttons or even potentiometers.
Do you think it could mix well with your library, (and SPI library also) ?

andrew
Site Admin
Posts: 1374
Joined: Sun Aug 05, 2012 4:15 pm

Re: HCMAX7219 - LED driver library

Post by andrew » Wed Oct 11, 2017 8:52 am

Do you think the memory of an Arduino Uno will handle 24 modules ?
Yes the library itself will compile with that many modules. 24 modules will take an additional 10% of the Unos RAM. Obviously your own application will need leave enough spare memory for the library for them to work together.
I also project to use real-time controllers, like buttons or even potentiometers.
Do you think it could mix well with your library, (and SPI library also) ?
The library only uses CPU cycles when executing a library function or whilst pushing new data to the drivers with the Refresh() function. If your sketch isn't currently executing one of these functions then there wont be any library code running in the background.

It does use the hardware SPI interface to push the data to the drivers when performing a refresh. However, as it makes use of a chip select pin (LOAD) then you'll probably be able to connect other SPI slave devices so long as the code and the hardware make use of separate CS pins.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

Kolki
Posts: 10
Joined: Mon Oct 09, 2017 8:31 pm

Re: HCMAX7219 - LED driver library

Post by Kolki » Wed Oct 11, 2017 9:18 am

Thanks Andrew,

I will carry on with my project, and maby come back with some other questions.

Regards Albert

jeremixogg
Posts: 2
Joined: Tue Oct 10, 2017 5:03 pm

Re: HCMAX7219 - LED driver library

Post by jeremixogg » Wed Oct 11, 2017 11:23 am

Thanks Andrew.

I don't understand everything in your answer (as I'm Arduino beginner).

But I realize that my question was :
Do you think I could use the Scheduler library with SPI and yours together ?
This is more accurate ;)

andrew
Site Admin
Posts: 1374
Joined: Sun Aug 05, 2012 4:15 pm

Re: HCMAX7219 - LED driver library

Post by andrew » Wed Oct 11, 2017 2:33 pm

I've never used the scheduler library so I can't say for sure. They only thing I can say is that the HCMAX7219 library doesn't do anything special or use any interrupts so there's a a good chance it would work. The same goes for other third party libraries that use the SPI interface other than the HCMAX7219 has been written in a way that it should be able to coexist with libraries that use the SPI interface so long as they use a chip select function/pin.

So I'm afraid the best answer I can give is I'm not sure but probably :-)
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

Kolki
Posts: 10
Joined: Mon Oct 09, 2017 8:31 pm

Re: HCMAX7219 - LED driver library

Post by Kolki » Wed Oct 11, 2017 2:39 pm

Andrew,
Sorry to bother you again but i have one more question.
Is it possible to change the pin numbers fot DIN CLK LOAD as my project is completely wired .
My pinnumbers are DIN 22, LOAD 24 CLK 26.
It will be a great help if it is possible.
Thanks in advange.
Best regards Albert

andrew
Site Admin
Posts: 1374
Joined: Sun Aug 05, 2012 4:15 pm

Re: HCMAX7219 - LED driver library

Post by andrew » Wed Oct 11, 2017 4:14 pm

Not for the DIN (MOSI) and CLK (SCL) pins I'm afraid. The library makes use of the Arduinos hardware SPI interface which fixed to specific digital pins the location of which is dependent on the model of Arduino board you are using. Only the LOAD pin can be moved to another pin.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

Post Reply

Return to “Arduino”