A simple way to do fixed graphics (or a BIG font) on a DMD

The Dot Matrix Display (DMD) is a 32x16 array of high-brightness LEDs for visually striking effects. [Product Page]
Post Reply
Brissieboy
Posts: 181
Joined: Fri Sep 20, 2013 7:25 am

A simple way to do fixed graphics (or a BIG font) on a DMD

Post by Brissieboy » Fri Apr 11, 2014 11:55 pm

It is possible to use a font to handle non-animated DMD graphics. In fact it is a really easy way to do it.

The same approach can be used to display full screen characters on a vertical DMD (32 pixels high by 16 pixels wide). Or anything else for that matter.

We can define a font like this one:

Code: Select all

#include <inttypes.h>
#include <avr/pgmspace.h>

#ifndef MYGRAPHICSFONT_H
#define MYGGRAPHICSFONT_H

static uint8_t MyGraphicsFont[] PROGMEM = { // the name here 'MyGiantFont' must be used to refer to this font
                                            // 'PROGMEM' forces the data into programme space to save RAM
    0x00, 0x00, // size     0 here indicates a fixed width font
    0x20, // width          these are 32 pixels wide (a full DMD)
    0x10, // height         max height of the characters = 16 (a full DMD)
    0x31, // first char     hex value of the first character ('1')
    0x02, // char count     the number of characters in this font

    // font data
    // only 2 characters defined - these are accessed by '1' (ascii 49/0X31) and '2' (ascii 50/0X32)

// first char is a '1' as a sample of the use of BIG characters on a vertical DMD
0XC0, 0XC0, 0XC0, 0XC0, 0XC0, 0XC0, 0XC0, 0XC0, 0XC0, 0XC0, 0XC0, 0XC0, 0XC0, 0XC0, 0XC0, 0XC0, 0XC0, 0XC0, 0XC0, 0XC0, 0XC0, 0XC0, 0XC0, 0XC0, 0XC0, 0XC0, 0XC0, 0XC0, 0XC0, 0XF0, 0XF0, 0XF0, 0X01, 0X03, 0X07, 0X0F, 0X01, 0X01, 0X01, 0X01, 0X01, 0X01, 0X01, 0X01, 0X01, 0X01, 0X01, 0X01, 0X01, 0X01, 0X01, 0X01, 0X01, 0X01, 0X01, 0X01, 0X01, 0X01, 0X01, 0X01, 0X01, 0X0F, 0X0F, 0X0F, // note the comma at the end

// second one is a simple graphic screen
0XFF, 0X01, 0X01, 0X31, 0X31, 0X01, 0X01, 0X31, 0X31, 0X01, 0X01, 0X01, 0X01, 0X31, 0X31, 0X01, 0X01, 0X31, 0X31, 0X01, 0X01, 0X01, 0X01, 0X31, 0X31, 0X01, 0X01, 0X31, 0X31, 0X01, 0X01, 0XFF, 0XFF, 0X80, 0X82, 0X84, 0X88, 0X88, 0X88, 0X88, 0X84, 0X82, 0X80, 0X80, 0X84, 0X84, 0X84, 0X84, 0X84, 0X84, 0X84, 0X84, 0X80, 0X80, 0X88, 0X84, 0X82, 0X82, 0X82, 0X82, 0X84, 0X88, 0X80, 0XFF // note NO comma on the last entry

};

#endif
Save the file as MyGraphicsFont.h

Now in your sketch make sure you include the line:
#include "MyGraphicsFont.h"
where the other includes are located.

Use dmd.drawChar() to draw these characters, but how you use it will depend on the version of the DMD library you are using as there are critical differences.

First select the font with:
dmd.selectFont( MyGraphicsFont );
then display a character by either:
dmd.drawChar(0, 0, '1', GRAPHICS_NORMAL);
or
dmd.drawChar( 0, 0, '1', 1, 0 );

These will print a full screen '1' vertically to demonstrate the BIG vertical font,
or use '2' to display the simple graphics demo horizontally.

Note that this demo font only has the 2 characters defined, but it can be extended as required.
As each character/screen takes 64 bytes it can use a fair bit of memory, but that is required for any graphics. You can define as many, or as few, characters in the font as you need.

Take care if using dmd.drawString() to display these 'characters' as this puts a blank line before and after the text which can overwrite adjacent space (if you are using more than 1 DMD) so it is better to draw just a single 'character' with dmd.drawChar().
The only overhead for this approach is the 6 bytes at the head of the font declaration. It saves in code by being able to use existing DMD library functions without any modifications.

The excel file attached is a simple tool which will generate the font data required.
It simplifies the conversion from a visual screen representation into the data which represents it.
I have included a portrait view wich makes it much easier to design vertical graphics/characters.
It contains a macro, so macros must be enabled for it to work properly.
It has some basic instructions included.
It is very basic but can be adapted as required.
The data produced is only suitable to use in this approach - the data produced is NOT the same as the data required to directly populate the DMD screen buffer. It could easily be modified to do this, but that approach that would also require mods to the DMD library.
It could also be modified to cope with multiple DMDs or something less that a full DMD.

I hope this is useful.
Attachments
DMD Graphic Tool.zip
(30.57 KiB) Downloaded 991 times

andrew
Freetronics Staff
Freetronics Staff
Posts: 978
Joined: Sun Jul 14, 2013 7:06 am
Location: Melbourne, Australia
Contact:

Re: A simple way to do fixed graphics (or a BIG font) on a D

Post by andrew » Sat Apr 12, 2014 6:50 am

Well done, I'm sure many people will find that useful.

User avatar
stryker
Posts: 282
Joined: Sat Jan 14, 2012 2:44 pm

Re: A simple way to do fixed graphics (or a BIG font) on a D

Post by stryker » Sat Apr 12, 2014 9:15 am

Thanks again!

haydent
Posts: 4
Joined: Fri Jan 23, 2015 9:52 am

Re: A simple way to do fixed graphics (or a BIG font) on a D

Post by haydent » Fri Jan 23, 2015 11:34 am

thanks, this is neat.

dinoelectro
Posts: 5
Joined: Sat Nov 05, 2016 12:38 pm

Re: A simple way to do fixed graphics (or a BIG font) on a DMD

Post by dinoelectro » Sat Nov 05, 2016 12:51 pm

[quote="Brissieboy"]It is possible to use a font to handle non-animated DMD graphics. In fact it is a really easy way to do it.

tanks Brissieboy i found a bug but its solved...

replace this line;

static uint8_t MyGraphicsFont[] PROGMEM =

by this;

const static uint8_t MyGraphicsFont[] PROGMEM =

greetings!!!

dinoelectro
Posts: 5
Joined: Sat Nov 05, 2016 12:38 pm

Re: A simple way to do fixed graphics (or a BIG font) on a DMD

Post by dinoelectro » Sun Nov 06, 2016 10:00 am

Please someone knows if DMD library is situable for programing model P5 32x64 display?

Image

KegRaider
Posts: 15
Joined: Sun Sep 09, 2012 12:08 am

Re: A simple way to do fixed graphics (or a BIG font) on a DMD

Post by KegRaider » Mon Dec 05, 2016 1:46 am

Hi dinoelectro,

I cannot see why it wouldn't work, provided it is connected to the arduino in a similar fashion as the Freetronics style panels. I would try with these values, to effectively double the amount of LED's (V & H) expected from the Freetronics DMD. Have you tried with your panel, or are you just looking around??

Code: Select all

    
    0x00, 0x00, // size     0 here indicates a fixed width font
    0x40, // width          these are 32 pixels wide (a full DMD)
    0x20, // height         max height of the characters = 16 (a full DMD)
 
** Edit: Removed Profanity :)

Post Reply