Larger fonts on SSD1306 OLED displays

Showroom for MicroPython related hardware projects.
Target audience: Users wanting to show off their project!
User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Larger fonts on SSD1306 OLED displays

Post by pythoncoder » Mon Aug 31, 2020 6:53 am

You need to use font_to_py.py with the -x option to create horizontally mapped fonts. This shows the options

Code: Select all

$ font_to_py.py --help
Peter Hinch
Index to my micropython libraries.

IHOXOHI
Posts: 119
Joined: Sat Apr 25, 2020 7:31 am

Re: Larger fonts on SSD1306 OLED displays

Post by IHOXOHI » Mon Aug 31, 2020 10:26 am

PERFECT.

So good.

All my respect.
All the best.

IHOXOHI
Posts: 119
Joined: Sat Apr 25, 2020 7:31 am

Re: Larger fonts on SSD1306 OLED displays

Post by IHOXOHI » Sat Oct 17, 2020 11:09 am

Yip,

It works too with an epaper!

WONDERFULL!!!

Thanks.

volkerjaenisch
Posts: 5
Joined: Thu Jun 10, 2021 9:38 pm

Re: Larger fonts on SSD1306 OLED displays

Post by volkerjaenisch » Sun Aug 22, 2021 9:34 pm

Really cool software!

l00p1n6
Posts: 9
Joined: Fri Feb 07, 2020 11:33 pm

Re: Larger fonts on SSD1306 OLED displays

Post by l00p1n6 » Mon Dec 09, 2024 1:01 pm

If someone is still interested in this topic, here is a solution I came up with....

NB: I am using ESP32-WROOM-32, 0.91" OLED 128x32

Code: Select all

from machine import SoftI2C, Pin
import time
import ssd1306

OLED_SCL_PIN = 22  # clock
OLED_SDA_PIN = 21  # data
OLED_WIDTH = 128  # pixels
OLED_HEIGHT = 32  # pixels


def oled_text_scaled(oled, text, x, y, scale, character_width=8, character_height=8):
    # temporary buffer for the text
    width = character_width * len(text)
    height = character_height
    temp_buf = bytearray(width * height)
    temp_fb = ssd1306.framebuf.FrameBuffer(temp_buf, width, height, ssd1306.framebuf.MONO_VLSB)

    # write text to the temporary framebuffer
    temp_fb.text(text, 0, 0, 1)

    # scale and write to the display
    for i in range(width):
        for j in range(height):
            pixel = temp_fb.pixel(i, j)
            if pixel:  # If the pixel is set, draw a larger rectangle
                oled.fill_rect(x + i * scale, y + j * scale, scale, scale, 1)


def main():
    i2c = SoftI2C(scl=Pin(OLED_SCL_PIN), sda=Pin(OLED_SDA_PIN))
    oled = ssd1306.SSD1306_I2C(OLED_WIDTH, OLED_HEIGHT, i2c)

    # no scaling
    oled.fill(0)
    oled.text("ABCDEFGHIJKLMNOP", 0, 0)
    oled.text("abcdefghijklmnop", 0, 8)
    oled.text("0123456789012345", 0, 16)
    oled.text("=!\"#$%&/()?-+*:;", 0, 24)
    oled.show()
    time.sleep(3)

    # 2x
    oled.fill(0)
    oled_text_scaled(oled, "ABCDEFGH", 0, 0, 2)
    oled_text_scaled(oled, "abcdefgh", 0, 16, 2)
    oled.show()
    time.sleep(3)

    # 4x
    oled.fill(0)
    oled_text_scaled(oled, "ABCD", 0, 0, 4)
    oled.show()
    time.sleep(3)


if __name__ == "__main__":
    main()

davef
Posts: 813
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: Larger fonts on SSD1306 OLED displays

Post by davef » Mon Dec 09, 2024 6:57 pm


l00p1n6
Posts: 9
Joined: Fri Feb 07, 2020 11:33 pm

Re: Larger fonts on SSD1306 OLED displays

Post by l00p1n6 » Tue Dec 10, 2024 12:54 pm

davef wrote:
Mon Dec 09, 2024 6:57 pm
I suggest posting this here:
https://github.com/orgs/micropython/dis ... w-and-tell
Done, do you want me to remove the previous post's content and just put a link to the solution on GitHub?

davef
Posts: 813
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: Larger fonts on SSD1306 OLED displays

Post by davef » Tue Dec 10, 2024 7:36 pm

I'd leave it and then that gives two opportunities to find it. Will try your code as reading standard fonts on these OLEDs is difficult.

l00p1n6
Posts: 9
Joined: Fri Feb 07, 2020 11:33 pm

Re: Larger fonts on SSD1306 OLED displays

Post by l00p1n6 » Wed Dec 11, 2024 12:49 pm

davef wrote:
Tue Dec 10, 2024 7:36 pm
I'd leave it and then that gives two opportunities to find it. Will try your code as reading standard fonts on these OLEDs is difficult.
Should be readable at 4x scale ;)

Link to image (cannot embed):
https://ibb.co/XyP2fBY

Post Reply