Sunday, 5-January-2020
Atmel ATTiny85 and mini OLED 128*32px i2c how to..
EN
Welcome!
Have you been searching in internet for that particular combination of OLED screen and controller? Yeah, me too.
And I found some solution that work good for me, and if you like to test it hopefully do the same for you.
Before starting my write up, will kindly suggest you to get the following:
TinyWireM - I2C library , best for Attiny85
You can downloaded it here: http://github.com/adafruit/TinyWireM
Tiny4kOLED - one really good I2C OLED library, dedicated to 128*32 - SSD1306 module
You can downloaded it here: https://github.com/datacute/Tiny4kOLED
LCD Image Converter - that is the best converting ALL IN ONE software
I`ve ever found. And will do most of the work for you. All credits goes to it the developer.
You can downloaded it here: https://www.riuson.c … /lcd-image-converter
IMPORTANT:
- inside the file: Tiny4kOLED.h (from Tiny4kOLED library folder) , find that: #include “Tiny4kOLED_TinyWireM.h” It should be unmarked, and all other with “//” in front
- ATTINY85 SDA/SCL pins are : SDA= D0 (pin5) / SCL=D2(pin7)
Once you get the software, let`s continue:
There are few compact SSD1306 libraries there, but I like Tiny4kOLED because the option to add and use own custom fonts. For me, as not good programmer who can correct with ease the libraries, that is pure bonus!
Important thing here that you need to keep in mind is, that every font`s height must be 8px or multiple of 8 like 16,24,32px. As width can be set any pixel size.
Creating font:
For LCD Image Converter you can create own custom template of how the data will be exported.
In the code block below, will share mine that so far give quite good result. Feel free to use it or modify it.
$(start_block_header) /* * -------------------------------------------------------------------- * generated by lcd-image-converter rev.$(app_rev) from $(app_date) * $(doc_data_type) * filename: $(doc_filename) * name: $(doc_name) * included characters: $(fnt_string) * unicode bom: $(fnt_use_bom) * * preset name: $(out_preset_name) * data block size: $(img_data_block_size) bit(s), uint$(img_data_block_size)_t * RLE compression enabled: $(img_rle) * conversion type: $(pre_conv_type), $(pre_mono_type) $(pre_mono_edge) * bits per pixel: $(out_bpp) * -------------------------------------------------------------------------- <strong>/ $(end_block_header) // ---------------------------------------------------------------------------- #include <avr/pgmspace.h> // ---------------------------------------------------------------------------- const uint8_t $(doc_name_ws)_bitmap [] PROGMEM = { $(start_block_images_table)$(out_image_data), // 0x$(out_char_code) - $(out_char_text) $(end_block_images_table) }; const DCfont $(doc_name_ws) = { (uint8_t *)$(doc_name_ws)_bitmap, XX, // character width in pixels, write correct one $(fnt_size), // character height in pages (8 pixels per page) so correct that one 0x20,0x7e // ASCII extents like 48,52 <-start , end - that cover full space to ~ array };
When the conversion is done, and you get your data file inside need small adjustments to be made. About that I`ll write after few paragraphs again.
Will assume for now, that we use my template. Let`s open the program and select “New font”:
Select name for your font project:
Now, you need to do some settings and you start with Source font (1).
There will be list with all available to use fonts. (2) and their type as Bold, italic.. (3). The selected size (4) is not as straight forward as I expected to be but after playing a little, you`ll get how to use it. In the lower corner will be the current size in pixels for given character (5). In the big table (6) you have listed all characters and in the field (7) is the character order.
In the picture you see 18px font height but that should not be an issue, as one can resize the font little after been selected.
Please, continue and we`ll get to it.
Select characters to be included in your project: now, you can select all characters (really big array), only the all base ones or in case you like to create full screen clock.. only the numbers.
For that example will create listing with all basic Latin characters:
!”#$%&’()+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~
Now, we select the color and how the characters will be distributed. I choose black as background and white as font color, because wish my text/graphic to be shown by bright pixels on the screen. Then the next option is : Monospaced
That is selected, because in that way each glyph will take exactly same space.The library read each glyph data from array and will fill exactly same “rectangle” and need to have that data. For example “!” and “W” for font 6×8px will be 8 bytes no matter what. If “Proportional” is your choice then you`ll get different WIDTH and either you need description of each symbol or choose same way for all and just “print”.
With pressing OK, the program bring the follow screen:
As you can see, each glyph is same size(about). But as I mention in the beginning the height must be 8px or any other as 16,24,32.. My intend here is to bring it to 16px. So, let`s resize it little by removing pixel row from top and bottom.
If you set up and down to -1px , remember to click on some character`s New size cell and all will accept the new value.
After we are ready, and in the bottom corner new font size is presented as W15 x H16px font, we can test and export.
But before to try that must be done some additional extra settings.
Go to “OPTIONS” menu and select “Conversion”. Then you drop on that screen:
Select “Prepare” -> “Scanning” and mark [v] Use custom script (1). In the blank field you will add that code:
var page = 0; var x = 0; var y = 7; for(var k=0; k < image.height*image.width; k++){ image.addPoint(x,(page*8)+y); y--; if(y < 0){ y = 7; x++; if(x >= image.width){ x = 0; page++; } } }
Next few settings please do as follow:
Now, do you remember the template from the beginning? Good! Copy the code into file, for example “my_font_template” and put the extension “tmpl”. Im my case that is “font.tmpl”
And as last setting, we need to select it that the export file will be created exactly with content we like to be:
Under mark 1 is our font export template,but all settings what have been done can be saved under some name (pos 2 and 3).
Almost ready to export. But hey, what about small preview how that font will appear?
No problem : open the following website: http://javl.github.io/image2cpp/
Again from the LCD software, select in the settings window “Show Preview” (1)(2) , select character (3) , and then in window (3) you get the code:
Mark that HEX data and got to the website that I just mention. There paste it in field (1):
Mark 15 as width, 16 as height (position 2) , and choose vertical reading. The image should be seen in position 4!
If you see proper character then all went good. Let`s export them characters..But before that, confirm on the settings dialog that you wish to save the changes.
On the opening dialog for that example my file will be : Your_Font_Name_Here.h And it content like that:
/* * -------------------------------------------------------------------- * generated by lcd-image-converter rev.129188f from 2019-07-09 00:20:51 +0500 * font * filename: unsaved * name: Your_Font_Name_Here * included characters: !"#$%&'()*+,-./0123456789:;<=>?x0040ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~ * unicode bom: no * * preset name: My-Settings-2pages-MONOCHROME * data block size: 8 bit(s), uint8_t * RLE compression enabled: no * conversion type: Monochrome, Diffuse Dither 128 * bits per pixel: 1 *-------------------------------------------------------------------------- */ // ---------------------------------------------------------------------------- #include <avr/pgmspace.h> // ---------------------------------------------------------------------------- const uint8_t Your_Font_Name_Here_bitmap [] PROGMEM = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x20 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x37, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x21 - ! 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x22 - " 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0xe0, 0x58, 0x40, 0xe0, 0x58, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x34, 0x0e, 0x05, 0x34, 0x0e, 0x05, 0x04, 0x00, 0x00, 0x00, 0x00, // 0x23 - # 0x00, 0x00, 0x00, 0x00, 0xe0, 0x10, 0x10, 0xfc, 0x10, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x21, 0x21, 0xff, 0x22, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x24 - $ 0x00, 0xf0, 0x08, 0x08, 0x08, 0xf0, 0x00, 0x00, 0xc0, 0x30, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x21, 0x18, 0x04, 0x03, 0x00, 0x1e, 0x21, 0x21, 0x21, 0x1e, 0x00, // 0x25 - % 0x00, 0x00, 0x00, 0x70, 0x88, 0x08, 0x88, 0x70, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x21, 0x21, 0x21, 0x22, 0x24, 0x18, 0x17, 0x20, 0x00, 0x00, 0x00, 0x00, // 0x26 - & 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x27 - ' 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x30, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x60, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x28 - ( 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x08, 0x30, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x60, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x29 - ) 0x00, 0x00, 0x00, 0x00, 0x88, 0x50, 0x20, 0xfc, 0x20, 0x50, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x2a - * 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x3f, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, // 0x2b - + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x2c - , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x2d - - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x2e - . 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x38, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x70, 0x0e, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x2f - / 0x00, 0x00, 0x00, 0xe0, 0x10, 0x08, 0x08, 0x08, 0x10, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x10, 0x20, 0x20, 0x20, 0x10, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x30 - 0 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x3f, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x31 - 1 0x00, 0x00, 0x00, 0x00, 0x10, 0x08, 0x08, 0x08, 0x10, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x28, 0x24, 0x22, 0x21, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x32 - 2 0x00, 0x00, 0x00, 0x10, 0x08, 0x08, 0x08, 0x08, 0x90, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x20, 0x21, 0x21, 0x21, 0x12, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x33 - 3 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x20, 0x10, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x02, 0x02, 0x02, 0x02, 0x3f, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x34 - 4 0x00, 0x00, 0x00, 0xf8, 0x88, 0x88, 0x88, 0x88, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x20, 0x20, 0x20, 0x20, 0x11, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x35 - 5 0x00, 0x00, 0x00, 0xc0, 0xb0, 0x90, 0x88, 0x88, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x10, 0x20, 0x20, 0x20, 0x11, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x36 - 6 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x88, 0x68, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x18, 0x06, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x37 - 7 0x00, 0x00, 0x00, 0x60, 0x90, 0x08, 0x08, 0x08, 0x90, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x12, 0x21, 0x21, 0x21, 0x12, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x38 - 8 0x00, 0x00, 0x00, 0xe0, 0x10, 0x08, 0x08, 0x08, 0x10, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x22, 0x22, 0x12, 0x1a, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x39 - 9 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x3a - : 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x3b - ; 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x40, 0x40, 0x20, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x02, 0x04, 0x04, 0x08, 0x08, 0x10, 0x00, 0x00, 0x00, 0x00, // 0x3c - < 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, // 0x3d - = 0x00, 0x00, 0x00, 0x00, 0x10, 0x20, 0x20, 0x40, 0x40, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x08, 0x08, 0x04, 0x04, 0x02, 0x02, 0x01, 0x00, 0x00, 0x00, // 0x3e - > 0x00, 0x00, 0x00, 0x00, 0x10, 0x08, 0x08, 0x08, 0x88, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x3f - ? 0x00, 0x80, 0x60, 0x10, 0x10, 0x88, 0x48, 0x48, 0x48, 0xc8, 0x10, 0x20, 0xc0, 0x00, 0x00, 0x00, 0x0f, 0x30, 0x40, 0x4f, 0x90, 0x90, 0x90, 0x90, 0x9f, 0x10, 0x10, 0x0f, 0x00, 0x00, // 0x40 - @ 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x18, 0x18, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x0e, 0x05, 0x04, 0x04, 0x05, 0x0e, 0x30, 0x00, 0x00, 0x00, 0x00, // 0x41 - A 0x00, 0x00, 0x00, 0xf8, 0x88, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x20, 0x20, 0x20, 0x20, 0x20, 0x11, 0x0e, 0x00, 0x00, 0x00, 0x00, // 0x42 - B 0x00, 0x00, 0x00, 0xc0, 0x30, 0x10, 0x08, 0x08, 0x08, 0x08, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x18, 0x10, 0x20, 0x20, 0x20, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, // 0x43 - C 0x00, 0x00, 0xf8, 0x08, 0x08, 0x08, 0x08, 0x08, 0x10, 0x30, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x20, 0x20, 0x20, 0x20, 0x20, 0x10, 0x18, 0x07, 0x00, 0x00, 0x00, 0x00, // 0x44 - D 0x00, 0x00, 0x00, 0xf8, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x45 - E 0x00, 0x00, 0x00, 0xf8, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x46 - F 0x00, 0x00, 0xc0, 0x30, 0x10, 0x08, 0x08, 0x08, 0x08, 0x08, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x18, 0x10, 0x20, 0x20, 0x21, 0x21, 0x21, 0x1f, 0x00, 0x00, 0x00, 0x00, // 0x47 - G 0x00, 0x00, 0xf8, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, // 0x48 - H 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0xf8, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x3f, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x49 - I 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x20, 0x20, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x4a - J 0x00, 0x00, 0x00, 0xf8, 0x00, 0x80, 0x40, 0x20, 0x10, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x01, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x00, 0x00, 0x00, 0x00, // 0x4b - K 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x4c - L 0x00, 0xf8, 0x08, 0x30, 0xc0, 0x00, 0x00, 0x00, 0xc0, 0x30, 0x08, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x03, 0x04, 0x03, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, // 0x4d - M 0x00, 0x00, 0xf8, 0x10, 0x20, 0xc0, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x01, 0x02, 0x0c, 0x10, 0x3f, 0x00, 0x00, 0x00, 0x00, // 0x4e - N 0x00, 0x00, 0xc0, 0x30, 0x10, 0x08, 0x08, 0x08, 0x08, 0x10, 0x30, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x18, 0x10, 0x20, 0x20, 0x20, 0x20, 0x10, 0x18, 0x07, 0x00, 0x00, 0x00, // 0x4f - O 0x00, 0x00, 0x00, 0xf8, 0x08, 0x08, 0x08, 0x08, 0x10, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x02, 0x02, 0x02, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x50 - P 0x00, 0x00, 0xc0, 0x30, 0x10, 0x08, 0x08, 0x08, 0x08, 0x10, 0x30, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x18, 0x10, 0x20, 0x20, 0xe0, 0x20, 0x10, 0x18, 0x07, 0x00, 0x00, 0x00, // 0x51 - Q 0x00, 0x00, 0x00, 0xf8, 0x08, 0x08, 0x08, 0x08, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x02, 0x02, 0x02, 0x05, 0x08, 0x10, 0x20, 0x00, 0x00, 0x00, 0x00, // 0x52 - R 0x00, 0x00, 0x00, 0x60, 0x90, 0x08, 0x08, 0x08, 0x08, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x20, 0x21, 0x21, 0x21, 0x12, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x53 - S 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0xf8, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x54 - T 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x10, 0x20, 0x20, 0x20, 0x20, 0x20, 0x10, 0x0f, 0x00, 0x00, 0x00, 0x00, // 0x55 - U 0x00, 0x00, 0x00, 0x18, 0xe0, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x38, 0x38, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x56 - V 0x18, 0xe0, 0x00, 0x00, 0x00, 0xf0, 0x08, 0xf0, 0x00, 0x00, 0x00, 0xe0, 0x18, 0x00, 0x00, 0x00, 0x01, 0x1e, 0x30, 0x0f, 0x00, 0x00, 0x00, 0x0f, 0x30, 0x1e, 0x01, 0x00, 0x00, 0x00, // 0x57 - W 0x00, 0x00, 0x00, 0x08, 0x30, 0x40, 0x80, 0x80, 0x40, 0x30, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x18, 0x04, 0x03, 0x03, 0x04, 0x18, 0x20, 0x00, 0x00, 0x00, 0x00, // 0x58 - X 0x00, 0x00, 0x08, 0x10, 0x60, 0x80, 0x00, 0x80, 0x60, 0x10, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x59 - Y 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0xc8, 0x28, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x28, 0x26, 0x21, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x5a - Z 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x5b - [ 0x00, 0x00, 0x00, 0x00, 0x0c, 0x30, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x0e, 0x70, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x5c - 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x5d - ] 0x00, 0x00, 0x00, 0x80, 0x40, 0x20, 0x10, 0x08, 0x10, 0x20, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x5e - ^ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, // 0x5f - _ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x60 - ` 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x40, 0x40, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x24, 0x22, 0x22, 0x22, 0x12, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x61 - a 0x00, 0x00, 0x00, 0xfc, 0x80, 0x40, 0x40, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x20, 0x20, 0x20, 0x20, 0x10, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x62 - b 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x40, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x10, 0x20, 0x20, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x63 - c 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x40, 0x40, 0x40, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x10, 0x20, 0x20, 0x20, 0x10, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x64 - d 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x40, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x12, 0x22, 0x22, 0x22, 0x22, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x65 - e 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0xf8, 0x44, 0x44, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x66 - f 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x40, 0x40, 0x40, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x90, 0x20, 0x20, 0x20, 0x90, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x67 - g 0x00, 0x00, 0x00, 0xfc, 0x80, 0x40, 0x40, 0x40, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x68 - h 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x69 - i 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0xc8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x6a - j 0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x80, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x02, 0x05, 0x08, 0x10, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x6b - k 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x6c - l 0x00, 0x00, 0xc0, 0x80, 0x40, 0x40, 0x40, 0x80, 0x80, 0x40, 0x40, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, // 0x6d - m 0x00, 0x00, 0x00, 0xc0, 0x80, 0x40, 0x40, 0x40, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x6e - n 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x40, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x10, 0x20, 0x20, 0x20, 0x10, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x6f - o 0x00, 0x00, 0x00, 0xc0, 0x80, 0x40, 0x40, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x20, 0x20, 0x20, 0x20, 0x10, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x70 - p 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x40, 0x40, 0x40, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x10, 0x20, 0x20, 0x20, 0x10, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x71 - q 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x80, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x72 - r 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x40, 0x40, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x22, 0x22, 0x24, 0x24, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x73 - s 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0xf0, 0x40, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x74 - t 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x20, 0x20, 0x20, 0x20, 0x10, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x75 - u 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0c, 0x30, 0x0c, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x76 - v 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x0e, 0x38, 0x07, 0x00, 0x07, 0x38, 0x0e, 0x01, 0x00, 0x00, 0x00, 0x00, // 0x77 - w 0x00, 0x00, 0x00, 0x40, 0x80, 0x00, 0x00, 0x00, 0x80, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x10, 0x09, 0x06, 0x09, 0x10, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x78 - x 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x8c, 0x70, 0x0c, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x79 - y 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x28, 0x24, 0x22, 0x21, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x7a - z 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x7b - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x7c - | 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfd, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x7d - } 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x04, 0x03, 0x00, 0x00, 0x00, // 0x7e - ~ }; const DCfont Your_Font_Name_Here = { (uint8_t *)Your_Font_Name_Here_bitmap, XX, // character width in pixels, write correct one 15, // character height in pages (8 pixels per page) so correct that one 0x20,0x7e // ASCII extents like 48,52 <-start , end - that cover full space to ~ array };
Now what? Well.. you need to set few more things.. before use that new font. First is to give the right character width and the height in pages. In our case is 15px width and 2 pages (16/8px) height. Then the right starting and ending character HEX code. In other words, for the upper code it will be the following bottom :
const DCfont Your_Font_Name_Here = {
(uint8_t *)Your_Font_Name_Here_bitmap,
15, // character width in pixels, write correct one
2, // character height in pages (8 pixels per page) so correct that one
0×20,0×7e // ASCII extents
};
Last two HEX bytes represent the first and last character code in our array. For example if you decide to create only numeric array with few symbols like that one: +,-./0123456789: , then you have:
* some bytes * // 0×2b - +
* some bytes * // 0×2c - ,
* some bytes * // 0×2d - -
* some bytes * // 0×2e - .
* some bytes * // 0×2f - /
* some bytes * // 0×30 - 0
* some bytes * // 0×31 - 1
* some bytes * // 0×32 - 2
* some bytes * // 0×33 - 3
* some bytes * // 0×34 - 4
* some bytes * // 0×35 - 5
* some bytes * // 0×36 - 6
* some bytes * // 0×37 - 7
* some bytes * // 0×38 - 8
* some bytes * // 0×39 - 9
* some bytes * // 0×3a - :
and our end will be:
const DCfont Your_Font_Name_Here = {
(uint8_t *)Your_Font_Name_Here_bitmap,
15, // character width in pixels, write correct one
2, // character height in pages (8 pixels per page) so correct that one
0×2b, 0×3a // ASCII extents
};
REMEMBER!!! you can`t skip character. For example, if you create array as 0-1-2-6-7-8 and then expect starting to be
// 0×30 - 0 , and end // 0×38 - 8 and to work correctly..
If you need character that is to the end of the table just “draw” (copy the HEX code) into some of the beginning.
In the video I create instead simple dot : “.” , whole clock glyph and in the code when I “print” dot it show the clock..
Now, example. Create new arduino file and put inside the follow code:
#include <Tiny4kOLED.h> #include <TinyWireM.h> #include "Your_Font_Name_Here.h" void setup() { oled.begin(); oled.clear(); oled.on(); oled.setFont(&Your_Font_Name_Here); oled.setCursor(0,0); oled.print("ABCD..XYZ"); oled.setCursor(10,1); oled.print("-123.568"); for(int demo = 10; demo < 30; demo++){ oled.setCursor(5,2); oled.print(demo); delay(250); } } void loop(){ }
Of course, I presume you already install that libraries I mention in the beginig.
Remember our created “Your_Font_Name_Here.h” file? You need to add it in the same folder as your arduino file you just create and give it a try.
The files from the video can be obtained here: demo files
BITMAPS and how to show them:
Well, that`s one idea slow process. If you wish to print 32px in height bitmap you have to modify the code of the library (seems it must be taken the same part as printing glyph) , print it like font (actually quite easy solution, remember the clock glyph) or to slice it in 4 pieces and then convert it using the follow script:
Then press “Show preview” and try the code in the website:
The test flash logo bitmap file is included in demo files. Inside the code you`ll find the follow row:
int position_x = 10; //<- how many pixels from max left X0 to the image start..
Try to change the position from 10 to 48 for example. That number is used as second position when the logo appear second time in the video.
Well.. that was all. Hope you find it usefull.. Thanks for reading!