Manage a LED matrix with Arduino

projet-electronique-gestion-dune-matrice-des-led-avec-arduino-max7219cng

projet-electronique-gestion-dune-matrice-des-led-avec-arduino-principe

Objectives and analysis of operation

The project involves the management of a matrix of LED 8X8 based Arduino using the circuit MAX7219CNG . The electronic project uses a bookseller for the management of the circuit MAX7219CNG with SPI link. This mini project highlighted the use of the bookseller with other secondary functions (shift, conversion, …).

 

 

the matrix operation of LEDs 8 × 8

projet-electronique-gestion-dune-matrice-des-led-avec-arduino-matrice-led

 

The LED matrix consists of 8 rows and 8 columns. the matrix can be likened to a 1D array of 8 elements, each array element is 8-bit or Ex B00001111 0x0F in the figure below illustrates the passage of a matrix 8 × 8 array of 8 elements Bye-type or unsigned char. We will see in the following function that displays the code in the matrix 8 × 8.

The module used is based on MAX7219 with a serial link for data. The SPI bus consists of three sons:

  • CS: Chip Select for activation model
  • CLK: clock for synchronous data. The set clock speeds serial data transmission
  • DIN: The 8-bit serial data

More details on the serial transmission: SPI

projet-electronique-gestion-dune-matrice-des-led-avec-arduino-matrice-fonctionnement

Comments on the program

  • void int2BitArray (unsigned char DATAIN, unsigned char size, byte * dataArray)

The int2BitArray function converts a char variable into an array of N bits (N = 8 bits)

Ex1: for DataIN = 10, size = 8 then the output variable dataArray [8] = {0,0,0,0,1,0,1,0] (equivalent to B00001010)
Ex2: DataIN = 127, height = 8, then the output variable dataArray [8] = {0,1,1,1,1,1,1,1] (equivalent to B011111111)

  • void DataShiftArray (unsigned char NumShift, unsigned char size, byte * DataIn, byte * DataOutShift)

DataShiftArray the function you can move right in an array of length “size” bits (binary table) DataIn, the result is stored and then returned to the table DataOutShift. At first the table DataOutShift is assumed initialized to 0.

Eg NumShift = 3 size = 8 DataIn [8] = {1,1,1,1,0,0,0,0} then DataOutShift [8] = {0,0,0, 1,1,1 , 1.0}.

The aim of the function is to shift an object in the 8 × 8 matrices of LEDs.

Cascade assembly of matrices

Each matrix is defined by the index are the first at index 0, the second 1 … To write in a matrix simply specify the index of the matrix.

projet-electronique-gestion-dune-matrice-des-led-avec-arduino

The functions available in the bookshop LedControl.h (MAX7219 / MAX7221)

class LedControl {
    private
        /* The array for shifting the data to the devices */
        byte spidata[16];
        /* Send out a single command to the device */
        void spiTransfer(int addr, byte opcode, byte data);

        /* We keep track of the led-status for all 8 devices in this array */
        byte status[64];
        /* Data is shifted out of this pin*/
        int SPI_MOSI;
        /* The clock is signaled on this pin */
        int SPI_CLK;
        /* This one is driven LOW for chip selectzion */
        int SPI_CS;
        /* The maximum number of devices we use */
        int maxDevices;

    public:
        /*
         * Create a new controler
         * Params :
         * dataPin                pin on the Arduino where data gets shifted out
         * clockPin                pin for the clock
         * csPin                pin for selecting the device
         * numDevices        maximum number of devices that can be controled
         */
        LedControl(int dataPin, int clkPin, int csPin, int numDevices=1);

        /*
         * Gets the number of devices attached to this LedControl.
         * Returns :
         * int        the number of devices on this LedControl
         */
        int getDeviceCount();

        /*
         * Set the shutdown (power saving) mode for the device
         * Params :
         * addr        The address of the display to control
         * status        If true the device goes into power-down mode. Set to false
         *                for normal operation.
         */
        void shutdown(int addr, bool status);

        /*
         * Set the number of digits (or rows) to be displayed.
         * See datasheet for sideeffects of the scanlimit on the brightness
         * of the display.
         * Params :
         * addr        address of the display to control
         * limit        number of digits to be displayed (1..8)
         */
        void setScanLimit(int addr, int limit);

        /*
         * Set the brightness of the display.
         * Params:
         * addr                the address of the display to control
         * intensity        the brightness of the display. (0..15)
         */
        void setIntensity(int addr, int intensity);

        /*
         * Switch all Leds on the display off.
         * Params:
         * addr        address of the display to control
         */
        void clearDisplay(int addr);

        /*
         * Set the status of a single Led.
         * Params :
         * addr        address of the display
         * row        the row of the Led (0..7)
         * col        the column of the Led (0..7)
         * state        If true the led is switched on,
         *                if false it is switched off
         */
        void setLed(int addr, int row, int col, boolean state);

        /*
         * Set all 8 Led's in a row to a new state
         * Params:
         * addr        address of the display
         * row        row which is to be set (0..7)
         * value        each bit set to 1 will light up the
         *                corresponding Led.
         */
        void setRow(int addr, int row, byte value);

        /*
         * Set all 8 Led's in a column to a new state
         * Params:
         * addr        address of the display
         * col        column which is to be set (0..7)
         * value        each bit set to 1 will light up the
         *                corresponding Led.
         */
        void setColumn(int addr, int col, byte value);

        /*
         * Display a hexadecimal digit on a 7-Segment Display
         * Params:
         * addr        address of the display
         * digit        the position of the digit on the display (0..7)
         * value        the value to be displayed. (0x00..0x0F)
         * dp        sets the decimal point.
         */
        void setDigit(int addr, int digit, byte value, boolean dp);

        /*
         * Display a character on a 7-Segment display.
         * There are only a few characters that make sense here :
         *        '0','1','2','3','4','5','6','7','8','9','0',
         *  'A','b','c','d','E','F','H','L','P',
         *  '.','-','_',' '
         * Params:
         * addr        address of the display
         * digit        the position of the character on the display (0..7)
         * value        the character to be displayed.
         * dp        sets the decimal point.
         */
        void setChar(int addr, int digit, char value, boolean dp);
};

 

Example of use of the program bookseller

//Bookseller import !
#include "LedControl.h"

/*
 Configuring pines (MAX72XX)
 LedControl lc=LedControl(12,11,10,1);
 Pin 12  connected to DataIn
 Pin 11  connected to CLK
 Pin 10  connected to LOAD
*/

LedControl lc=LedControl(12,10,11,1);

/* Delay commissioning of the display */
unsigned long delaytime=100;

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 writeArduinoOnMatrix() {

  /* Tables 8 byte, each byte consists of 8 bits (8x8=64) */
  byte t[8]={B00000000,B11111111,B11111111,B00011000,B00011000,B00011000,B00011000,B00011000};
  byte Data[8]={0,0,0,0,0,0,0,0};
  byte DataShif[8]={0,0,0,0,0,0,0,0};
  byte XData[8]={B10111101,B11000011,B10011001,B10011001,B01000010,B01111110,B10011001,B10011001};
  byte EM[8]={B11110001,B11000011,B10100101,B10011001,B11111001,B10000001,B10000001,B11110001};

  /* Display T character, column by column (8 entries) */
  for(int i=0;i<8;i++)
  {
    // View the online t [i] to the position of column i
    lc.setColumn(0,i,t[i]);
    delay(delaytime);
  }
  lc.clearDisplay(0);

  delay(1000);

  /* Display of the carachter T line by line (Rotate 90 ° to the setColumn (function (8 entries)*/
  for(int i=0;i<8;i++)
  {
    // View the column t[i] to the position of the line i
    lc.setRow(0,i,t[i]);
    delay(delaytime);
  }
  lc.clearDisplay(0);
  delay(1000);

  /* Writing in the display pixel by pixel (8x8 scriptures) */
  for(int k=0;k<8;k++)
  {
    //Right shift value = k [0..7]
    DataShiftArray(k,8, EM,DataShif )  ;
    for(int i=0;i<8;i++)
    {
      // Conversion Byte DataShif [i] in 8-bit binary
      int2BitArray( DataShif[i],8 ,Data );
      for(int j=0;j<8;j++)
      {
        // Viewing the Big Data [j] at the position (i, j) of the matrix (8x8)
        lc.setLed(0,i,j,Data[j]);
        //delay(1);
      }
    }
    delay(1000);
    lc.clearDisplay(0);
  }

}

void int2BitArray(unsigned char dataIn,unsigned char taille, byte *dataArray)
{
  int i=0;

  for(i=0;i<taille;i++)
    dataArray[taille-i-1]= (dataIn>>i)&0x01;
}

void DataShiftArray(unsigned char NumShift,unsigned char taille,  byte *DataIn, byte *DataOutShift)
{
  int i=0;

  for(i=0;i<taille;i++)
    DataOutShift[i]= (DataIn[i]>>NumShift);
}

void loop() {
  writeArduinoOnMatrix();
}

 

 

Bookseller project files + C e project (.rar)

 

Photos of the electronic project

projet-electronique-gestion-dune-matrice-des-led-avec-arduino-photos-projet-6-1500x1125

projet-electronique-gestion-dune-matrice-des-led-avec-arduino-photos-projet-4-1500x1125 projet-electronique-gestion-dune-matrice-des-led-avec-arduino-photos-projet-3-1500x1125

projet-electronique-gestion-dune-matrice-des-led-avec-arduino-photos-projet-7-1500x1125

projet-electronique-gestion-dune-matrice-des-led-avec-arduino-photos-projet-1-1500x1125

 


 

 

(Visited 111 times, 1 visits today)

Post Author: gyoby

Leave a Reply

Your email address will not be published. Required fields are marked *