Remarks

Max7219
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.Displays.Max7219

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

Max7219 display;

public override Task Initialize()
{
    Resolver.Log.Info("Initialize...");

    display = new Max7219(Device.CreateSpiBus(), Device.Pins.D01, 1, Max7219.Max7219Mode.Character);

    return base.Initialize();
}

void TestCharacterMode()
{
    display.SetMode(Max7219.Max7219Mode.Character);
    //show every supported character 
    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();
    }
}

void TestDigitalMode()
{
    Resolver.Log.Info("Digital test");

    display.SetMode(Max7219.Max7219Mode.Digital);
    //control indivial LEDs - for 8x8 matrix configurations - use the Meadow graphics library
    for (byte i = 0; i < 64; i++)
    {
        for (int d = 0; d < 8; d++)
        {
            display.SetDigit(i, d);
        }
        display.Show();
    }
}

public override Task Run()
{
    while (true)
    {
        TestDigitalMode();
        TestCharacterMode();
    }
}

Sample project(s) available on GitHub

Wiring Example

To wire a Max7219 to your Meadow board, connect the following:

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

Syntax

public class Max7219 : IPixelBuffer, IGraphicsDisplay

Constructors

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

Create a new Max7219 object

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

Parameters

Type Name Description
ISpiBus spiBus

SPI bus

IDigitalOutputPort chipselectPort

Chip select port

System.Int32 deviceCount

Number of cascaded devices

Max7219.Max7219Mode maxMode

Display mode of max7219

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

Create a new Max7219 object

Declaration
public Max7219(ISpiBus spiBus, IDigitalOutputPort chipselectPort, int deviceRows, int deviceColumns, Max7219.Max7219Mode maxMode = Max7219.Max7219Mode.Display)

Parameters

Type Name Description
ISpiBus spiBus

SPI bus

IDigitalOutputPort chipselectPort

Chip select port

System.Int32 deviceRows

Number of devices cascaded vertically

System.Int32 deviceColumns

Number of devices cascaded horizontally

Max7219.Max7219Mode maxMode

Display mode of max7219

Max7219(ISpiBus, IPin, Int32, Max7219.Max7219Mode)

Create a new Max7219 object

Declaration
public Max7219(ISpiBus spiBus, IPin chipSelectPin, int deviceCount = 1, Max7219.Max7219Mode maxMode = Max7219.Max7219Mode.Display)

Parameters

Type Name Description
ISpiBus spiBus

SPI bus

IPin chipSelectPin

Chip select pin

System.Int32 deviceCount

Number of cascaded devices

Max7219.Max7219Mode maxMode

Display mode of max7219

Max7219(ISpiBus, IPin, Int32, Int32, Max7219.Max7219Mode)

Create a new Max7219 object

Declaration
public Max7219(ISpiBus spiBus, IPin chipSelectPin, int deviceRows = 1, int deviceColumns = 1, Max7219.Max7219Mode maxMode = Max7219.Max7219Mode.Display)

Parameters

Type Name Description
ISpiBus spiBus

SPI bus

IPin chipSelectPin

Chip select pin

System.Int32 deviceRows

Number of devices cascaded vertically

System.Int32 deviceColumns

Number of devices cascaded horizontally

Max7219.Max7219Mode maxMode

Display mode of max7219

Fields

DefaultSpiBusSpeed

MAX7219 Spi Clock Frequency

Declaration
public static Frequency DefaultSpiBusSpeed

Field Value

Type Description
Frequency

DigitsPerDevice

Number of digits per Module

Declaration
public const int DigitsPerDevice = null

Field Value

Type Description
System.Int32

Properties

BitDepth

The bit depth of the display

Declaration
public int BitDepth { get; }

Property Value

Type Description
System.Int32

Buffer

The backing buffer for the pixel buffer (not implemented)

Declaration
public byte[] Buffer { get; }

Property Value

Type Description
System.Byte[]

ByteCount

The total bytes used for the display buffer

Declaration
public int ByteCount { get; }

Property Value

Type Description
System.Int32

ColorMode

Color mode of display - 1bpp

Declaration
public ColorMode ColorMode { get; }

Property Value

Type Description
ColorMode

DeviceCount

Number of cascaded devices

Declaration
public int DeviceCount { get; }

Property Value

Type Description
System.Int32

DigitColumns

Number of columns when representing digits

Declaration
public int DigitColumns { get; }

Property Value

Type Description
System.Int32

DigitRows

Number of rows when representing digits

Declaration
public int DigitRows { get; }

Property Value

Type Description
System.Int32

Height

Height of array of displays in pixels

Declaration
public int Height { get; }

Property Value

Type Description
System.Int32

Length

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

Declaration
public int Length { get; }

Property Value

Type Description
System.Int32

PixelBuffer

The offscreen buffer used for the display

Declaration
public IPixelBuffer PixelBuffer { get; }

Property Value

Type Description
IPixelBuffer

SupportedColorModes

The Color mode supported by the display

Declaration
public ColorMode SupportedColorModes { get; }

Property Value

Type Description
ColorMode

Width

Width of array of displays in pixels

Declaration
public int Width { get; }

Property Value

Type Description
System.Int32

Methods

Clear()

Clear the display buffer

Declaration
public void Clear()

Clear(Boolean)

Clears the buffer from the given start to end and flushes

Declaration
public void Clear(bool updateDisplay = false)

Parameters

Type Name Description
System.Boolean updateDisplay

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

DrawPixel(Int32, Int32, Color)

Draw pixel at location

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

Parameters

Type Name Description
System.Int32 x

x position

System.Int32 y

y position

Color color

color of pixel - converted to on/off

DrawPixel(Int32, Int32, Boolean)

Draw pixel at location

Declaration
public void DrawPixel(int x, int y, bool enabled)

Parameters

Type Name Description
System.Int32 x

x position in pixels

System.Int32 y

y position in pixels

System.Boolean enabled

True = turn on pixel, false = turn off pixel

Fill(Color)

Fill the display with a normalized color to on/off

Declaration
public void Fill(Color color)

Parameters

Type Name Description
Color color

The color to fill

Fill(Color, Boolean)

Fill with color

Declaration
public void Fill(Color fillColor, bool updateDisplay = false)

Parameters

Type Name Description
Color fillColor

color - converted to on/off

System.Boolean updateDisplay

should refresh display

Fill(Int32, Int32, Int32, Int32, Color)

Fill region with color

Declaration
public void Fill(int x, int y, int width, int height, Color fillColor)

Parameters

Type Name Description
System.Int32 x

x position

System.Int32 y

y position

System.Int32 width

width of region

System.Int32 height

height of region

Color fillColor

color - converted to on/off

GetCharacter(Int32, Int32)

Get the stored character

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

Parameters

Type Name Description
System.Int32 digit

the digit index of the character

System.Int32 deviceId

the cascaded device id

Returns

Type Description
Max7219.CharacterType

GetDigit(Int32, Int32)

Get the number at a specific position

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

Parameters

Type Name Description
System.Int32 digit

the digit index

System.Int32 deviceId

the cascaded device id

Returns

Type Description
System.Int32

GetPixel(Int32, Int32)

Get the Color of the pixel at a location (not implemented)

Declaration
public Color GetPixel(int x, int y)

Parameters

Type Name Description
System.Int32 x

The x position in pixels

System.Int32 y

The y position in pixels

Returns

Type Description
Color

The pixel color

InvertPixel(Int32, Int32)

Invert pixel at location (toggle on/off)

Declaration
public void InvertPixel(int x, int y)

Parameters

Type Name Description
System.Int32 x

x position in pixels

System.Int32 y

y position in pixels

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.

SetBrightness(Int32, Int32)

Sets the brightness for a specific device

Declaration
public void SetBrightness(int intensity, int deviceId)

Parameters

Type Name Description
System.Int32 intensity

intensity level ranging from 0..15.

System.Int32 deviceId

index of cascaded device.

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

Set a single character

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

Parameters

Type Name Description
Max7219.CharacterType character

the chracter to display

System.Int32 digit

the digit index starting from the left

System.Boolean showDecimal

show the decimal with the character

System.Int32 deviceId

the cascaded device id

SetDigit(Byte, Int32, Int32)

Set a number at a specific position

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

Parameters

Type Name Description
System.Byte value

the value to display

System.Int32 digit

the digit index

System.Int32 deviceId

the cascaded device id

SetMode(Max7219.Max7219Mode)

Set the display mode of the max7219

Declaration
public void SetMode(Max7219.Max7219Mode maxMode)

Parameters

Type Name Description
Max7219.Max7219Mode maxMode

the mode

SetNumber(Int32, Int32)

Set number to display (left aligned)

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

Parameters

Type Name Description
System.Int32 value

the number to display

System.Int32 deviceId

the cascaded device id

SetPixel(Int32, Int32, Color)

Set a pixel at a specific location

Declaration
public void SetPixel(int x, int y, Color color)

Parameters

Type Name Description
System.Int32 x

The x position in pixels

System.Int32 y

The y position in pixels

Color color

The pixel color normalized to on/off

Show()

Writes all the Values to the devices.

Declaration
public void Show()

Show(Int32, Int32, Int32, Int32)

Partial screen update

Declaration
public void Show(int left, int top, int right, int bottom)

Parameters

Type Name Description
System.Int32 left
System.Int32 top
System.Int32 right
System.Int32 bottom

TestDisplay(TimeSpan)

Helper test method - will turn all leds on then off

Declaration
public void TestDisplay(TimeSpan time)

Parameters

Type Name Description
TimeSpan time

time to show leds

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

WriteBuffer(Int32, Int32, IPixelBuffer)

Draw buffer at location

Declaration
public void WriteBuffer(int x, int y, IPixelBuffer displayBuffer)

Parameters

Type Name Description
System.Int32 x

x position in pixels

System.Int32 y

y position in pixels

IPixelBuffer displayBuffer

buffer to draw