max7219 package

Submodules

max7219.font module

class max7219.font.proportional(font)[source]

Bases: object

Wraps an existing font array, and on on indexing, trims any leading or trailing zero column definitions. This works especially well with scrolling messages, as interspace columns are squeezed to a single pixel.

max7219.led module

class max7219.led.constants[source]

Bases: object

MAX7219_REG_DECODEMODE = 9
MAX7219_REG_DIGIT0 = 1
MAX7219_REG_DIGIT1 = 2
MAX7219_REG_DIGIT2 = 3
MAX7219_REG_DIGIT3 = 4
MAX7219_REG_DIGIT4 = 5
MAX7219_REG_DIGIT5 = 6
MAX7219_REG_DIGIT6 = 7
MAX7219_REG_DIGIT7 = 8
MAX7219_REG_DISPLAYTEST = 15
MAX7219_REG_INTENSITY = 10
MAX7219_REG_NOOP = 0
MAX7219_REG_SCANLIMIT = 11
MAX7219_REG_SHUTDOWN = 12
class max7219.led.device(cascaded=1, spi_bus=0, spi_device=0, vertical=False)[source]

Bases: object

Base class for handling multiple cascaded MAX7219 devices. Callers should generally pick either the sevensegment or matrix subclasses instead depending on which application is required.

A buffer is maintained which holds the bytes that will be cascaded every time flush() is called.

NUM_DIGITS = 8
brightness(intensity)[source]

Sets the brightness level of all cascaded devices to the same intensity level, ranging from 0..15. Note that setting the brightness to a high level will draw more current, and may cause intermittent issues / crashes if the USB power source is insufficient.

clear(deviceId=None)[source]

Clears the buffer the given deviceId if specified (else clears all devices), and flushes.

command(register, data)[source]

Sends a specific register some data, replicated for all cascaded devices

flush()[source]

For each digit/column, cascade out the contents of the buffer cells to the SPI device.

rotate_left(redraw=True)[source]

Scrolls the buffer one column to the left. The data that scrolls off the left side re-appears at the right-most position. If redraw is not suppled, or left set to True, will force a redraw of _all_ buffer items

rotate_right(redraw=True)[source]

Scrolls the buffer one column to the right. The data that scrolls off the right side re-appears at the left-most position. If redraw is not suppled, or left set to True, will force a redraw of _all_ buffer items

scroll_left(redraw=True)[source]

Scrolls the buffer one column to the left. Any data that scrolls off the left side is lost and does not re-appear on the right. An empty column is inserted at the right-most position. If redraw is not suppled, or set to True, will force a redraw of _all_ buffer items

scroll_right(redraw=True)[source]

Scrolls the buffer one column to the right. Any data that scrolls off the right side is lost and does not re-appear on the left. An empty column is inserted at the left-most position. If redraw is not suppled, or set to True, will force a redraw of _all_ buffer items

set_byte(deviceId, position, value, redraw=True)[source]

Low level mechanism to set a byte value in the buffer array. If redraw is not suppled, or set to True, will force a redraw of _all_ buffer items: If you are calling this method rapidly/frequently (e.g in a loop), it would be more efficient to set to False, and when done, call flush().

Prefer to use the higher-level method calls in the subclasses below.

class max7219.led.matrix(cascaded=1, spi_bus=0, spi_device=0, vertical=False)[source]

Bases: max7219.led.device

Implementation of MAX7219 devices cascaded with a series of 8x8 LED matrix devices. It provides a convenient methods to write letters to specific devices, to scroll a large message from left-to-right, or to set specific pixels. It is assumed the matrices are linearly aligned.

invert(value, redraw=True)[source]

Sets whether the display should be inverted or not when displaying letters.

letter(deviceId, asciiCode, font=None, redraw=True)[source]

Writes the ASCII letter code to the given device in the specified font.

orientation(angle, redraw=True)[source]

Sets the orientation (angle should be 0, 90, 180 or 270) at which the characters are displayed.

pixel(x, y, value, redraw=True)[source]

Sets (value = 1) or clears (value = 0) the pixel at the given co-ordinate. It may be more efficient to batch multiple pixel operations together with redraw=False, and then call flush() to redraw just once.

scroll_down(redraw=True)[source]

Scrolls the underlying buffer (for all cascaded devices) down one pixel

scroll_up(redraw=True)[source]

Scrolls the underlying buffer (for all cascaded devices) up one pixel

show_message(text, font=None, delay=0.05, always_scroll=False)[source]

Shows a message on the device. If it’s longer then the total width (or always_scroll=True), it transitions the text message across the devices from right-to-left.

class max7219.led.sevensegment(cascaded=1, spi_bus=0, spi_device=0, vertical=False)[source]

Bases: max7219.led.device

Implementation of MAX7219 devices cascaded with a series of seven-segment LEDs. It provides a convenient method to write a number to a given device in octal, decimal or hex, flushed left/right with zero padding. Base 10 numbers can be either integers or floating point (with the number of decimal points configurable).

letter(deviceId, position, char, dot=False, redraw=True)[source]

Looks up the most appropriate character representation for char from the digits table, and writes that bitmap value into the buffer at the given deviceId / position.

show_message(text, delay=0.4)[source]

Transitions the text message across the devices from left-to-right

write_number(deviceId, value, base=10, decimalPlaces=0, zeroPad=False, leftJustify=False)[source]

Formats the value according to the parameters supplied, and displays on the specified device. If the formatted number is larger than 8 digits, then an OverflowError is raised.

write_text(deviceId, text)[source]

Outputs the text (as near as possible) on the specific device. If text is larger than 8 characters, then an OverflowError is raised.

max7219.rotate8x8 module

max7219.rotate8x8.rotate(src)[source]

Rotate an 8x8 tile (8-element array of 8-bit numbers) 90 degrees counter-clockwise by table lookup. Large bitmaps can be rotated an 8x8 tile at a time. The extraction is done a nybble at a time to reduce the size of the tables.

Module contents

Raspberry Pi MAX7219 Driver.