Introduction
In this tutorial, we will be using an 8×8 LED matrix that is controlled by a MAX7219 chip. We will be using a Raspberry Pi Pico as our microcontroller and we will be programming it in MicroPython. This project is a great intro to using LED matrix and the MAX7219 chip.
Required Components
- Raspberry Pi Pico
- 8×8 LED matrix
- jumper wire
- breadboard
MAX7219 LED Dot Matrix Display
The dot-matrix display is an electrical device that can show information on machines, clocks, and many other devices. In this project, we will use the Raspberry Pi Pico to control the 8×8 LED dot matrix to make a heart pattern.
The MAX7219 SPI interface allows you to control the module with just a few wires, making it perfect for use with Raspberry Pi Pico. Getting Started Raspberry Pi Pico – Pinout, Specs – Beginner Guide
This module can be used to control an 8×8 LED matrix or 64 individual LEDs. You can use it to create animations, games, or any other creative project. The module is easy to use and only requires a few wires to connect it to your project. The MAX7219 comes with a built-in voltage regulator so it can be powered by either a 5V or 3.3V power supply.
MAX7219 Dot Led Matrix Pinout
The LED matrix can be done through two driving modes. They are parallel (where each row or column is sent with parallel data) and serial (where the data is sent serially and an IC is operated to convert this serial data into parallel data).
Schematic Diagram – 8×8 LED Matrix MAX7219 With Raspberry Pi Pico
MAX7219 | Pico Name | Pico GPIO | Pico PIN |
---|---|---|---|
VCC | VBUS | 40 | |
GND | GND | 38 | |
DIN | MOSI (SPI0 TX) | GP7 | 10 |
CS | SPI0 CSn | GP5 | 7 |
CLK | SCK | GP6 | 9 |
Micropython Code & Libraries
This 8×8 LED Matrix Library module will be interfaced with Raspberry Pi Pico for displaying alphabets, symbols & logos. First, we require to download a micropython library specifically designed for LED MATRIX. Getting Started With Raspberry Pi Pico With Thonny IDE
Installing MAX7219 MicroPython Library
Open a new tab in Thonny IDE. Copy the code here. Save it to Raspberry Pi Pico with the name max7219.py under the lib folder.
max7219.py
The below libraries allow you to control the max7219 LED driver with a variety of different commands.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
""" MicroPython max7219 cascadable 8x8 LED matrix driver https://github.com/mcauser/micropython-max7219 MIT License Copyright (c) 2017 Mike Causer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ """ MicroPython max7219 cascadable 8x8 LED matrix driver https://github.com/mcauser/micropython-max7219 MIT License Copyright (c) 2017 Mike Causer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ from micropython import const import framebuf _NOOP = const(0) _DIGIT0 = const(1) _DECODEMODE = const(9) _INTENSITY = const(10) _SCANLIMIT = const(11) _SHUTDOWN = const(12) _DISPLAYTEST = const(15) class Matrix8x8: def __init__(self, spi, cs, num): """ Driver for cascading MAX7219 8x8 LED matrices. >>> import max7219 >>> from machine import Pin, SPI >>> spi = SPI(1) >>> display = max7219.Matrix8x8(spi, Pin('X5'), 4) >>> display.text('1234',0,0,1) >>> display.show() """ self.spi = spi self.cs = cs self.cs.init(cs.OUT, True) self.buffer = bytearray(8 * num) self.num = num fb = framebuf.FrameBuffer(self.buffer, 8 * num, 8, framebuf.MONO_HLSB) self.framebuf = fb # Provide methods for accessing FrameBuffer graphics primitives. This is a workround # because inheritance from a native class is currently unsupported. # http://docs.micropython.org/en/latest/pyboard/library/framebuf.html self.fill = fb.fill # (col) self.pixel = fb.pixel # (x, y[, c]) self.hline = fb.hline # (x, y, w, col) self.vline = fb.vline # (x, y, h, col) self.line = fb.line # (x1, y1, x2, y2, col) self.rect = fb.rect # (x, y, w, h, col) self.fill_rect = fb.fill_rect # (x, y, w, h, col) self.text = fb.text # (string, x, y, col=1) self.scroll = fb.scroll # (dx, dy) self.blit = fb.blit # (fbuf, x, y[, key]) self.init() def _write(self, command, data): self.cs(0) for m in range(self.num): self.spi.write(bytearray([command, data])) self.cs(1) def init(self): for command, data in ( (_SHUTDOWN, 0), (_DISPLAYTEST, 0), (_SCANLIMIT, 7), (_DECODEMODE, 0), (_SHUTDOWN, 1), ): self._write(command, data) def brightness(self, value): if not 0 <= value <= 15: raise ValueError("Brightness out of range") self._write(_INTENSITY, value) def show(self): for y in range(8): self.cs(0) for m in range(self.num): self.spi.write(bytearray([_DIGIT0 + y, self.buffer[(y * self.num) + m]])) self.cs(1) |
main.py
copy the below code and Save it in Pico.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
import max7219 from machine import Pin, SPI from time import sleep class matrix(): def __init__(self): self.MAX7219_NUM = 4 self.MAX7219_INVERT = False self.MAX7219_SCROLL_DELAY = 0.03 cs_pin = 5 spi = SPI(0) self.display = max7219.Matrix8x8(spi=spi, cs=Pin(cs_pin), num=self.MAX7219_NUM) self.display.brightness(2) def text_scroll(self, text, scroll_delay=None): if scroll_delay != None: self.MAX7219_SCROLL_DELAY = scroll_delay p = self.MAX7219_NUM * 8 for p in range(self.MAX7219_NUM * 8, len(text) * -8 - 1, -1): self.display.fill(self.MAX7219_INVERT) self.display.text(text, p, 1, not self.MAX7219_INVERT) self.display.show() sleep(self.MAX7219_SCROLL_DELAY) led = matrix() text = "ABC" led.text_scroll(text) |
Conclusion
In ending, the 8×8 LED matrix MAX7219 with raspberry pi pico is a perfect project for anyone interested in electronics and coding. This project is simple With a little bit of creativity, you can create a unique display that is sure to impress your friends.
Popular Raspberry Pi Pico Posts
- Raspberry Pi Pico W Relay Module Web Server Using Thonny IDE
- Control 28BYJ-48 Stepper Motor With Raspberry Pi Pico – Micropython
- Raspberry Pi Pico W Remote Controlled Car Robot Web Server
- How to Control WS2812 LED w/ Raspberry Pi Pico W & Adafruit IO
- BME280 With Raspberry Pi Pico W Using MicroPython
- Raspberry Pi Pico W Web Server with BME280 – Mini Weather Station