Has anyone got working code for Max7219

Discussion about the ZBasic language including the System Library. If you're not sure where to post your message, do it here. However, do not make test posts here; that's the purpose of the Sandbox.
Post Reply
FFMan
Posts: 502
Joined: 09 January 2010, 12:52 PM

Has anyone got working code for Max7219

Post by FFMan »

I'm having issues getting the max7219 on a dot matrix display to behave as it should.

Not sure if its timing or misunderstanding of what i need to do, but i've looked at many arduino examples and it shouldn't be too hard to replicate

https://www.best-microcontroller-projec ... x7219.html

i'm bit banging it as i've done before with shift registers

if anyone has any experience or code that would be appreciated
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: Has anyone got working code for Max7219

Post by dkinzer »

FFMan wrote:I'm having issues getting the max7219 on a dot matrix display to behave as it should.
It looks fairly straightforward. I'm willing to take a look at your code if you'd like.
- Don Kinzer
FFMan
Posts: 502
Joined: 09 January 2010, 12:52 PM

Post by FFMan »

thanks don - just about cracked it now.

a wiring issue and fiddled with the timing. the only issue being the init commands leave a pattern on the display, but if i quickly clear line by line it's not noticeable.
eserdahl
Posts: 6
Joined: 14 December 2005, 16:06 PM
Location: Sunnyvale, CA
Contact:

Has anyone got working code for Max7219

Post by eserdahl »

I would be interested in seeing the code that finally made it work.
Eric Serdahl.
Sent from my iPad Air 2



On Mar 27, 2019, at 2:20 PM, ZBasic <zbasic.forum@zbasic.net (zbasic.forum@zbasic.net)> wrote:

thanks don - just about cracked it now.

a wiring issue and fiddled with the timing. the only issue being the init commands leave a pattern on the display, but if i quickly clear line by line it's not noticeable.




FFMan
Posts: 502
Joined: 09 January 2010, 12:52 PM

Post by FFMan »

Here is some roughish test code - but it works.
Attachments
MatrixTest.pjt
(73 Bytes) Downloaded 479 times
MatrixTest.bas
(3.69 KiB) Downloaded 484 times
MatrixDispFns.bas
(2.88 KiB) Downloaded 479 times
FFMan
Posts: 502
Joined: 09 January 2010, 12:52 PM

Post by FFMan »

Attachments
MatrixClock-Small.jpg
MatrixClock-Small.jpg (118.28 KiB) Viewed 4828 times
FFMan
Posts: 502
Joined: 09 January 2010, 12:52 PM

Post by FFMan »

comments on how most efficiently to store the font data welcome as each character is 8 bytes - not a lot really but i want entire alphabet and maybe upper and lower case.

https://xantorohara.github.io/led-matrix-editor/#

I think i recall i can put that in progmem somehow ?

Scrolling is i guess easily achieved with font data shift commands ?
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

FFMan wrote:I think i recall i can put that in progmem somehow ?
Yes, it's probably best to use the ProgMem data type ByteTableData. For example,

Code: Select all

Dim byChrs as ByteTableData &#40;&#123;
    '0
    &B00111000, &B01000100, &B01000100, &B01000100, &B01000100, &B01000100, &B01000100, &B00111000
    '1
    &B00010000, &B00110000, &B00010000, &B00010000, &B00010000, &B00010000, &B00010000, &B00111000
    '2
    &B00111000, &B01000100, &B00000100, &B00000100, &B00001000, &B00010000, &B00100000, &B01111100
    '3
    &B00111000, &B01000100, &B00000100, &B00011000, &B00000100, &B00000100, &B01000100, &B00111000
    '4
    &B00000100, &B00001100, &B00010100, &B00100100, &B01000100, &B01111100, &B00000100, &B00000100
    '5
    &B01111100, &B01000000, &B01000000, &B01111000, &B00000100, &B00000100, &B01000100, &B00111000
    '6
    &B00111000, &B01000100, &B01000000, &B01111000, &B01000100, &B01000100, &B01000100, &B00111000
    '7
    &B01111100, &B00000100, &B00000100, &B00001000, &B00010000, &B00100000, &B00100000, &B00100000
    '8
    &B00111000, &B01000100, &B01000100, &B00111000, &B01000100, &B01000100, &B01000100, &B00111000
    '9
    &B00111000, &B01000100, &B01000100, &B01000100, &B00111100, &B00000100, &B01000100, &B00111000
&#125;&#41;

Sub Main&#40;&#41;
    Dim i as Integer, j as Integer

    For i = 1 to 10
        For j = 1 to 8
            Debug.Print "0x"; CStrHex&#40;byChrs&#40;j, i&#41;&#41;; " ";
        Next j
        Debug.Print
    Next i
End Sub
Note that the the column index is given first and the row index second. As documented, this is backward from the way that RAM arrays are stored. The simple test program demonstrates how to access the table and confirms that the index order is correct.
- Don Kinzer
FFMan
Posts: 502
Joined: 09 January 2010, 12:52 PM

Post by FFMan »

thanks don - i used that and added in A-Z characters.

Question - when it come to scrolling text. Lets say I have a 4 character display and a message like "Hello World" (keeping it traditional) that i want to scroll.

Scrolling is simply achieved by shifting each bit pattern 1 bit at a time and re-displaying.

So I've created a 50 byte (x 8 for each row) message buffer and written a sub to load the bit patterns for my message.

There are a couple of options to achieve scrolling:-

1) i write a routine that always displays the first 4 characters of my buffer, and i write a routine that shuffles all the bits across the buffer, and then re-displays. Achievable but a bit of a pain as bits will traverse from one array element to another and it doesn't feel very efficient though i daresay there is time as the scrolling needs to be slow enough to be readable,

2) my display routine simply has a startbit parameter and it reads from that point in the buffer forwards for 4 characters

both of these routines would be much easier if there was a way of addressing the bits as a continuous stream rather than buffer element 5, bit 3 etc

I can write a routine to abstract the byte array boundaries and return say bit 245, but again it feels inefficent as calls will be numerous to write 4 characters.

I'm thinking there must be a better approach but I can't think of it - any suggestions welcome.
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

FFMan wrote:Scrolling is simply achieved by shifting each bit pattern 1 bit at a time and re-displaying.
My impression was that the character data is given as dot columns, i.e. each byte represents the on/off state of a column of dots on the display. If that is true and your message buffer essentially amounts to the dot columns of the message, the scrolling should be achievable by advancing one or more dot columns (bytes) in the message buffer for each scroll interval. Am I missing something?
- Don Kinzer
FFMan
Posts: 502
Joined: 09 January 2010, 12:52 PM

Post by FFMan »

the data is actually dot rows (but the principal is the same) with each byte containing 8 bits that indicate what led should do. each character is 8 bytes so the 8x8 matrix is covered.

> the scrolling should be achievable by advancing one or more dot columns (bytes)

If you shift bytes, the characters will jump whole display segments, rather 1 column at a time and the desired smooth scroll.

What would be useful is some sort of GetBit that can operate on a data stream 400 bits wide efficiently. I can code this but i was wondering if there is a more efficient way like Rampeek that returns a bit.
Post Reply