Uncategorized

Showing letters on a 8×8 dot matrix display with only 3 GPIO pins on Raspberry PI

I have been playing around with connecting electronics to the raspberry pi, so I bought the Sunfounder SuperKit v2 for Raspberry PI. It’s a great value and comes with everything you need to begin playing with the PI and electronics. Really recommended.

711vaK78H0L._SL1000_

The book shows what to do with each of the main components (engine, display, etc). One of the components I really like is the Dot Matrix display. On their example, it is shown how to use the two shift register micro controllers in cascade, to be able to control the 64 LEDS using just three outputs (bits) from the Raspberry. As you can see on their schematics, it uses GPIO 11, 12 and 13:

4.png

With it, they have shown how to display one line or column at a time. Which is hardly what you want with this thing. In fact, they give you very unfriendly examples on how to display. Their code just shows you this:

code_H = [0x01,0xff,0x80,0xff,0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff]
code_L = [0x00,0x7f,0x00,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f]

Full code on Sunfounder’s GitHub

So I decided to improve. Taking that program, I created a 6×8 binary representation of the alphabet, and I show one letter at a time. So, one can just type

display_phrase("This is a test 0 0 0") # Zero shows a heart :-)

And it will show exactly this.

My version of the code also improves on the fact that it is easier to understand how to draw with mine: You just draw in binary, from right-to-left, an 8×8 square and it will show it. The value zero is a pixel on, 1 is a pixel off.

alphabet= {'A': [0b11110011,
                 0b11101101,
                 0b11011110,
                 0b11011110,
                 0b11000000,
                 0b11011110,
                 0b11011110,
                 0b11011110], ... }

A letter A. Easy to draw like this, isn’t it? 🙂

It also always cleanup the GPIO values, among other things. You can fork my code from GitHub.

Advertisements
Standard

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s