HCuOLED library for SSD1307 & SH1106 based OLED displays

Useful guides, libraries, and example sketches to support our Arduino based products.
andrew
Site Admin
Posts: 1133
Joined: Sun Aug 05, 2012 4:15 pm

Re: HCuOLED library for SSD1307 & SH1106 based OLED displays

Post by andrew » Mon Feb 15, 2021 4:56 pm

You can use a program called The Dot Factory to generate new fonts:

http://www.eran.io/the-dot-factory-an-l ... generator/

It will take an existing installed font and will generate 3 tables, one containing the font bitmap information, a descriptor table, and a font info table.

You'll need to add these tables to the fonts.h file found in the HCuLED library folder. I would recommend taking a look at the existing fonts in that file to get an idea of how they are stored.

You'll also need to add a reference for any font(s) you add to the HCuLED.h file. Lines 50 to 52 in that file are where the existing fonts are listed.

One other tip is when you're viewing/editing these files don't use Windows Notepad. It's rubbish and gets the formatting wrong. Use a proper text editor like Notepad++ (https://notepad-plus-plus.org/downloads/) to edit them.

Btw, the smallest font in the library is only 8 pixels tall so I think it's going to be difficult to generate a readable font that's smaller than that.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

ChrisSharp
Posts: 8
Joined: Thu Dec 31, 2020 1:22 pm

Re: HCuOLED library for SSD1307 & SH1106 based OLED displays

Post by ChrisSharp » Mon Feb 15, 2021 10:04 pm

Thanks for the info.

As a Mac user this was going to be complicated for me, but I have a Virtual Machine so I do have access to Windows.

The main stumbling block was the output from The Dot Factory. I eventually realised that it was outputting the "bit layout" as rows and I need to change this in the configuration to columns. At which point everything worked fine.

On a readability point of view, Verdana was the classic website font when everyone loved to write websites with small text so I went with that. It's OK at 6pt, but better at 5pt! I've touched up a few of the characters when The Dot Factory fell short.

The final challenge was to get tweak the character spacing form 2 pixels to 1. "2" appears 142 times in HCuLED.ccp, so it took a bit of finding.

I added some extra "else if" statements at the bottom of HCuLED.cpp while I was hacking around trying to get things working. You didn't mention this in your instructions, but I do need them there to get it to work with my new fonts.

Thanks again for your help. I very much appreciate the value you add with this form, I've learnt a lot about how to use your products from it.

andrew
Site Admin
Posts: 1133
Joined: Sun Aug 05, 2012 4:15 pm

Re: HCuOLED library for SSD1307 & SH1106 based OLED displays

Post by andrew » Tue Feb 16, 2021 11:54 am

I added some extra "else if" statements at the bottom of HCuLED.cpp while I was hacking around trying to get things working. You didn't mention this in your instructions, but I do need them there to get it to work with my new fonts.
Ah sorry about that. I wrote that library years ago so it's hard to remember what's need to add another font. Tbh I expected you to come back with more questions so I'm impressed you figured it all out so quickly without help. At some point in the future I intend to add support for these displays into the newer HCDisplay library which handles fonts slightly better.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

ChrisSharp
Posts: 8
Joined: Thu Dec 31, 2020 1:22 pm

Re: HCuOLED library for SSD1307 & SH1106 based OLED displays

Post by ChrisSharp » Fri Feb 19, 2021 10:07 am

Thanks for the comment on working it out "so quickly without help." It felt anything but quick at this end. :?

I spent some time touching up the output of The Dot Factory. By "some time" I mean several hours and "touching up" completely redrawing the fonts in 6pt and 5pt.

The result is tiny text which is just readable, which is what I'm aiming for in railway modelling.

If you are updating the libraries and would like to include a tiny text option then I'm happy to send you the font file.
IMG_0337.jpg
I'm not familiar with C++. And making the text on the screen dynamic rather than hard coded is taking me ages. Very confused by char, String, when an * is needed and what that * does and how the whole lot interact with arrays. But I'm making progress, very slowly.
You do not have the required permissions to view the files attached to this post.

andrew
Site Admin
Posts: 1133
Joined: Sun Aug 05, 2012 4:15 pm

Re: HCuOLED library for SSD1307 & SH1106 based OLED displays

Post by andrew » Fri Feb 19, 2021 11:11 am

That looks fantastic. Yeah please do send a copy. As soon as I get chance I'll check it and update the library. I'll be sure to credit you in the source code of course.

I may also have to steal it to use in other libraries if you don't mind ;-)
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

ChrisSharp
Posts: 8
Joined: Thu Dec 31, 2020 1:22 pm

Re: HCuOLED library for SSD1307 & SH1106 based OLED displays

Post by ChrisSharp » Fri Feb 19, 2021 5:32 pm

Cool. I'll take another pass at the bit maps and tweak some of the punctuation, which I skipped by because I wouldn't be using those characters.

Shall I post it on here or would you prefer me to email it to you.

I don't mind where it is used. Justifies the amount of time I took getting it to work and look readable.

andrew
Site Admin
Posts: 1133
Joined: Sun Aug 05, 2012 4:15 pm

Re: HCuOLED library for SSD1307 & SH1106 based OLED displays

Post by andrew » Sat Feb 20, 2021 8:39 am

As it's only a small file best option is to Just attach it as a post here when you're happy with it. Thanks.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

ChrisSharp
Posts: 8
Joined: Thu Dec 31, 2020 1:22 pm

Re: HCuOLED library for SSD1307 & SH1106 based OLED displays

Post by ChrisSharp » Sat Feb 20, 2021 1:11 pm

Another few hours tweaking the fonts. I actually enjoy corralling pixels into place, so it wasn't a chore. And the text on my screens is much improved.

There are two sizes of shapsharp font. They are 5pt and 6pt which gives them a 7px and 8px height. Width is variable.

If you do rewrite the libraries then I recommend that you change the character spacing for these fonts from 2px to 1px. Or you could change SetFont to include an optional spacing value. something like HCuOLED.SetFont(sharpsharp_5pt, 1); Just a thought.

file attached. Feel free modify the fonts.

cheers
You do not have the required permissions to view the files attached to this post.

andrew
Site Admin
Posts: 1133
Joined: Sun Aug 05, 2012 4:15 pm

Re: HCuOLED library for SSD1307 & SH1106 based OLED displays

Post by andrew » Sun Feb 21, 2021 8:24 am

Excellent. As soon as I can grab a bit of time I'll get a display set up and test it.
If you do rewrite the libraries then I recommend that you change the character spacing for these fonts from 2px to 1px. Or you could change SetFont to include an optional spacing value. something like HCuOLED.SetFont(sharpsharp_5pt, 1); Just a thought.

Yeah the HCDisplay library can handle different font spacing widths. It does it by having an extra font spacing parameter in the font info table. As I say I'd like to add the OLED displays into the library at some point but I'll see if I can make an update to the HCuOLED library to support this feature.

Hopefully I'll get chance to look at it this next week. I'll let you know as soon as I've updated it.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

andrew
Site Admin
Posts: 1133
Joined: Sun Aug 05, 2012 4:15 pm

Re: HCuOLED library for SSD1307 & SH1106 based OLED displays

Post by andrew » Wed Feb 24, 2021 11:31 am

Hi Chris, just to let you know I've tested the font and it looks great - so tiny! I've now updated the HCuLED library (V0.7) to include your fonts and I've also included the ability to use a different character spacing for each font with yours set to 1pt. Thanks again for this contribution.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

Post Reply