![]() |
Forum Index : Microcontroller and PC projects : Picomite and MAX7219 Dot Matrix Display Module
Author | Message | ||||
Rickard5![]() Guru ![]() Joined: 31/03/2022 Location: United StatesPosts: 463 |
Hello Has anyone gotten one of these MAX7219 Dot Matrix 4 in One Display Modules working on the Picomite? I got it working in Python with this hardware hookup Raspberry pi pico MAX 7219 PIN PIN NUMBER 7 CS 8 GND 9 CLK 10 DIN 36 VCC The end goal is I'd like to mount one of these on my PMVGA and send text strings to display information and eventually be able to connect 3-4 in series and display graphics :) ![]() I may be Vulgar, but , while I'm poor, I'm Industrious, Honest, and trustworthy! I Know my Place |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
The forum has a search button. It's use will be informative. VK7JH MMedit |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
No promises, but this worked 12 months or so ago with 4 separate modules chained together: ' LED scrolling text demo. 'Library Load "matrix.lib" 'Library Load "text.lib" Save "text.bas" ' Picomite Const m7219_clk = 4 ' GP2 Const m7219_cs = 7 ' GP5 Const m7219_tx = 5 ' GP3 Const m7219_rx = 6 ' GP4 SetPin m7219_cs, Dout SetPin m7219_rx, m7219_tx, m7219_clk, SPI Pin(m7219_cs) = 1 ' Active low, so initially set high 'Cls m7219_init(8,32) 'm7219_init(8,8) 'matrix_fill() m7219_draw() text_init() SetTick 50, m7219_draw s$ = MM.CmdLine$ If Len(s$) = 0 Then Line Input "Message: ", s$ text_scroll(s$) End ' ********** ' matrix.lib ' ********** ' LED matrix manipulation library. ' Makes use of a global matrix(8) created by calling matrix_init(). ' Elements 0-7 are the 8-bit pattern for the matrix columns. Sub matrix_init() Local i For i = 1 To 8 : SetPin i, dout : Next i For i = 11 To 18 : SetPin i, dout : Next i matrix_nc = 8 Dim matrix(matrix_nc - 1) ' All elements initalised to 0 matrix_r = 0 End Sub Sub matrix_clear() Local i For i = 0 To matrix_nc - 1 : matrix(i) = 0 : Next i End Sub Sub matrix_fill() Local i For i = 0 To matrix_nc - 1 : matrix(i) = &hFF : Next i End Sub Function matrix_get(x, y) Local x2, y2 x2 = x + (y \ 8) * matrix_w y2 = y Mod 8 matrix_get = (matrix(x2) And 2^y2) > 0 End Function Sub matrix_set(x, y, z) Local x2, y2 x2 = x + (y \ 8) * matrix_w y2 = y Mod 8 matrix(x2) = matrix(x2) And (&hFF Xor 2^y2) Or (z * 2^y2) End Sub Sub matrix_left() Local i For i = 0 To matrix_nc - 2 : matrix(i) = matrix(i + 1) : Next i matrix(matrix_nc - 1) = 0 End Sub ' Updates scanline/row 'matrix_r'. ' ' Assumes that a HIGH is required on the row & column to light the LED. ' If a LOW is required on the row then use the commented out values in the ' calls to Port(). ' ' This routine needs to be fast (it is called every 2ms) hence the ' unrolled loop used to calculate 'x'. ' ' A much faster implementation is possible if matrix data is stored by ' rows instead of columns, i.e. ' ' Port(1, 8, 11, 8) = matrix(matrix_r) Or 2^(matrix_r + 8) Sub matrix_draw() Local m, x m = 2^matrix_r x = ((matrix(0) And m) > 0) Or 2 * ((matrix(1) And m) > 0) x = x Or 4 * ((matrix(2) And m) > 0) Or 8 * ((matrix(3) And m) > 0) x = x Or 16 * ((matrix(4) And m) > 0) Or 32 * ((matrix(5) And m) > 0) x = x Or 64 * ((matrix(6) And m) > 0) Or 128 * ((matrix(7) And m) > 0) Port(1, 8, 11, 8) = 0 ' &hFF00 Port(1, 8, 11, 8) = x Or 2^(matrix_r + 8) ' &hFF00 - 2^(matrix_r + 8) matrix_r = (matrix_r + 1) Mod 8 End Sub Sub m7219_init(w, h) Local i If w Mod 8 <> 0 Then Error "Invalid number of columns: " + Str$(w) If w Mod 8 <> 0 Then Error "Invalid number of rows: " + Str$(h) matrix_nc = w * (h \ 8) matrix_h = h matrix_w = w Dim matrix(matrix_nc - 1) ' all elements initialised to 0 SPI Open 3000000, 0, 16 For i = 0 To matrix_nc \ 8 - 1 m7219_write(&h0900, i) ' BCD DECODE ALL DIGITS m7219_write(&h0A00, i) ' BRIGHTNESS (0-15) m7219_write(&h0B07, i) ' 8 COLUMNS m7219_write(&h0F00, i) ' TESTS OFF m7219_write(&h0C01, i) ' OPERATING MODE (i.e. NOT SHUTDOWN MODE) Next i m7219_draw() ' Clears the matrix - is this necessary? End Sub Sub m7219_draw() Local c For c = 0 To matrix_nc - 1 m7219_write((1 + c Mod 8) * 256 + matrix(c), c \ 8) Next c End Sub Sub m7219_write(x, idx) Local i ' SPI Open 3000000, 3, 16 Pin(m7219_cs) = 0 For i = matrix_nc \ 8 - 1 To 0 Step -1 ' null = SPI(m7219_rx, m7219_tx, m7219_clk, x * (i = idx), H, 3, 16) null = SPI(x * (i = idx)) Next i Pin(m7219_cs) = 1 End Sub Sub digits_init() Local i, x Dim digits(9, 7) ' 10 digits, 8 columns per character ' Each DATA line represents dot-patterns for the 8-columns ' (left to right) msb=bottom dot, lsb=top dot Data &h7E, &hFF, &hFF, &hC3, &hC3, &hFF, &hFF, &h7E ' 0 Data &h00, &h00, &h04, &h06, &hFF, &hFF, &hFF, &h00 ' 1 Data &hE6, &hE7, &hF7, &hD3, &hDB, &hCF, &hCF, &hC6 ' 2 Data &hDB, &hDB, &hDB, &hDB, &hDB, &hFF, &hFF, &h66 ' 3 Data &h1F, &h1F, &h1F, &h18, &hFF, &hFF, &hFF, &h18 ' 4 Data &h5F, &hDF, &hDF, &hDB, &hDB, &hFB, &hFB, &h73 ' 5 Data &h7E, &hFF, &hFF, &hDB, &hDB, &hFB, &hFB, &h72 ' 6 Data &h03, &h03, &hE3, &hF3, &hFB, &h1F, &h0F, &h07 ' 7 Data &h66, &hFF, &hFF, &hDB, &hDB, &hFF, &hFF, &h66 ' 8 Data &h4E, &hDF, &hDF, &hDB, &hDB, &hFF, &hFF, &h7E ' 9 For i = 0 To 9 For x = 0 To 7 Read digits(i, x) Next x Next i End Sub ' ********** ' text.lib ' ********** ' LED font display library. ' Makes use of a global font4x6() array created by calling text_init(). Sub text_init() Local end, height, i, j, s$, start, x, width Open "tt4x6.fnt" For Input As #1 Input #1, height, width, start, end If height <> 6 Then Error If width <> 4 Then Error If start <> 20 Then Error If end <> 126 Then Error ' This is actually more storage than is required because it allocates ' 4 bytes per glyph and we only need 3. Dim font4x6(end - start) For i = 0 To (end - start) ' Iterate over glyphs For j = 0 To 5 Step 2 ' Iterate over rows, 2 at a time x = 0 Line Input #1, s$ If Len(s$) <> width Then Error If Peek(Var s$, 1) > 32 Then x = x Or &b00000001 If Peek(Var s$, 2) > 32 Then x = x Or &b00000010 If Peek(Var s$, 3) > 32 Then x = x Or &b00000100 If Peek(Var s$, 4) > 32 Then x = x Or &b00001000 Line Input #1, s$ If Len(s$) <> width Then Error If Peek(Var s$, 1) > 32 Then x = x Or &b00010000 If Peek(Var s$, 2) > 32 Then x = x Or &b00100000 If Peek(Var s$, 3) > 32 Then x = x Or &b01000000 If Peek(Var s$, 4) > 32 Then x = x Or &b10000000 Poke Var font4x6(0), i * 3 + j \ 2, x Next j Next i Close #1 End Sub Sub text_scroll(s$) Local c, ch, i cmd = 0 For i = 1 To Len(s$) ' Print "x"; ch = Peek(Var s$, i) For c = 0 To 3 ' Print "y"; ' Poor man's proportional spacing. If c = 0 And ch = 105 Then c = 1 If c = 2 And ch = 105 Then c = 3 If c = 1 And ch = 32 Then c = 4 ' Print "a"; text_blit(Peek(Var s$, i), c) ' Print "b"; Pause 150 ' Print "c"; matrix_left() Next c If cmd <> 0 Then i = Len(s$) Next i ' Print "leaving" For i = 1 To matrix_nc : Pause 100 : matrix_left() : Next i End Sub ' Copies column 'c' of glyph 'a' to the last column of the matrix. Sub text_blit(a, c) Local i, p, s, z p = 1 s = (a - 20) * 3 For i = s To s + 2 z = Peek(Var font4x6(0), i) matrix_set(matrix_nc - 1, p, (z And 2^c) > 0) p = p + 1 matrix_set(matrix_nc - 1, p, (z And 2^(c+4)) > 0) p = p + 1 Next i End Sub You also need this font: tt4x6.zip Note that IIRC those modules are a nuisance as they have no explicit reset so occasionally they get their knickers in a twist and have to be power-cycled. Additionally the above contains some unnecessary stuff (prefixed matrix_) as it was part of a library that was also capable of bitbanging a homebrew LED matrix without the MAX7219 controller. Let me know how it goes, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
bigmik![]() Guru ![]() Joined: 20/06/2011 Location: AustraliaPosts: 2950 |
Hi Rickard, You might want to look at a project Curtis (JustPlayin) and myself worked on that uses these chips to create a moving message board using Bi-Colour LEDs that can create 3 colour (RED GREEN and YELLOW) characters. <<< Mik-Matrix >>> This was done a few years ago and ran on a Pic’170. You might find some hints and ideas from this build Regards, Mick Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<< |
||||
Rickard5![]() Guru ![]() Joined: 31/03/2022 Location: United StatesPosts: 463 |
Thanks everyone, I just knew it couldn't be a 2-3 Line thing, Thwill I'm gonna be chewing on that code though many POTS of Coffee I may be Vulgar, but , while I'm poor, I'm Industrious, Honest, and trustworthy! I Know my Place |
||||
Justplayin![]() Guru ![]() Joined: 31/01/2014 Location: United StatesPosts: 328 |
You may want to look at my original program effort using the mono color matrix displays and completely written in MmBasic. Mik-Matrix is far more complex and dependant on CFunctions which are not compatible with the Pico. Thread here. One thing about my code though, it requires the matrix modules to be rotated 90 degrees. The rotation makes far easier to scroll the displays without a lot of data manipulation. --Curtis I am not a Mad Scientist... It makes me happy inventing new ways to take over the world!! |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |