adafruit_max7219.max7219 - MAX7219 LED Matrix/Digit Display Driver

CircuitPython library to support MAX7219 LED Matrix/Digit Display Driver. This library supports the use of the MAX7219-based display in CircuitPython, either an 8x8 matrix or a 8 digit 7-segment numeric display.

See Also

  • matrices.Maxtrix8x8 is a class support an 8x8 led matrix display

  • matrices.CustomMatrix is a class support a custom sized constellation of 8x8 led matrix displays

  • bcddigits.BCDDigits is a class that support the 8 digit 7-segment display

Beware that most CircuitPython compatible hardware are 3.3v logic level! Make sure that the input pin is 5v tolerant.

  • Author(s): Michael McWethy

Implementation Notes

Hardware:

Software and Dependencies:

Notes: #. Datasheet: https://cdn-shop.adafruit.com/datasheets/MAX7219.pdf

class adafruit_max7219.max7219.MAX7219(width: int, height: int, spi: SPI, cs: DigitalInOut, *, baudrate: int = 8000000, polarity: int = 0, phase: int = 0)[source]

Bases: object

MAX7219 - driver for displays based on max7219 chip_select

Parameters:
  • width (int) – the number of pixels wide

  • height (int) – the number of pixels high

  • spi (SPI) – an spi busio or spi bitbangio object

  • chip_select (DigitalInOut) – digital in/out to use as chip select signal

  • baudrate (int) – for SPIDevice baudrate (default 8000000)

  • polarity (int) – for SPIDevice polarity (default 0)

  • phase (int) – for SPIDevice phase (default 0)

init_display() None[source]

Must be implemented by derived class (matrices, bcddigits)

brightness(value: int) None[source]

Controls the brightness of the display.

Parameters:

value (int) – 0->15 dimmest to brightest

show() None[source]

Updates the display.

fill(bit_value: int) None[source]

Fill the display buffer.

Parameters:

bit_value (int) – value > 0 set the buffer bit, else clears the buffer bit

pixel(xpos: int, ypos: int, bit_value: int = None) None[source]

Set one buffer bit

Parameters:
  • xpos (int) – x position to set bit

  • ypos (int) – y position to set bit

  • bit_value (int) – value > 0 sets the buffer bit, else clears the buffer bit

scroll(delta_x: int, delta_y: int) None[source]

Srcolls the display using delta_x,delta_y.

Parameters:
  • delta_x (int) – positions to scroll in the x direction

  • delta_y (int) – positions to scroll in the y direction

write_cmd(cmd: int, data: int) None[source]

Writes a command to spi device.

Parameters:
  • cmd (int) – register address to write data to

  • data (int) – data to be written to commanded register

class adafruit_max7219.max7219.ChainableMAX7219(width: int, height: int, spi: SPI, cs: DigitalInOut, *, baudrate: int = 8000000, polarity: int = 0, phase: int = 0)[source]

Bases: MAX7219

Daisy Chainable MAX7219 - driver for cascading displays based on max7219 chip_select

Parameters:
  • width (int) – the number of pixels wide

  • height (int) – the number of pixels high

  • spi (SPI) – an spi busio or spi bitbangio object

  • chip_select (DigitalInOut) – digital in/out to use as chip select signal

  • baudrate (int) – for SPIDevice baudrate (default 8000000)

  • polarity (int) – for SPIDevice polarity (default 0)

  • phase (int) – for SPIDevice phase (default 0)

write_cmd(cmd: int, data: int) None[source]

Writes a command to spi device.

Parameters:
  • cmd (int) – register address to write data to

  • data (int) – data to be written to commanded register

show() None[source]

Updates the display.

adafruit_max7219.matrices

class adafruit_max7219.matrices.Matrix8x8(spi: SPI, cs: DigitalInOut)[source]

Driver for a 8x8 LED matrix based on the MAX7219 chip.

Parameters:
  • spi (SPI) – an spi busio or spi bitbangio object

  • cs (DigitalInOut) – digital in/out to use as chip select signal

init_display() None[source]

Must be implemented by derived class (matrices, bcddigits)

text(strg: str, xpos: int, ypos: int, bit_value: int = 1, *, font_name: str = 'font5x8.bin') None[source]

Draw text in the 8x8 matrix.

Parameters:
  • strg (str) – string to place in to display

  • xpos (int) – x position of LED in matrix

  • ypos (int) – y position of LED in matrix

  • bit_value (int) – > 1 sets the text, otherwise resets

  • font_name (str) – path to binary font file (default: “font5x8.bin”). The font can only be set once, if you want a different font you must re-initialize the matrix.

clear_all() None[source]

Clears all matrix leds.

class adafruit_max7219.matrices.CustomMatrix(spi: SPI, cs: DigitalInOut, width: int, height: int, *, rotation: int = 1)[source]

Driver for a custom 8x8 LED matrix constellation based on daisy chained MAX7219 chips.

Parameters:
  • spi (SPI) – an spi busio or spi bitbangio object

  • cs (DigitalInOut) – digital in/out to use as chip select signal

  • width (int) – the number of pixels wide

  • height (int) – the number of pixels high

  • rotation (int) – the number of times to rotate the coordinate system (default 1)

init_display() None[source]

Must be implemented by derived class (matrices, bcddigits)

clear_all() None[source]

Clears all matrix leds.

pixel(xpos: int, ypos: int, bit_value: int = None) None[source]

Set one buffer bit

Parameters:
  • xpos (int) – x position to set bit

  • ypos (int) – y position to set bit

  • bit_value (int) – value > 0 sets the buffer bit, else clears the buffer bit

scroll(delta_x: int, delta_y: int) None[source]

Srcolls the display using delta_x, delta_y.

Parameters:
  • delta_x (int) – positions to scroll in the x direction

  • delta_y (int) – positions to scroll in the y direction

rect(x: int, y: int, width: int, height: int, color: int, fill: bool = False) None[source]

Draw a rectangle at the given position of the given size, color, and fill.

Parameters:
  • x (int) – x position

  • y (int) – y position

  • width (int) – width of rectangle

  • height (int) – height of rectangle

  • color (int) – color of rectangle

  • fill (bool) – 1 pixel outline or filled rectangle (default: False)

text(strg: str, xpos: int, ypos: int, color: int = 1, *, font_name: str = 'font5x8.bin', size: int = 1) None[source]

Draw text in the matrix.

Parameters:
  • strg (str) – string to place in to display

  • xpos (int) – x position of LED in matrix

  • ypos (int) – y position of LED in matrix

  • color (int) – > 1 sets the text, otherwise resets

  • font_name (str) – path to binary font file (default: “font5x8.bin”)

  • size (int) – size of the font, acts as a multiplier

adafruit_max7219.bcddigits.BCDDigits

class adafruit_max7219.bcddigits.BCDDigits(spi: SPI, cs: DigitalInOut, nDigits: int = 1)[source]

Basic support for display on a 7-Segment BCD display controlled by a Max7219 chip using SPI.

Parameters:
  • spi (SPI) – an spi busio or spi bitbangio object

  • cs (DigitalInOut) – digital in/out to use as chip select signal

  • nDigits (int) – number of led 7-segment digits; default 1; max 8

init_display() None[source]

Must be implemented by derived class (matrices, bcddigits)

set_digit(dpos: int, value: int) None[source]

Display one digit.

Parameters:
  • dpos (int) – the digit position; zero-based

  • value (int) – integer ranging from 0->15

set_digits(start: int, values: List[int]) None[source]

Display digits from a list.

Parameters:
  • start (int) – digit to start display zero-based

  • values (list[int]) – list of integer values ranging from 0->15

show_dot(dpos: int, bit_value: int = None) None[source]

The decimal point for a digit.

Parameters:
  • dpos (int) – the digit to set the decimal point zero-based

  • bit_value (int) – value > zero lights the decimal point, else unlights the point

clear_all() None[source]

Clear all digits and decimal points.

show_str(start: int, strg: str) None[source]

Displays a numeric str in the display. Shows digits 0-9, -, and ..

Parameters:
  • start (int) – start position to show the numeric string

  • strg (str) – the numeric string

show_help(start: int) None[source]

Display the word HELP in the display.

Parameters:

start (int) – start position to show HELP