Maker.io main logo

How to Interface an LED Matrix with the MAX7219

2021-06-23 | By Maker.io Staff

License: General Public License

Building an Arduino-Based Spectrum Analyzer-How to Interface an LED Matrix with the MAX7219

This series of articles discusses how to design and build an Arduino-based spectrum analyzer and graphic equalizer that can spice up your home Hi-Fi system. This article introduces you to the MAX7219 seven-segment and LED display controller and how you can interface it with an Arduino.

A Look at the MAX7219 Display Controller

The MAX7219 is a popular IC for controlling common-cathode seven-segment displays and LED matrices. One of its major benefits is the serial interface, which allows microcontrollers, such as the ATMega328PU found in the Arduino UNO, to communicate with the controller IC using only three digital I/O pins. Besides that, it’s possible to connect up to eight MAX7219 in series. Doing so forms a cascade that can either control up to 64 seven-segment displays or 512 individual LEDs without occupying any additional I/O pins on the microcontroller.

As mentioned, the MAX7219 only requires three lines to communicate with a microcontroller such as the ATMega328PU:

Scheme-it

Besides the three connections between the MCU (IC1) and the LED display driver (IC2), I also added two resistors. R2 connects the reset pin of the ATMega328PU to VCC, which prevents the MCU from resetting. You could add a push-button that pulls the reset pin low to allow the user to reboot the MCU when needed. The other resistor (R1) connects the ISET pin of the MAX7219CNG to GND. This resistor determines the current that flows through the individual LEDs of the display. The current that flows through the LEDs is roughly ten times the current through R1. You can tweak this value to alter the brightness of the LEDs. Note that selecting the wrong resistor value might permanently damage the display or the ICs.

You can use this online calculator to determine the value of R1. In my case, I chose a 6K resistor for R1, which should keep the displays and the ICs well within their rated specifications.

Running the MCU without an Arduino Board

As noted before, the ATMega328PU is the same MCU that powers the Arduino UNO. However, in this project, I only employ the microcontroller without adding the entire Arduino board. Doing so allows me to keep the final product as small as possible, which results in a more professional finish and lower PCB manufacturing costs. Using the ATMega328PU without the rest of the Arduino board requires you to add a few additional components to the setup from above:

Scheme-it

Besides the 16 MHz crystal with two 22pF non-polarized capacitors, I also included two polarized electrolytic capacitors (C3 and C4) near the VCC and GND pins of the two ICs. These additional capacitors help smooth the power input to those chips. Omitting these capacitors might lead to a brown-out issue, which results in the microcontroller constantly resetting itself. Note that this circuit doesn’t contain any components that allow you to program the MCU directly, so you’ll still need an Arduino board to flash the program onto the microcontroller.

Cascading Multiple MAX7219 Display Drivers

As mentioned earlier, a single MAX7219 display controller can drive up to 64 individual LEDs, either arranged in a grid or as eight independent seven-segment displays. I’ll use three 8x8 LED matrix displays in this project, which results in push-button192 individual LEDs. Therefore, this project requires three MAX7219 chips to function as intended. Luckily, you can cascade up to eight MAX7219 controllers to control up to 512 LEDs. Each controller IC has a DIN (data in) and a DOUT (data out) pin for that purpose. The first chip in the chain communicates directly with the ATMega328PU through its DIN pin. Then, the first MAX7219’s DOUT pin connects to the next MAX7219’s DIN pin. You can repeat this process up to eight times:

Scheme-it

Connecting the LED Matrix Displays

The schematic contains all the ICs and the connections between them. Besides that, it also includes all other relevant components such as the resistors, capacitors, and a 16 MHz crystal for clock generation. However, the drawing omits the connections to the 8x8 matrix displays, as the schematic will quickly become confusing with those lines added. Instead of adding the displays to the schematic, it helps to investigate how an LED matrix is typically connected internally:

LED Matrix

The internal structure of an 8x8 LED matrix (Image Source)

The image above outlines the internal structure of an 8x8 LED matrix display. Note that you can choose the order of the columns and rows arbitrarily. However, I recommend you use this order, as it corresponds to the one used in the LedControl Arduino library that we’ll later use to display values on the three 8x8 matrix displays.

As mentioned earlier, the MAX7219 is a common-cathode LED driver. Therefore, the digit pins connect the cathodes of the LEDs. Each digit signal represents one line of the display. The segment connections correspond to the columns.

The Audio Input Circuit

This project uses the MCU's built-in ADC to convert the analog audio input to digital values that the MCU can process to determine the individual frequency components of the audio signal. Unfortunately, feeding the audio output signal of a computer, for example, directly into the Arduino may result in a loss of information due to clipping. The loss happens because the audio signal is an AC signal that dips into negative voltages, which the ADC can’t convert. Therefore, this project uses a simple DC bias circuit that elevates the zero point (total silence) from 0V to 2.5V. Therefore, when the audio input signal goes below 0V, the actual input at the ADC will still be between 0V and 2.5V:

The two resistors per audio channel pull each ADC input to 2.5V when the circuit is open. For this to work, the resistors must have the same value. Alternatively, you could also replace the resistors with potentiometers to allow tweaking of the DC bias. Doing so helps to prevent clipping issues when the audio input is very loud. The added 1uF capacitors act as high-pass filters to filter out low frequencies. Note that this is a simple DC biasing circuit, and there’s room for improvements. However, I used fewer components to reduce the PCB complexity and size.

Another way to achieve better readings is to derive a dedicated analog reference voltage and feed that into the AREF pin. This method could potentially damage the internal components of the IC. Therefore, I used the MCU’s built-in 5V reference, which worked perfectly fine for this project.

PCB Design Files

You can download the Gerber PCB design files here. The PCB design comes as a ZIP package that contains files that adhere to the RS247x specifications, and you can directly upload the package to the DigiKey PCB Builder service and get an instant quote.

Summary

The MAX7219 is a powerful LED driver that can control up to 64 individual LEDs with a single IC. The display controller communicates with an MCU over a serial interface that uses only three digital I/O lines. You can connect up to eight MAX7219 chips in series to control a total number of 512 individual LEDs without occupying additional I/O lines. This project uses an ATMega328PU as its main microcontroller, which is the same MCU found on the Arduino UNO board. The audio input section of the circuit allows the analog-to-digital converter of the MCU to properly read and process the AC audio input signal without clipping errors. It’s a simple circuit that sacrifices some accuracy to keep the final product as small as possible and easy to understand and modify.

制造商零件编号 MAX7219CWG+
IC DRVR 7 SEGMNT 8 DIGIT 24SOIC
Analog Devices Inc./Maxim Integrated
¥143.43
Details
制造商零件编号 1818
LED MATRIX 8X8 SQUARE AMBER
Adafruit Industries LLC
¥37.92
Details
制造商零件编号 MAX7219ENG+
IC DRVR 7 SEGMENT 8 DIGIT 24DIP
Analog Devices Inc./Maxim Integrated
¥114.53
Details
制造商零件编号 ATMEGA328-PU
IC MCU 8BIT 32KB FLASH 28DIP
Microchip Technology
¥21.41
Details
制造商零件编号 ECS-160-20-4X
CRYSTAL 16.0000MHZ 20PF TH
ECS Inc.
¥4.97
Details
制造商零件编号 C317C220J2G5TA
CAP CER 22PF 200V NP0 RADIAL
KEMET
¥2.36
Details
制造商零件编号 CF14JT10K0
RES 10K OHM 5% 1/4W AXIAL
Stackpole Electronics Inc
¥0.81
Details
制造商零件编号 MFR-25FBF52-5K9
RES 5.9K OHM 1% 1/4W AXIAL
YAGEO
¥0.81
Details
制造商零件编号 ESK106M016AC3AA
CAP ALUM 10UF 20% 16V RADIAL TH
KEMET
¥1.55
Details
制造商零件编号 ESL107M016AC3AA
CAP ALUM 100UF 20% 16V RADIAL TH
KEMET
¥1.63
Details
Add all DigiKey Parts to Cart
TechForum

Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.

Visit TechForum