Shitty Amateur Electronics - Part 9: Completing the Matrix

It’s time for me to do something I never usually do: finish a project.

I dug the LED matrix out of the drawer and hooked it up to my Pi Zero. Luckily there are enough GPIO pins on each side to let me plug the rows on one side and the columns on another. Keeps it easier to manage. I’m tempted to wire it up to a 40 pin connector to make it even easier, but then I couldn’t use it on any other device than an RPi or compatible device.

The first thing to do is dig out some code fragments from other projects to build a framework to start from. Because I’m a shit coder. I piece things together like Marconi inventing the radio. I cut and paste things and edit to make it work. I code by Google a lot. That’s extremely bad, but I just suck at learning how to code naturally. I used to be good at it, but those days are behind me. However, Python is quite an easy language to understand.

I managed to get something workable. Firstly the code uses a loop to set some pins for use as outputs. Then I wrote another loop to cycle through each row in term. After an individual row has been turned on we need to do the columns. If we do them in order with a short delay between them we should then cycle through each of the 6 LEDs in the row. Then the next iteration of the row loop turns off that row and turns on the next one.

Firstly I made the delay between lights really long as a test mode to check each LED. And they all worked! A few flickery connections which I later figured out were loose connections to the GPIO pins on the RPi side. Annoying but confirms my prototype board actually works and was well constructed. Ish.

And so it was time to light all of the LEDs at once - or at least appear to my brain to all be lit at once. Lower the delay! I had to experiment to find the right delay so that there wasn’t any flickering, but I settled on 0.00001 seconds. And as expected I had a square full of light. It was then that I realised I was being silly and could change the code to do a full row at a time, as I have previously described. This meant I could lower the delay to 0.001 seconds. At 0.006 seconds for a full frame this gave a refresh rate of 167 Hz. Tidy. (apologies for portrait video).

So obviously I showed off to the wife next.

But now it was time to get clever. Let’s look into animations. By only slightly adjusting the code and making a larger array we can store multiple strings of data for the drawing loop - which will also need adjusting to point to the current frame. Changing the loop to add a counter system makes it possible to do rudimentary timings between frames as well.

And here’s the result. A simple 3 frame animation to test the concept.

And here’s where this blog ends. I’ll work towards putting this in a protective box with a see through top, or make one of those frosted pixel-type displays instead. But right now I’ve proven that the stupid board I made from scratch actually works. I think it’s time to take stock at this point and acknowledge that for someone who only had a tiny knowledge about electronics I’ve done fairly well getting to this point.

Time to start thinking about the next project and look for some new toys to play with...

Comments