Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Creating custom characters for LCD printing


  • Please log in to reply
15 replies to this topic

#1 terb

terb

    Member

  • Members
  • PipPip
  • 22 posts

Posted 17 September 2012 - 08:30 PM

Hi all ! I'm trying to create custom characters for my LCD shield. It's a 16x2 screen with 8x5 characters, and I drive it with the Hd44780Lcd class. I found a link that seems useful (http://www.quinapalu...hd44780udg.html) to translate a pixel matrix into numeric elements, but I don't understand how I should set my custom characters. I tried to write a byte array using hexadecimal values but it doesn't work. If somebody has an idea to solve this problem, I would really appreciate it :) thank you very much !

#2 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 18 September 2012 - 06:13 AM

Hi Terb,

I've done that before, for this project:

The code isn't published yet, but the method for the custom characters is this one:
       public static void main()
       {
            // To play snake on a 2x16 LCD, we need 7 custom characters (0x00 to 0x06):
            _CustomizeCharacter(0x00, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x0e, 0x00 }); // b000: ₒ     (fruit at the bottom)
            _CustomizeCharacter(0x01, new byte[] { 0x00, 0x0e, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00 }); // b001: °     (fruit at the top)
            _CustomizeCharacter(0x02, new byte[] { 0x1f, 0x1f, 0x1f, 0x1f, 0x00, 0x00, 0x00, 0x00 }); // b010: ▀     (snake at the top)
            _CustomizeCharacter(0x03, new byte[] { 0x1f, 0x1f, 0x1f, 0x1f, 0x00, 0x0e, 0x0e, 0x00 }); // b011: ▀ + ₒ (snake at the top + fruit at the bottom)
            _CustomizeCharacter(0x04, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x1f, 0x1f, 0x1f, 0x1f }); // b100: ▄     (snake at the bottom)
            _CustomizeCharacter(0x05, new byte[] { 0x00, 0x0e, 0x0e, 0x00, 0x1f, 0x1f, 0x1f, 0x1f }); // b101: ▄ + ° (snake at the bottom + fruit at the top)
            _CustomizeCharacter(0x06, new byte[] { 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f }); // b110: █     (snake at the bottom + snake at the top)
       }

        /// <summary>
        /// Creates a customized character on a HD44780 LCD
        /// </summary>
        /// <param name="Index">Character index (0 to 7)</param>
        /// <param name="Character">Character bitmap</param>
        private static void _CustomizeCharacter(int Index, byte[] CharacterBitmap)
        {
            if (Index < 0 || Index > 7) throw new IndexOutOfRangeException("Index must be a value from 0 to 7");
            if (CharacterBitmap.Length != 8) throw new ArgumentOutOfRangeException("CharacterBitmap must have 8 byte values");
            _disp.Write((byte)(0x40 + 8 * Index), true); // Set CGRAM Address
            _disp.Write(CharacterBitmap);                // Writes the character
            _disp.Write(0x80, true);                     // Set DDRAM Address
        }
Maybe that'll help you?

_disp is an instance of Toolbox.NETMF.Hardware.Hd44780Lcd
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#3 terb

terb

    Member

  • Members
  • PipPip
  • 22 posts

Posted 21 September 2012 - 08:11 AM

Hi Stefan, thank you very much ! I use the same class so it will be easy to try your method on my program. thank you again, I'll try this today and let you know :) By the way I watched your video, it's really great. I like the idea of using a 2-lines screen and custom characters to use it as a 4-line screen.

#4 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 21 September 2012 - 08:30 AM

By the way I watched your video, it's really great. I like the idea of using a 2-lines screen and custom characters to use it as a 4-line screen.

Thanks!

I hope to release the code next week :)
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#5 terb

terb

    Member

  • Members
  • PipPip
  • 22 posts

Posted 21 September 2012 - 08:40 AM

I just tried this way to set and display custom characters, it works perfectly. Thank you again Stefan ! your help is really precious to me. do you know how many custom characters can be set on these LCD screens ?

#6 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 21 September 2012 - 08:42 AM

do you know how many custom characters can be set on these LCD screens ?

Yep, only 8 :(
Hence this line of code:
if (Index < 0 || Index > 7) throw new IndexOutOfRangeException("Index must be a value from 0 to 7");
B)


I wish it could do more, but it's still very nice for such cheap displays I reccon.
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#7 terb

terb

    Member

  • Members
  • PipPip
  • 22 posts

Posted 21 September 2012 - 09:49 AM

Yes, that's what I understood. I need way more than 8 custom chars, but I think I can deal with 8 custom chars displayed at a given time. I think I will do something like redefine the custom chars dynamically. should work :) By the way, I'm ok with you, these screens are pretty cheap and it's a good thing to have 8 custom chars. way better than nothing :)

#8 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 21 September 2012 - 10:49 AM

Yes, that's what I understood. I need way more than 8 custom chars, but I think I can deal with 8 custom chars displayed at a given time. I think I will do something like redefine the custom chars dynamically. should work :)

That's a good thing to do; dynamically. My app will do that too. While playing the game, it'll contain 8 characters required for the snake, but I will also have a graphical splash screen, composed with 8 other characters :)
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#9 terb

terb

    Member

  • Members
  • PipPip
  • 22 posts

Posted 21 September 2012 - 11:26 AM

Great ! I'd love to see this spash screen :) My goal is to display big numbers but I will have no more than 2 numbers at the same time. Each digit will be displayed on 4 characters (2x2 matrix) so I'm fine with 8 user-defined characters at a given time. I'd like to add other fancy characters but the 8 chars limit won't allow me that. Not a big issue.

#10 terb

terb

    Member

  • Members
  • PipPip
  • 22 posts

Posted 22 September 2012 - 08:12 AM

I tried the dynamic user-defined characters, it works fine. One interesting point (at least for my project) is that there is no need to write the character after redefying it, if the position doesn't change. It means that I will write my 8 custom characters at fixed positions on the LCD screen, and I will change the values by dynamically redefying the characters, directly in the LCD controller RAM. I'm writing a class to manage all these operations, and I will only have to change the values with something like this :
Lcd.WriteBigCharacters("14");


#11 terb

terb

    Member

  • Members
  • PipPip
  • 22 posts

Posted 25 September 2012 - 06:35 PM

Here it is ! a short demo video showing every character (number) several times over a 1-minute loop : http://rutube.ru/vid...79d27361df83d1/ it works by dynamic characters definition, as we said before.

#12 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 25 September 2012 - 07:05 PM

Here it is ! a short demo video showing every character (number) several times over a 1-minute loop : http://rutube.ru/vid...79d27361df83d1/
it works by dynamic characters definition, as we said before.

Nice use of the dynamic characters, terb.

Chris

#13 terb

terb

    Member

  • Members
  • PipPip
  • 22 posts

Posted 25 September 2012 - 07:07 PM

thanks Chris

#14 terb

terb

    Member

  • Members
  • PipPip
  • 22 posts

Posted 05 October 2012 - 09:37 AM

Hi there !
just a quick update : a simple waiting screen (will be used when the GPS will be searching for satellites). It's a 16-steps sequence loop that uses dynamic custom characters definition. It uses 20 custom characters (+ 40 other ones for the numbers) in total, 8 at a given time.

here it is : http://rutube.ru/vid...b238eb5298c8c36

#15 nhale

nhale

    Advanced Member

  • Members
  • PipPipPip
  • 64 posts
  • LocationHeidelberg, Germany

Posted 02 February 2013 - 06:38 PM

Hi Terb,

I've done that before, for this project:

The code isn't published yet, but the method for the custom characters is this one:

       public static void main()       {            // To play snake on a 2x16 LCD, we need 7 custom characters (0x00 to 0x06):            _CustomizeCharacter(0x00, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x0e, 0x00 }); // b000: ₒ     (fruit at the bottom)            _CustomizeCharacter(0x01, new byte[] { 0x00, 0x0e, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00 }); // b001: °     (fruit at the top)            _CustomizeCharacter(0x02, new byte[] { 0x1f, 0x1f, 0x1f, 0x1f, 0x00, 0x00, 0x00, 0x00 }); // b010: ▀     (snake at the top)            _CustomizeCharacter(0x03, new byte[] { 0x1f, 0x1f, 0x1f, 0x1f, 0x00, 0x0e, 0x0e, 0x00 }); // b011: ▀ + ₒ (snake at the top + fruit at the bottom)            _CustomizeCharacter(0x04, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x1f, 0x1f, 0x1f, 0x1f }); // b100: ▄     (snake at the bottom)            _CustomizeCharacter(0x05, new byte[] { 0x00, 0x0e, 0x0e, 0x00, 0x1f, 0x1f, 0x1f, 0x1f }); // b101: ▄ + ° (snake at the bottom + fruit at the top)            _CustomizeCharacter(0x06, new byte[] { 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f }); // b110: █     (snake at the bottom + snake at the top)       }        /// <summary>        /// Creates a customized character on a HD44780 LCD        /// </summary>        /// <param name="Index">Character index (0 to 7)</param>        /// <param name="Character">Character bitmap</param>        private static void _CustomizeCharacter(int Index, byte[] CharacterBitmap)        {            if (Index < 0 || Index > 7) throw new IndexOutOfRangeException("Index must be a value from 0 to 7");            if (CharacterBitmap.Length != 8) throw new ArgumentOutOfRangeException("CharacterBitmap must have 8 byte values");            _disp.Write((byte)(0x40 + 8 * Index), true); // Set CGRAM Address            _disp.Write(CharacterBitmap);                // Writes the character            _disp.Write(0x80, true);                     // Set DDRAM Address        }
Maybe that'll help you?

_disp is an instance of Toolbox.NETMF.Hardware.Hd44780Lcd

 

Hi,

 

I just bought the Adafruit 16x2 LCD with a RCB LCD in a package and it works fine for standard character.

Now I tried you code above, but nothing is shown...do I have to call the character somehow to actually write it to the screen?

 

Thanks



#16 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 04 February 2013 - 07:40 AM

Hi,

 

I just bought the Adafruit 16x2 LCD with a RCB LCD in a package and it works fine for standard character.

Now I tried you code above, but nothing is shown...do I have to call the character somehow to actually write it to the screen?

 

Thanks

 

Yes, you must call the character. You can best check out this sample code:

http://netmftoolbox....ew/21723#339006

 

        /// <summary>        /// Shows the splash screen        /// </summary>        public static void Splash()        {            _disp.ClearDisplay();            _NetduinoLogo();            _disp.Write(" HD44780  Snake");            _disp.ChangePosition(1, 2);            _disp.Write("for ");            _disp.Write(new byte[] { 0, 1, 2, 3, 4, 5, 0, 6 }, false);        }

The last line writes the characters by their index.


"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.