Reply to topic  [ 1 post ] 
HCMAX7219 - LED driver library 
Author Message
Site Admin

Joined: Sun Aug 05, 2012 4:02 pm
Posts: 633
Post HCMAX7219 - LED driver library
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:
#include <HCMAX7219.h>
HCMAX7219 HCMAX7219(DIN, CLK, LOAD);


Where:

DIN is the number for the digital pin connected to the first MAX7219 's DIN pin.
CLK is the number for the digital pin connected to the first MAX7219 's CLK pin.
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:
HCMAX7219.Init();


Initialises the library. This function should be executed once before any other library function.



Code:
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:
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:
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:
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:
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:
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:
HCMAX7219.Refresh()


Update all connected drivers with the contents of the output buffer.


Code:
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:
#define NUMBEROFDRIVERS 1



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

Code:
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:
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:
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:
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:
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:
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:
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:
/* 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:
/* 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:
/* 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 from github here:

https://github.com/HobbyComponents/HCMAX7219

Or directly from this forum:

Latest version (0.3)
Attachment:
HCMAX7219_V0_3.zip



Older version 0.2
Attachment:
HCMAX7219.zip


You do not have the required permissions to view the files attached to this post.


Thu Mar 12, 2015 4:17 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

Who is online

Users browsing this forum: Google [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Thank you to phpBB.com & phpBB.ro.
Design created by Florea Cosmin Ionut.
© 2011 All contents of this site are © Hobby Components LTD