Ageir
Posts: 17
Joined: Wed May 03, 2017 5:48 pm

Code for LED matrix with shift registers.

Thu Nov 16, 2017 12:55 pm

I'm trying to run a 8x8 led matrix via 2x 74hc595 shift registers.
I got it working with this code.
https://www.sunfounder.com/learn/Super_ ... rrypi.html

But trying to write text or graphics with that code is rather difficult. It's using only two bytes to write to the shift registers.
I found several editors that generate text and graphic code. This seems to be the best.
https://xantorohara.github.io/led-matrix-editor/

But the problem is how to use it! The python code I'm using is using a 2 byte system, 1 byte for rows and the other byte for columns.
And all editors/code generators are generating 8 bytes, one byte for each row.

How do i adapt or write code for that? Have been googling for hours for examples but no luck.
All code I'm finding is using max7219/21 and not the shift registers.

Anyone got any idea how to solve this? Any help appreciated!

Edit: I'm aware that the generator is creating c code, but converting it to python is a minor issue. The problem is how to convert the 8 byte data and send it to the shift registers.

Ageir
Posts: 17
Joined: Wed May 03, 2017 5:48 pm

Re: Code for LED matrix with shift registers.

Fri Nov 17, 2017 12:52 pm

Basically anything really. Just using two bytes, 0x00, 0xff etc is a pain to draw any shape.

BitHead
Posts: 15
Joined: Wed Sep 03, 2014 1:14 pm

Re: Code for LED matrix with shift registers.

Fri Nov 17, 2017 3:59 pm

Use that 8x8 matrix code and 'pretend' it is going to LED matrix - but really write it to an 8x8 array in ram.
Then, using a timer-interrupt, write a routine that reads that array and turns bit positions into 'Y' register columns for each of your 8 'X' register rows.
20mS human eye flicker perception limit / 8 -> about 2mS timer timeout time.

Good luck!

Ageir
Posts: 17
Joined: Wed May 03, 2017 5:48 pm

Re: Code for LED matrix with shift registers.

Sat Nov 18, 2017 3:14 pm

Thanks BitHead. Will try it.

What's the best way to convert/store this in python? Array? Tuple? List? Matrix?

Code: Select all

const byte IMAGES[][8] = {
{
  B00000000,
  B00011000,
  B00011000,
  B00111000,
  B00011000,
  B00011000,
  B00011000,
  B01111110
},{
  B00000000,
  B00111100,
  B01100110,
  B00000110,
  B00001100,
  B00110000,
  B01100000,
  B01111110
},{
  B00000000,
  B00111100,
  B01100110,
  B00000110,
  B00011100,
  B00000110,
  B01100110,
  B00111100
},{
  B00000000,
  B00001100,
  B00011100,
  B00101100,
  B01001100,
  B01111110,
  B00001100,
  B00001100
},{
  B00000000,
  B01111110,
  B01100000,
  B01111100,
  B00000110,
  B00000110,
  B01100110,
  B00111100
},{
  B00000000,
  B00111100,
  B01100110,
  B01100000,
  B01111100,
  B01100110,
  B01100110,
  B00111100
},{
  B00000000,
  B01111110,
  B01100110,
  B00001100,
  B00001100,
  B00011000,
  B00011000,
  B00011000
},{
  B00000000,
  B00111100,
  B01100110,
  B01100110,
  B00111100,
  B01100110,
  B01100110,
  B00111100
},{
  B00000000,
  B00111100,
  B01100110,
  B01100110,
  B00111110,
  B00000110,
  B01100110,
  B00111100
},{
  B00000000,
  B00111100,
  B01100110,
  B01101110,
  B01110110,
  B01100110,
  B01100110,
  B00111100
}};
Edit: When I think of it, it would be better to store the character/number etc with the data so that it could be found more easily.

Code: Select all

'1', {
  B00000000,
  B00011000,
  B00011000,
  B00111000,
  B00011000,
  B00011000,
  B00011000,
  B01111110
}
Not sure what's the best way to do this.

Ageir
Posts: 17
Joined: Wed May 03, 2017 5:48 pm

Re: Code for LED matrix with shift registers.

Sat Nov 18, 2017 4:04 pm

Looking into it I'm guessing a dictionary containing tuples would be a good choice.

Code: Select all

num= {'1': (0b00000000,
  	            0b00011000,
                    0b00011000,
                    0b00111000,
                    0b00011000,
                    0b00011000,
                    0b00011000,
                    0b01111110),
              '2':(0b00000000,
                     0b00111100,
                     0b01100110,
                     0b00000110,
                     0b00001100,
                     0b00110000,
                     0b01100000,
                     0b01111110)
            }
Something like this. Am I right? Any better solution?

Ageir
Posts: 17
Joined: Wed May 03, 2017 5:48 pm

Re: Code for LED matrix with shift registers.

Sat Nov 18, 2017 6:37 pm

That's working just fine. But it's all inversed on my display.
How do i rotate the bitmap in python?

This is the number two how it should look like.

Code: Select all

             '2':(0b00000000,
                     0b00111100,
                     0b01100110,
                     0b00000110,
                     0b00001100,
                     0b00110000,
                     0b01100000,
                     0b01111110)
And this is what my display is showing. It's backwards.

Code: Select all

             '2':(0b00000000,
                     0b00111100,
                     0b01100110,
                     0b01100000,
                     0b00110000,
                     0b00001100,
                     0b00000110,
                     0b01111110)
What's the easiest way to rotate it? Any build it function for this?

monochromaticmau
Posts: 2
Joined: Thu Apr 25, 2019 10:20 am

Re: Code for LED matrix with shift registers.

Thu Apr 25, 2019 10:23 am

I'm going through the same thing right now. Can you share the altered code that made it work?

Did you put resistors in your system? The instructions don't include it, but most content online have current limiting resistors, and I'm noticing some weird behavior when I try to Multiplex. Not what I would expect. I found this great article https://circuitdigest.com/microcontroll ... spberry-pi that helps explain what needs to get done to get unique shapes without lighting unwanted LEDs.

When I slow down the cycles it's what I expect, but when I speed it up to attempt to Multiplex, more lights than what I turn on light up, etc.


Andyroo
Posts: 3316
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Code for LED matrix with shift registers.

Thu May 23, 2019 7:42 pm

Please be aware the the original poster has not been here since Nov 18, 2017 7:52 pm and it’s unlikely a mail notification on the post would get any reply.

It’s best to create a new topic referencing this old one with a simple link and explain what you have so far. Often old topics require out of date or unavailable software, OS or websites.
Need Pi spray - these things are breeding in my house...

Return to “Python”