Update SSD1306 library supporting bigger font

128 views
Skip to first unread message

rob...@hotmail.com

unread,
Sep 21, 2025, 7:38:05 AM9/21/25
to jallib
Hi Bill,

It took me quite some time to figure this out. First of all, you cannot read data from the SSD1306. This means that I cannot write characters using pixels.

So I looked at the procedure ssd1306_write_char() which writes ... characters. This procedure does not require the big cache that you normally need when writing characters as pixels or when using graphics in general.

Currently the SSD1306 library worked correctly for the 6x8 font and that was only because that is a vertical font and that matches how the SSD1306 displays the data. This seems to be one of the view (or the only?) vertical font, all other - larger - fonts are horizontal fonts and that causes the problem when using them.

So I added code to this procedure that checks if the used font is a horizontal font and if so it rotates the character 90 degrees to match the SSD1306 display and splits the character up into smaller pieces since the SSD1306 works with pages (0..7) each 8 pixels high. If a font is bigger than 8 pixels, it needs to be spit up and divided over 2 pages. 

I attached the library including a picture that shows the 12x16 font working. I still need to test this for other font sizes and I need to clean the library up since currently the limit is 12x16 and if you use a smaller font I could save data space. So please give it try. You do not need any special setting for this only that you are using text mode. 

Next to cleaning the library up I am planning to move the IIC and SPI part from this library to the main program so that it is not included by this library anymore. This is in line with the JAL style guide but it results in a breaking change for anyone who is currently using the library since incuding IIC or SPI and initializing them moves to the main program. 

Kind regards,

Rob

glcd_ssd1306.jal
P1070762.JPG

Bill Beek

unread,
Sep 22, 2025, 6:26:24 AM9/22/25
to jallib

Hi Rob,
I tested the lib but the same problem exist.
I added your name at the lib to be sure that the right lib was used.
You can see what's happens on the picture.
I can't understand what I have done wrong so I added my program.

Kind regards, Bill.
18F2520_1306_OLED.jal
IMG_20250922_121150.jpg

Rob CJ

unread,
Sep 22, 2025, 1:02:08 PM9/22/25
to jallib
Hi Bill,

The only thing I found is that you include and initialize i2c_hardware. As you may remember this is currently also done by the ssd1306 and I am not sure if this messes things up so I commented that part out. I also commented out the include of glcd_common since that is needed by the ssd1306 library so it is included there. I also moved the selection of the font but that should not make a difference. I attached the update.

For the final version of the updated library you have to include and initialize i2c_hardware but not yet for this version.

So it should work but not sure if the I2c_hardware has messed things up (I do not think so).

Unfortunately I do not have an 18F2520  to test it. 

I see you have two devices on the IIC bus. Did you also test with without the INA3221?

And to be sure. Although the module works at +5V you should not pull-up the SDA and SCL lines to +5Volt. If you have connected both the INA3221 and the SSD1306 to +5V, the INA3221 will pull-up the lines to +5V and that can kill the module. Last but not least. As I mentioned before the SSD1306 module generates a lot of noise on the SDA and SCL lines and that is gone if you use it on 3.3 Volt.

So for this test. Only connect the SSD1306 and use it (including the PIC) at 3.3 Volt and see if that works. If that is the case and you want to use it together with the INA3221 at +5V then use a level shifter between the PIC and the SSD1306.

BTW. I do not see any power connection to the SDD1306 🙂.

Kind regards,

Rob




Van: jal...@googlegroups.com <jal...@googlegroups.com> namens Bill Beek <bill...@gmail.com>
Verzonden: maandag 22 september 2025 12:26
Aan: jallib <jal...@googlegroups.com>
Onderwerp: [jallib] Re: Update SSD1306 library supporting bigger font
 
--
You received this message because you are subscribed to the Google Groups "jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jallib+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/jallib/5f33c130-d73d-4080-b8c4-03900fba52a9n%40googlegroups.com.
18F2520_1306_OLED.jal

Bill Beek

unread,
Sep 22, 2025, 2:15:03 PM9/22/25
to jallib
Hi Rob,
Tested without the ina3221, delete the I2C code lines from the program and Vcc 3,3V but nothing changed.
So I wondered if it's possible that the lib you posted is not the same as in your test? 
The 1306 is powered by wires under the board. 
Kind regards, Bill.

Bill Beek

unread,
Sep 23, 2025, 11:25:07 AM9/23/25
to jallib
Hi Rob,
Some extra information about the topic.
I tested also with a 18f1825 and sw I2C and as expected, got the same image as in the photo I posted.
If the 6x8 font is used, everything works well even with the 18f2520, which is equipped  with the tiny bootloader                                            which works handy and fast for me. 
The 16F1825 is programmed with the pickit 2. I hope that you are able to locate the problem.                                                                                                                                                                                                                                                                                                                                    Kind regards, Bill.  

Rob CJ

unread,
Sep 23, 2025, 12:34:28 PM9/23/25
to jallib
Hi Bill,

I cannot explain this. I will do some more testing and also test it with the SPI interface.

Did you try it without any other connections to the IIC bus and at 3.3. Volt?

Kind regards,

Rob


Verzonden: dinsdag 23 september 2025 17:25
Aan: jallib <jal...@googlegroups.com>
Onderwerp: Re: [jallib] Re: Update SSD1306 library supporting bigger font
 

Bill Beek

unread,
Sep 23, 2025, 1:25:46 PM9/23/25
to jallib
Hi Rob,
Only the display on IC2 and 3.3V I don't  understand it either, are you sure that the posted lib is the same as in your test?
That could explain the problem.

Bill Beek

unread,
Sep 23, 2025, 1:29:49 PM9/23/25
to jallib
P.S. send me the hex file for the 18F1825 so i can see of that is okay with my setting.

Rob CJ

unread,
Sep 24, 2025, 1:01:50 PM9/24/25
to jallib
Hi Bill,

Attached the JAL testprogram I used and the hex file.

Kind regards,

Rob


Verzonden: dinsdag 23 september 2025 19:29
16f1825_glcd_ssd1306_test_font.hex
16f1825_glcd_ssd1306_test_font.jal

Bill Beek

unread,
Sep 24, 2025, 1:49:50 PM9/24/25
to jallib

Hi Rob,

The 12x16 font now works fine, the error was on my side, the hex file worked fine as expected.

After compilation of your program it went wrong again.

 After investigation, the glcd_font lib turned out to be corrupted, so I apologize for the inconvenience.

I have looked at the I2C lines, and also see that interference signals are

getting bigger as the voltage increases between 3 and 5 Volts.

What I also noticed was that the pulses were not very steep,

which is of course due to by the weak pullups.

After placing 2 x 4k7 resistors it looked much better and realized a more stable data transfer.

I noticed that the display regularly fails at 5V, after placing the resistors everything worked well at 5 Volts.

According to my info there is some kind of voltage regulator on the display board which would make it applicable from 3 to 5 Volt.

Many thanks for the good work,

Kind regards, Bill.


Rob CJ

unread,
Sep 25, 2025, 1:05:31 PM9/25/25
to jallib
Hi Bill,

Good to hear that it works. As I mentioned before the IC on the module operates at 3.3 Volts and the pins are not 5 Volt tollerant so be careful with that.

Today I tested the library with all available JAL fonts and they - after some smalle modifications to the library - all work  now. I also moved the IIC and SPI part out of the library and moved that to the main program. The library checks which interface (I2C software, I2C hardware, I2C harware 2, SPI hardware and SPI hardware 2) is included by the main program and uses that interface automagically. The only setting that remains for the interface is the SPI software, for all others interfaces it is just including the required interface before including the ssd1306 library and it will then use that interface for the communication with SSD1306 module.

I added a text with a bigger font to the current sample programs so that users can see that that works too. It works for I2C but I still need to test it for SPI as wel. If all works then I will upload the updated library and the updated sample programs.

Good luck with the project. I think this was a nice extension of the functionality of this library.

Kind regards,

Rob


Verzonden: woensdag 24 september 2025 19:49

Rob CJ

unread,
Sep 25, 2025, 3:48:13 PM9/25/25
to jallib
Hi Bill.

FYI. I finished the update of the glcd_ssd1306 library and the sample files. Tested it with all JAL Fonts using I2C and SPI and all seem to work fine.

I uploaded it to GitHub so it should be in the bee package of the upcoming weekend.

Since the version you have works for the 12x16 font it did not yet work for all available JAL fonts but that has been fixed. As said before, the IIC and SPI libraries now need to be included by the main program as to make the library compliant with the JAL style guide. It now also gives more flexibilty since you can now also use SPI 2 and I2C 2 if you needed that but it is a breaking change with the previous version of the library. Examples are given in de sample files.

Kind regards,

Rob


Van: jal...@googlegroups.com <jal...@googlegroups.com> namens Rob CJ <rob...@hotmail.com>
Verzonden: donderdag 25 september 2025 19:05

Bill Beek

unread,
Jan 13, 2026, 2:24:30 PM (10 days ago) Jan 13
to jallib

Hi Rob,

I tried to make the SSD1306 library suitable for the SH1106, but it won’t work.

Addressing the memory is different, with line, page and column addresses.

Because I don’t fully understand the 1306 lib, it is difficult for me to make it work.

Maybe you want to look at the data sheet to make some suggestions.

I send the lib along. I deleted the SPI and scroll functions to keep it simple.

Thank you in advance, and best wishes for 2026 to the group.

Bill.

glcd_sh1106.jal

Rob CJ

unread,
Jan 14, 2026, 12:57:06 PM (9 days ago) Jan 14
to jallib
Hi Bill,

That may take some time because those datasheets are not always that clear, especially Chinese ones.

Have you looked at an Arduino library for this display? That often gives an idea about how things should work. I know for example that I could never have written the library for the ili9341LCD without some info I got from the Arduino library and I still wonder how they figured out certain settings while the documentation did not give any clue on that.

Is nothing working or are certain things not working?

Kind regards,

Rob




Verzonden: dinsdag 13 januari 2026 20:24

Bill Beek

unread,
Jan 14, 2026, 2:43:38 PM (9 days ago) Jan 14
to jallib

Hi Rob,

Not working at all, see picture. I studied several arduino libs but that didn't give me a solution.

While the programmers write, that it is a small modification of the SSD1306, I don't see it.

 When I use the 1306 with this lib, the first line written from right to left with the text in mirrored image.

Kind regards, Bill.
20260114_203937.jpg
20260114_201623_001.jpg

Rob CJ

unread,
Jan 15, 2026, 12:08:03 PM (8 days ago) Jan 15
to jal...@googlegroups.com
Hi Bill,

First quick analisys starting at the intialize routine. You start a transmission and then you send bytes but it does not work that way since the device has various registers and it needs to know to which register you are addressing. Instead you better call the procedure that start a transmission, sends the command and the data and stops the transmission.

For example for setting the contrast. You use the following at the initialization after you have sent other data too:
_sh1106_write_byte(_sh1106_SET_CONTRAST)
_sh1106_write_byte(0x9F) -- A = 0x9F or 0xCF P = 0xAF

But you should send the contrast command (control byte) followed by the contrast data in each transmission like in the procedure set_contrast()
_sh1106_start_transmission(_sh1106_COMMAND_TRANSMISSION)
_sh1106_write_byte(_sh1106_SET_CONTRAST)
_sh1106_write_byte(contrast)
_sh1106_stop_transmission()

I noticed you based this on an olderversion of the ssd1306 library. In the newer version I removed the  include of the IIC library which has to be done by the main program (as it should according to the JAL style guide).

I hope this helps for the first step.

Kind regards,

Rob




Verzonden: woensdag 14 januari 2026 20:43
You received this message because you are subscribed to a topic in the Google Groups "jallib" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jallib/JdXGKBOcq1A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jallib+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/jallib/7947f9c7-ce70-4f06-ac3a-242c11b0a3f9n%40googlegroups.com.

Rob CJ

unread,
Jan 15, 2026, 4:24:37 PM (8 days ago) Jan 15
to jal...@googlegroups.com
Hi Bill,

Update. I looked at the attached Arduino library and they send a lot of commands during initialization like yoiu do using the procedure sh1106_command(). This procedure is as follows for IIC:

void Adafruit_SH1106::SH1106_command(uint8_t c) {
// I2C
uint8_t control = 0x00; // Co = 0, D/C = 0
Wire.beginTransmission(_i2caddr);
WIRE_WRITE(control);
WIRE_WRITE(c);
Wire.endTransmission();
}

So they send all data starting with a transmission of zero. I cannot find in the documentation why that works but maybe it does.

Kind regards,

Rob


Verzonden: donderdag 15 januari 2026 18:07
Aan: jal...@googlegroups.com <jal...@googlegroups.com>
Adafruit_SH1106.cpp

Bill Beek

unread,
Jan 16, 2026, 2:30:34 PM (7 days ago) Jan 16
to jallib
Hi Rob,
Thank you for the information.

As far as sending a 0x00 prior to the command transmission was concerned,

 I thought the procedure "_sh1106_start_transmission" took care of that.

Also I did try to add an extra write _byte(0x00) in the send_command procedure.

But nothing changed. If it's too much work for you to look in to it further, it's no problem.

I will try further  to understand several libraries, but i am not very good in the C coding.

Thank you for your effort.

Kind regards, Bill.

Rob CJ

unread,
Jan 17, 2026, 3:28:48 AM (7 days ago) Jan 17
to jallib
Hi Bill,

I heard and read that the control should - almost - be the same as for the SSD1306. I must say that I like it that this display is a bit bigger than the SSD1306 so I ordered an IIC and SPI version. If you can wait for some time I will make an sh1106 library and get it working.

Kind regards,

Rob


Verzonden: vrijdag 16 januari 2026 20:30

Rob CJ

unread,
Jan 17, 2026, 7:19:29 AM (6 days ago) Jan 17
to jal...@googlegroups.com
Hi Bill,

I created an intitial version of the sh1106 library and based it on the ssd1306 library. I made some changes:
  1. Functional. In the initialization I send the list of commands in a different order according to some other libraries that I saw.
  2. Not functional. I removed all function prototypes at the start of the library since it is more or less duplication.

I did not test this, only compiled it with the attached sample program.

You can give it a try to see if it works.

Kind regards,

Rob


Verzonden: zaterdag 17 januari 2026 09:28
16f1825_glcd_sh1106_font.jal
glcd_sh1106.jal

Bill Beek

unread,
Jan 18, 2026, 6:20:39 AM (5 days ago) Jan 18
to jallib

I tested the lib with 1106 and 1306, the 1106 was not all right the

1306 works well.

Then I controlled both displays at the same time and made a video of it.

Maybe you can determine what goes wrong from it.

Kind regards, Bill.



0117 (1)(2).mp4
Message has been deleted

Bill Beek

unread,
Jan 18, 2026, 6:41:21 AM (5 days ago) Jan 18
to jallib
my mistake

0118.mp4

Rob CJ

unread,
Jan 18, 2026, 9:21:23 AM (5 days ago) Jan 18
to jal...@googlegroups.com
Hi Bill,

Are you using both at the same time on the same IIC bus with the same IIC address? That may give problems.

I updated the library and used other initialization settings that I received from the other Rob. They should work both for the ssd1306 as well as for the sh1106.

Kind regards,

Rob


Verzonden: zondag 18 januari 2026 12:41

Aan: jallib <jal...@googlegroups.com>
Onderwerp: Re: [jallib] Re: Update SSD1306 library supporting bigger font
 
my mistake


--
You received this message because you are subscribed to the Google Groups "jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jallib+un...@googlegroups.com.
glcd_sh1106.jal

Bill Beek

unread,
Jan 18, 2026, 9:45:30 AM (5 days ago) Jan 18
to jallib
Hi Rob,
Only for the video together, when used 
separately the same results on the display
  

Bill Beek

unread,
Jan 18, 2026, 10:15:54 AM (5 days ago) Jan 18
to jallib
The latest lib make it worst, both displays are now up side down.
And the 1306 is now messy and the 1106 behavior is further unchanged.
Kind regards, Bill.

Rob CJ

unread,
Jan 18, 2026, 10:28:09 AM (5 days ago) Jan 18
to jal...@googlegroups.com
Hi Bill,

OK. These where settings that supposed to work for both. I will do some more research and will test it first myself before sending an update.

Kind regards,

Rob


Verzonden: zondag 18 januari 2026 16:15

Rob CJ

unread,
Jan 19, 2026, 12:58:17 PM (4 days ago) Jan 19
to jal...@googlegroups.com
Hi Bill,

I had a detailed look at the datasheet of the SH1106 and saw that setting the device on a certain position works differently so I changed that. This way of positioning the device uses a page addressing mode. This mode is also available in the SSD1306 but there the library uses horizontal addressing mode and so a different method is used. You can also select the page addressing mode on the SSD1306 and then the same approach is used as in the SH1106.

Not sure if this solves all problems but this version will not work on the SSD1306 since the command to select the addressing mode is not present in the SH1106 so I removed that command in total to prevent any side effects. In the future it might be possible to make one library for both (maybe with a 'define') but maybe it is better to keep them separate otherwise the library name should change to glcd_ssd1306_sh1106. 

If this does not work then you have to wait until I can test it myself.

Kind regards,

Rob




Van: jal...@googlegroups.com <jal...@googlegroups.com> namens Rob CJ <rob...@hotmail.com>
Verzonden: zondag 18 januari 2026 16:28
Aan: jal...@googlegroups.com <jal...@googlegroups.com>
glcd_sh1106.jal

Bill Beek

unread,
Jan 20, 2026, 10:33:27 AM (3 days ago) Jan 20
to jallib

Hi Rob,

You're on the right track, that addressing also gave me some problems to figure out.

I'll send some pictures so you can see what's happening on the display.

The "8" at the bottom left has been moved 1 position so that the full character is visible.

 That is not a big problem. Only the vertical scrolling functions work, the horizontal and

vertical ones don't.

And of course the unwanted pixels are the problem as far as I've been able to discover,

as you can see in the pictures.

Kind regards, Bill.

20260120_154636.jpg
20260120_155545.jpg
20260120_155423.jpg
20260120_155407.jpg

Bill Beek

unread,
Jan 20, 2026, 10:37:53 AM (3 days ago) Jan 20
to jallib
I meant Horizontal and diagonal scrolling.

Rob CJ

unread,
Jan 20, 2026, 12:47:41 PM (3 days ago) Jan 20
to jal...@googlegroups.com
Hi Bill,

Thanks for the info. I expect the LCD's to arrive soon so I can test it myself.

Strange all those random pixels (I assume after clear display. It may be that the shift 1 pixel to the left may be caused by the fact that this controller support 132x64 while the SSD1306 supports 128x64 and I still used 128x64 in this library but I will test that too. I head something similar from Rob Hamerling to add an offset.

I noticed when testing the SSD1306 library that some scrolling funtionality only worked for the version with SPI and not IIC. I do not know why that is.

As soon as I get it all working I will send you an update.

Kind regards,

Rob




Verzonden: dinsdag 20 januari 2026 16:37

Bill Beek

unread,
Jan 21, 2026, 2:25:54 PM (2 days ago) Jan 21
to jallib

Hello Rob,

It seems that the memory is not completely erased by the clear_screen procedure.

I made a work around that overwriting all 8 lines of text with spaces,

so that the unwanted pixels disappear.

Furthermore, I saw that only the 5x7 and the 6x8 fonts works, the larger one doesn't.

It's hard not to be able to test with the right display, so for now I'm waiting to see

what you can discover.

Kind regards, Bill.

Rob CJ

unread,
Jan 22, 2026, 12:51:46 PM (yesterday) Jan 22
to jallib
Hi Bill,

Good to know. 

About the fonts. The two fonts you mentioned are vertical oriented fonts like the display. The larger fonts are most likely horizontal fonts for which extra code is in the library to rotate this but it needs a character buffer for that. 

If you want to use the larger fonts you have to increase that character buffer as described in the library, see info below. In the SSD1306 I made this character buffer as large as was needed for the biggest fonts we currently have but if you do not use such a big font, it is waste of data space. In the SH1106 library I have set this buffer to the minimum of 1 so for each horizontal font you use (which are the larger fonts) you have to increase this size. I also changed this for the SSD1306 library - so that you know - but I did not upload that since I first want to see what comes out of testing the SH1106 library,


-- When using a horizontal oriented character font, a character buffer
-- is needed with the size of the used font, see the font library value
-- FONT_xxxx_BYTE_PER_CHAR for the font you are using.
-- The default size of this buffer is set to the minimum value of 1.
-- For example the 12x16 horizontal font uses 32 bytes for one character
-- and so we can set the character buffer to this size by:
-- -) const SH1106_CHAR_BUFFER_SIZE = 32
-- No buffer is required for vertical oriented fonts. For vertical fonts
-- only fonts with a maximum height of 8 pixels are supported.

Kind regards,

Rob




Verzonden: woensdag 21 januari 2026 20:25

Rob CJ

unread,
12:50 PM (4 hours ago) 12:50 PM
to jallib
Hi Bill,

Today I received the displays and I tested the I2C version and it worked! I had of course the same issue with the characters on the left that where cut off.

Attached you find an update of the library and a sample program. I made the following changes:
  1. Fixed the pixel shift no now the '8' are positioned correctly
  2. Removed the horizontal scroll procedures and diagonal scroll procedures since the SH1106 does not support that.

The big font was also working but make sure you increase the character buffer as shown in the sample program since the default size is 1 byte which is insufficient.

Then about your random pixels. I did not have them and I think I know why. When I used an ssd1306 in the past I also had random pixels. I saw on an osciloscope that the SSD1306 module generated a lot of noice on the IIC lines. This is also the case for the SH1106. The problem occurs when you use the module and the PIC both on 5Volt because the SH1106 operates at 3.3 Volt and so the I2C signals do not have a full swing to +5Volt and the noise is so high that it disturbs those signals changing a 1 into a 0 and the other way around. I solved this in the past by operating both the SSD1306 and the PIC at 3.3 Volt so that the whole level swing is used and that is also the set-up I used today for the SH1106. I had no random pixels in this set-up.

So you have two options:
  1. Operate both devices at 3.3. Volt
  2. Use a level shifter between the PIC and the SH1106 if you want your PIC to run at 5Volt.

If you look at the datasheet of both the SSD1306 and the SH1106 the inputs do not seem 5Volt tolerant so I wonder if they break down after some time if you use the PIC at 5Volt but I am not sure if that will occur.

Next test is to see if the SPI version also works correctly.

Last but not least a question (for all JAL users). The device - and the goto function - works for fonts horizontal with pixels but vertical with pages 0..7. I used pages since that is what I also saw in other libraries but it limits where you can place text vertically. I wonder if I should change that so that you can also use pixels for the vertical orientation so that you could position your charaters anywhere vertically and not only on pages 0..7. Do you think that is a feature that would be useful? I need to write additional code for this and if that works it should also be changed for the SSD1306 but this will result in all users that use this library to implement some changes to rearrange the text based on pixels. 

Let me know what you - all - think.

Thanks.

Kind regards,

Rob




Verzonden: donderdag 22 januari 2026 18:51
16f18857_glcd_sh1106_font_graphics.jal
glcd_sh1106.jal
Reply all
Reply to author
Forward
0 new messages