Remarks

MAX7219
Status
Source code GitHub
NuGet package

The MAX7219 is an LED display driver capable of driving 64 outputs. As well, the MAX7219 contains an 2-wire data bus allowing multiple MAX7219 chip to be connected together and controlled by a single I2C interface.

Although the MAX7219 can be used as a general purpose IO expander, it almost exclusively used to drive either 2-dimensional LED arrays (commonly 8x8) or an array of multi-segment displays (commonly 8 7-segment displays). The MAX7219 contains specific logic to display pre-configured characters when driving 7 segment displays, specifically: 0-9, E, H, L, P and -.

As it's most commonly used to as a display controller, you'll find it in the Meadow.Foundation.Displays namespace.

Code Example

public class MeadowApp : App<F7Micro, MeadowApp>
{
    Max7219 display;

    public MeadowApp()
    {
        Init();

        while(true)
        {
            TestDigitalMode();
            TestCharacterMode();
            CharacterDemo();
        }
    }

    void CharacterDemo()
    {
        display.SetMode(true);
        display.ClearAll();

        for (int i = 0; i < 8; i++)
        {
            display.SetCharacter(Max7219.CharacterType.Blank, i);
        }

        for (int i = 980; i < 999; i++)
        {
            display.SetNumber(i);
            display.Show();
        }

        display.SetCharacter(Max7219.CharacterType.Hyphen, 0);
        display.SetCharacter(Max7219.CharacterType.Hyphen, 1);
        display.SetCharacter(Max7219.CharacterType.P, 2);
        display.SetCharacter(Max7219.CharacterType.L, 3);
        display.SetCharacter(Max7219.CharacterType.E, 4);
        display.SetCharacter(Max7219.CharacterType.H, 5);
        display.SetCharacter(Max7219.CharacterType.Hyphen, 6);
        display.SetCharacter(Max7219.CharacterType.Hyphen, 7);
        display.Show();

        Thread.Sleep(1000);
    }

    void TestCharacterMode()
    {
        display.SetMode(true);

        for (int i = 0; i < (int)Max7219.CharacterType.count; i++)
        {
            for (int digit = 0; digit < 8; digit++)
            {
                display.SetCharacter((Max7219.CharacterType)i, digit, i%2 == 0);
            }
            display.Show();
            Console.WriteLine(((Max7219.CharacterType)i).ToString());
        }
    }

    void TestDigitalMode()
    {
        display.SetMode(false);

        for (byte i = 0; i < 64; i++)
        {
            for(int d = 0; d < 8; d++)
            {
                display.SetDigit(i, d);
            }
            display.Show();
        }
    }

    public void Init()
    {
        Console.WriteLine("Init...");

        display = new Max7219(Device, Device.CreateSpiBus(), Device.Pins.D02, 1, true);
    }
}

Sample projects available on GitHub

Characteristic Locus
Inheritance System.Object > Max7219
Namespace Meadow.Foundation.Displays
Assembly Max7219.dll

Syntax

public class Max7219 : DisplayBase

Constructors

View Source

Max7219(IIODevice, ISpiBus, IPin, Int32, Max7219.Max7219Type)

Creates a Max7219 Device given a to communicate over and the number of devices that are cascaded.

Declaration
public Max7219(IIODevice device, ISpiBus spiBus, IPin csPin, int deviceCount = 1, Max7219.Max7219Type maxMode = Max7219.Max7219Type.Display)

Parameters

Type Name Description
IIODevice device
ISpiBus spiBus
IPin csPin
System.Int32 deviceCount
Max7219.Max7219Type maxMode
View Source

Max7219(ISpiBus, IDigitalOutputPort, Int32, Max7219.Max7219Type)

Declaration
public Max7219(ISpiBus spiBus, IDigitalOutputPort csPort, int deviceCount = 1, Max7219.Max7219Type maxMode = Max7219.Max7219Type.Display)

Parameters

Type Name Description
ISpiBus spiBus
IDigitalOutputPort csPort
System.Int32 deviceCount
Max7219.Max7219Type maxMode

Fields

View Source

NumDigits

Number of digits Register per Module

Declaration
public const int NumDigits = 8

Field Value

Type Description
System.Int32

Properties

View Source

ColorMode

Declaration
public override DisplayColorMode ColorMode { get; }

Property Value

Type Description
DisplayColorMode
View Source

DeviceCount

Number of cascaded devices

Declaration
public int DeviceCount { get; }

Property Value

Type Description
System.Int32
View Source

Height

Declaration
public override uint Height { get; }

Property Value

Type Description
System.UInt32
View Source

Length

Gets the total number of digits (cascaded devices * num digits)

Declaration
public int Length { get; }

Property Value

Type Description
System.Int32
View Source

SpiClockFrequency

MAX7219 Spi Clock Frequency

Declaration
public static int SpiClockFrequency { get; }

Property Value

Type Description
System.Int32
View Source

Width

Declaration
public override uint Width { get; }

Property Value

Type Description
System.UInt32

Methods

View Source

Clear(Boolean)

Clears the buffer from the given start to end and flushes

Declaration
public override void Clear(bool updateDisplay = false)

Parameters

Type Name Description
System.Boolean updateDisplay
View Source

Clear(Int32, Int32)

Clears the buffer from the given start to end (exclusive) and flushes

Declaration
public void Clear(int start, int end)

Parameters

Type Name Description
System.Int32 start
System.Int32 end
View Source

DrawBitmap(Int32, Int32, Int32, Int32, Byte[], BitmapMode)

Declaration
public override void DrawBitmap(int x, int y, int width, int height, byte[] bitmap, BitmapMode bitmapMode)

Parameters

Type Name Description
System.Int32 x
System.Int32 y
System.Int32 width
System.Int32 height
System.Byte[] bitmap
BitmapMode bitmapMode
View Source

DrawBitmap(Int32, Int32, Int32, Int32, Byte[], Color)

Declaration
public override void DrawBitmap(int x, int y, int width, int height, byte[] bitmap, Color color)

Parameters

Type Name Description
System.Int32 x
System.Int32 y
System.Int32 width
System.Int32 height
System.Byte[] bitmap
Color color
View Source

DrawPixel(Int32, Int32)

Declaration
public override void DrawPixel(int x, int y)

Parameters

Type Name Description
System.Int32 x
System.Int32 y
View Source

DrawPixel(Int32, Int32, Color)

Declaration
public override void DrawPixel(int x, int y, Color color)

Parameters

Type Name Description
System.Int32 x
System.Int32 y
Color color
View Source

DrawPixel(Int32, Int32, Boolean)

Declaration
public override void DrawPixel(int x, int y, bool colored)

Parameters

Type Name Description
System.Int32 x
System.Int32 y
System.Boolean colored
View Source

GetCharacter(Int32, Int32)

Declaration
public Max7219.CharacterType GetCharacter(int digit, int deviceId = 0)

Parameters

Type Name Description
System.Int32 digit
System.Int32 deviceId

Returns

Type Description
Max7219.CharacterType
View Source

GetDigit(Int32, Int32)

Declaration
public byte GetDigit(int digit, int deviceId = 0)

Parameters

Type Name Description
System.Int32 digit
System.Int32 deviceId

Returns

Type Description
System.Byte
View Source

SetBrightness(Int32)

Sets the brightness of all cascaded devices to the same intensity level.

Declaration
public void SetBrightness(int intensity)

Parameters

Type Name Description
System.Int32 intensity

intensity level ranging from 0..15.

View Source

SetCharacter(Max7219.CharacterType, Int32, Boolean, Int32)

Declaration
public void SetCharacter(Max7219.CharacterType character, int digit, bool showDecimal = false, int deviceId = 0)

Parameters

Type Name Description
Max7219.CharacterType character
System.Int32 digit
System.Boolean showDecimal
System.Int32 deviceId
View Source

SetDigit(Byte, Int32, Int32)

Declaration
public void SetDigit(byte value, int digit, int deviceId = 0)

Parameters

Type Name Description
System.Byte value
System.Int32 digit
System.Int32 deviceId
View Source

SetMode(Max7219.Max7219Type)

Declaration
public void SetMode(Max7219.Max7219Type maxMode)

Parameters

Type Name Description
Max7219.Max7219Type maxMode
View Source

SetNumber(Int32, Int32)

Declaration
public void SetNumber(int value, int deviceId = 0)

Parameters

Type Name Description
System.Int32 value
System.Int32 deviceId
View Source

SetPenColor(Color)

Declaration
public override void SetPenColor(Color pen)

Parameters

Type Name Description
Color pen
View Source

Show()

Writes all the Values to the devices.

Declaration
public override void Show()
View Source

TestDisplay(Int32)

Declaration
public void TestDisplay(int timeInMs = 1000)

Parameters

Type Name Description
System.Int32 timeInMs
View Source

WriteBuffer(Byte[,])

Writes a two dimensional buffer containing all the values to the devices.

Declaration
public void WriteBuffer(byte[, ] buffer)

Parameters

Type Name Description
System.Byte[,] buffer