7 Segment Display (Anode) with MAX7219 / MAX7221 and Raspberry Pi

The most common form of 7-segment displays are “Common Cathode”, for which et al. the microchips MAX7219 and MAX7221 are intended. There are also “Common Anode”, which are usually a lot cheaper. However, these are not directly compatible with such a microchip. How it all works is shown in this tutorial. Anyone who wants to know more about anodes or the differences can do it  here.



Inspired by this article, I came up with the idea to make anode displays compatible with the Pi. For that we need:

  • 1-8 Common Anode 7-segment displays (for example, these here)
  • MAX7219 LED Display Driver (or MAX7221)
  • if necessary soldering tools and solder



Let’s take a look at the datasheet of the IC first.


The connection with the Raspberry Pi looks like this:

  • RPi Pin 2 (5V) => Pin 19 (V+)
  • RPi Pin 2 (5V) with 10k ohm resistor => Pin 18 (ISET)
  • RPi Pin 6 (GND) => Pin 4 and Pin 9 (GND)
  • RPi Pin 19 => Pin 1 (DIN)
  • RPi Pin 23 => Pin 13 (CLK)
  • RPi Pin 24 => Pin 12 (LOAD)


Now it goes to the connections between the 7-segment display and the MAX7219. In addition, the structure of such a display In addition, the structure of such a display (to make sure the pins are the same, you can test each pin on two 1.5V batteries in series, V+ on the positive pole and the respective pin on the negative pole, which V + pin you connect does not matter):

Usually, for a cathode display it would be DIG 0 – DIG 7 for each of the V+ of a display (therefore also maximally 8 segments per MAx7219) and SEG A to SEG DP connected parallel to the respective connections of the segment display (SEG A to all pin A’s of the segments, etc.).But since anodes are now polarized the other way round, we also have to swap the connections:

  • DIG 0 => Connections A (parallel to all)
  • DIG 7 => Connections DP (parallel to all)
  • SEG A => V + the segment on the far right
  • SEG B => V + the second segment from the right
  • SEG DP => V + the leftmost segment (only for 8 segments)

If you have less than 8 segments, you will go from right to left all through and some SEG pins will be empty. For example. I have only 4 segments connected to SEG A – SEG D.

Soldered to a breadboard it looks like this:




First of all, we install a library for the MAX7219 / 7221 so that we can control it more easily. If you have already done this (for example because of the LED dot matrix) you can, of course, skip it.

git clone https://github.com/rm-hull/max7219.git && cd max721

After the installation

sudo python setup.py install

You can already test the displays. Inspired by this article I wrote a script for the Pi:

sudo nano examples/segment.py

As you can see I have already predefined all numbers and some letters. Some letters (for example M, N, X, Y, … can not be displayed correctly on a 7-segment display, so they are missing). You can also define combinations for other characters, but be careful to start from the back (for example, only segment G would be 0b10000000, segment A would equal 0b00000010, and so on).

Here are two pictures with input “1234” and “StOP” (pay attention to upper / lower case, because I did not define all letters).


Have fun with it!

2 Responses

  1. Hey,

    Can you help me in getting through with Max7219 and Common Anode interface with raspberry pi ?

  2. nov 2019 – doesn’t work. Luma not recognized, install script doesn’t complete ( typos in routine) Another out of date article for Python, and another reason I hate this open source dross.


Leave a Comment

Your email address will not be published.

Subscribe to Raspberry Pi Tutorials and don't miss any new Tutorial!