How it works...

Initially, we defined addresses for each of the control registers used by the MAX7219 device. View the datasheet at for more information:

https://datasheets.maximintegrated.com/en/ds/MAX7219-MAX7221.pdf.

We created a class called matrix that will allow us to control the module. The __init__() function sets up the SPI of Raspberry Pi (using SPI_CS as pin 26 CS1 and SPI_SPEED as 100 kHz).

The key function in our matrix class is the sendCmd() function; it uses wiringpi.wiringPiSPIDataRW(SPI_CS,buff) to send buffer (which is the raw byte data that we want to send) over the SPI bus (while also setting the SPI_CS pin to low when the transfer occurs). Each command consists of two bytes: the first specifies the address of the register, ...

Get Raspberry Pi 3 Cookbook for Python Programmers - Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.