Arduino MAX7219 7-Segment Display Tutorial
by MrSottong in Circuits > Arduino
54340 Views, 24 Favorites, 0 Comments
Arduino MAX7219 7-Segment Display Tutorial
MAX7219 is an IC that is used to drive 7-segment LEDs (up to 8 digits), block displays (bar displays), and 64 individual LEDs that are comon cathodes. To communicate with a microcontroller, MAX7219 uses the SPI communication system. So to drive 64 LEDs only need 3 ports of the microcontroller.
In this article I will show you how to use a 7-Segement module that uses IC MAX7219 as the driver.
Required components:
- MAX7219 7-Segment Module
- Arduino Nano
- wire Jumper
- USB mini
Required Library:
In this tutorial I use Arduino Nano board. If you have never used it. I suggest reading my previous article about "How to Use Arduino Nano".
Assemble All Components
Connect the Arduino board to the 7-Segment module. See the picture or instruction that I wrote below:
Arduino to 7-Segment
+5V => VCC
GND => GND
D12 => DIN
D11 => CLK
D10 => CS/LOAD
Add Library
After the circuit is complete. Add the "LedControl" library to the Arduino IDE.
To add a library to Arduino, you can read it in the article "How to Add an External Library to Arduino" that I made earlier".
Additional Functions
After adding the LedControl library. You can use additional functions to control the 7-Segment module.
- Argument
addr - address of the display digit - the position of the digit on the display (0..7)\ value - the value to be displayed. (0x00..0x0F)<p>dp sets the decimal point.</p>
- Function
setChar(addr,digit,value.dp); //to display the char type value for 7-bit ASCII encoding setDigit(addr,digit,value,bolean dp); //to display digits and characters in one function<br> setRow(addr,digit,value,boolean dp); //to display the object in the desired digit
For more details, please read here.
Upload Sketch
I have sketched for the trial of this 7-Segment module. You can copy the code below, then paste it in your sketch.
//We always have to include the library
#include "LedControl.h"
/*
Now we need a LedControl to work with.
***** These pin numbers will probably not work with your hardware *****
pin 12 is connected to the DataIn
pin 11 is connected to the CLK
pin 10 is connected to LOAD
We have only a single MAX72XX.
*/
LedControl lc=LedControl(12,11,10,1);
/* we always wait a bit between updates of the display */
unsigned long delaytime=500;
void setup() {
/* The MAX72XX is in power-saving mode on startup, we have to do a wakeup call */
lc.shutdown(0,false);
/* Set the brightness to a medium values */
lc.setIntensity(0,8);
/* and clear the display */
lc.clearDisplay(0);
}
void hello(){
lc.setChar(0,7,'H',false);
lc.setChar(0,6,'E',false);
lc.setChar(0,5,'L',false);
lc.setChar(0,4,'L',false);
lc.setChar(0,3,'0',false);
lc.setChar(0,2,'.',false);
lc.setChar(0,1,'.',false);
lc.setChar(0,0,'.',false);
delay(delaytime+1000);
lc.clearDisplay(0);
delay(delaytime);
lc.setDigit(0,7,1,false);
delay(delaytime);
lc.setDigit(0,6,2,false);
delay(delaytime);
lc.setDigit(0,5,3,false);
delay(delaytime);
lc.setDigit(0,4,4,false);
delay(delaytime);
lc.setDigit(0,3,5,false);
delay(delaytime);
lc.setDigit(0,2,6,false);
delay(delaytime);
lc.setDigit(0,1,7,false);
delay(delaytime);
lc.setDigit(0,0,8,false);
delay(1500);
lc.clearDisplay(0);
delay(delaytime);
}
void loop() {
hello();
}
Or download the file below:
Downloads
Result
Ejoy the result.
If there are questions just write them in the comments column.
See you in next article.