Categories

Arduino MAX7219 7 segment display module example

The MAX7219  is a compact, serial input/output common-cathode display drivers that interface microprocessors (µPs) to 7-segment numeric LED displays of up to 8 digits, bar-graph displays, or 64 individual LEDs. Included on-chip are a BCD code-B decoder, multiplex scan circuitry, segment and digit drivers, and an 8×8 static RAM that stores each digit. Only one external resistor is required to set the segment current for all LEDs.

In this example we will use one of the MAX7219 modules with 7 segment displays that can be bought cheaply

These typically look like this

max7219-seven-segment-display

Connection

Vcc is connected to the VCC pin
Gnd is connected to the Gnd pin
pin 12 is connected to the DIN pin
pin 11 is connected to the CLK pin
pin 10 is connected to the CS pin

Code

This requires the LedControl library to be installed – https://github.com/wayoda/LedControl

#include "LedControl.h"
 
LedControl lc=LedControl(12,11,10,1);
// pin 12 is connected to the DIN pin
// pin 11 is connected to the CLK pin
// pin 10 is connected to the CS pin
// 1 as we are only using 1 MAX7219
 
void setup()
{
  // the zero refers to the MAX7219 number, it is zero for 1 chip
  lc.shutdown(0,false);// turn off power saving, enables display
  lc.setIntensity(0,8);// sets brightness (0~15 possible values)
  lc.clearDisplay(0);// clear screen
}
 
void loop()
{
  //numbers 7 to 0
  for (int a=0; a<8; a++)
  {
    lc.setDigit(0,a,a,false);
    delay(100);
  }
  delay(1000);
  //display number 8 on all segments
  for (int a=0; a<8; a++)
  {
    lc.setDigit(0,a,8,false);
    delay(100);
  }
  delay(1000);
  //
  for (int a=8; a>=0; a--)
  {
    lc.setDigit(0,a,a,false);
    delay(100);
  }
}

 

Links
8 digit 7 segment digit LED display can cascade finished product MAX7219 module

Share

Digit Shield overview

This shield uses a 4 digit, 7-segment display to give you the data you need. You can use it to make clocks, timers, show sensor data, or anything else you can dream up.

Here is a picture of the shield that I purchased, this version is slightly different than the original nootropic design version in that the resistors are surface mount types rather than the through hole ones. In this case the shield also did not come as a kit but was already assembled other than that its a basic copy, the reason for this is that the folks at nootropic made the shield open source and all design files are available. In theory you could create your own version, the only addition i would have is to perhaps using surface mount versions of the 2 IC’s used but that’s not a major improvement

Digit shield

Digit shield

If you would like to look at the schematics of the board I have put them on https://github.com/arduinolearning/Schematics-and-layouts/blob/master/digitshield_v1-0.pdf. I encourage you to look at the schematics to learn how this shield works, the main work is done by the 74Hc595 shift register and an IC that many may not have much knowledge of the 74LS247 BCD to seven-segment drive IC.

The IC does have some limitations in that it can only really display the numbers 0 to 9 and a few strange characters which can be made up using the segments, so you can display text of any description on this.

 

Features

The shield only uses 4 Arduino pins (2,3,4,5)
All through-hole parts for easy kit assembly , also comes in a pre-assembled form
Available in two display colors:  green or red-orange
On board reset button

There is a open source library to make it easier to use the shield, not that the shield is that difficult anyway. You can get the library from our github site at https://github.com/arduinolearning/Arduino-Libraries/blob/master/digitshieldlibrary.zip

 

Code

Here is the code adapted from the basic example which counts up to 1000 and displays this on the 7 segment displays

#include <DigitShield.h>
 
float counter = 0;
int d = 100;
 
 
void setup() 
{
  DigitShield.begin();
  DigitShield.setPrecision(0);
}
 
void loop() 
{
  DigitShield.setValue(counter);
  counter = counter + 1;
  delay(d);
  if (counter >= 9999) 
  {
    counter = 0;
  }
}

The page at http://nootropicdesign.com/digitshield/ explains the functions in the library in more detail with pictures

 

Links

The module comes in at under $9 a piece
Digit Shield 4 digit LED display module

Share

Arduino and a 7 segment display

In this example we will connect a 7 segment display to an Arduino

Schematic

arduino 7 segment

arduino 7 segment

Code


const int  A = 4;
const int  B = 5;
const int  C = 6;
const int  D = 7;
const int  E = 8;
const int  F = 9;
const int  G = 10;

//all of the values below are for a common anode display
//coomon cathode would need the values inverted HIGH -> LOW
void clearDisplay()
{
//sets the LEDs high
digitalWrite(A, HIGH);
digitalWrite(B, HIGH);
digitalWrite(C, HIGH);
digitalWrite(D, HIGH);
digitalWrite(E, HIGH);
digitalWrite(F, HIGH);
digitalWrite(G, HIGH);
}

void one()
{
//Displays 1
digitalWrite(A, HIGH);
digitalWrite(B, HIGH);
digitalWrite(C, HIGH);
digitalWrite(D, HIGH);
digitalWrite(E, LOW);
digitalWrite(F, LOW);
digitalWrite(G, HIGH);
}

void two()
{
//Displays 2
digitalWrite(A, LOW);
digitalWrite(B, LOW);
digitalWrite(C, HIGH);
digitalWrite(D, LOW);
digitalWrite(E, LOW);
digitalWrite(F, HIGH);
digitalWrite(G, LOW);
}

void three()
{
//Displays 3
digitalWrite(A, LOW);
digitalWrite(B, LOW);
digitalWrite(C, LOW);
digitalWrite(D, LOW);
digitalWrite(E, HIGH);
digitalWrite(F, HIGH);
digitalWrite(G, LOW);
}

void four()
{
//Displays 4
digitalWrite(A, HIGH);
digitalWrite(B, LOW);
digitalWrite(C, LOW);
digitalWrite(D, HIGH);
digitalWrite(E, HIGH);
digitalWrite(F, LOW);
digitalWrite(G, LOW);
}

void five()
{
//Displays 5
digitalWrite(A, LOW);
digitalWrite(B, HIGH);
digitalWrite(C, LOW);
digitalWrite(D, LOW);
digitalWrite(E, HIGH);
digitalWrite(F, LOW);
digitalWrite(G, LOW);
}

void six()
{
//Displays 6
digitalWrite(A, LOW);
digitalWrite(B, HIGH);
digitalWrite(C, LOW);
digitalWrite(D, LOW);
digitalWrite(E, LOW);
digitalWrite(F, LOW);
digitalWrite(G, LOW);
}

void seven()
{
//Displays 7
digitalWrite(A, LOW);
digitalWrite(B, LOW);
digitalWrite(C, LOW);
digitalWrite(D, HIGH);
digitalWrite(E, HIGH);
digitalWrite(F, HIGH);
digitalWrite(G, HIGH);
}

void eight()
{
//Displays 8
digitalWrite(A, LOW);
digitalWrite(B, LOW);
digitalWrite(C, LOW);
digitalWrite(D, LOW);
digitalWrite(E, LOW);
digitalWrite(F, LOW);
digitalWrite(G, LOW);
}

void nine()
{
//Displays 9
digitalWrite(A, LOW);
digitalWrite(B, LOW);
digitalWrite(C, LOW);
digitalWrite(D, LOW);
digitalWrite(E, HIGH);
digitalWrite(F, LOW);
digitalWrite(G, LOW);
}

void zero()
{
//Displays 0
digitalWrite(A, LOW);
digitalWrite(B, LOW);
digitalWrite(C, LOW);
digitalWrite(D, LOW);
digitalWrite(E, LOW);
digitalWrite(F, LOW);
digitalWrite(G, HIGH);
}
void LoopDisplay()
{
//Loop through all numbers
one();
delay(1000);
two();
delay(1000);
three();
delay(1000);
four();
delay(1000);
five();
delay(1000);
six();
delay(1000);
seven();
delay(1000);
eight();
delay(1000);
nine();
delay(1000);
zero();
delay(1000);
}

void setup()
{
//Setup our pins
pinMode(A, OUTPUT);
pinMode(B, OUTPUT);
pinMode(C, OUTPUT);
pinMode(D, OUTPUT);
pinMode(E, OUTPUT);
pinMode(F, OUTPUT);
pinMode(G, OUTPUT);
}

void loop()
{
clearDisplay();
LoopDisplay();
}

Links

UNO R3 MEGA328P ATMEGA16U2 + USB Cable

Share