Page 1 of 3

Larger fonts on SSD1306 OLED displays

Posted: Tue Nov 15, 2016 9:41 am
by pythoncoder
The official driver supports a single 8x8 pixel monospaced font. This extends it to support larger fonts.

A Python3 utility to run on a PC enables arbitrary monospaced and variable pitch fonts in standard formats to be converted to Python source files. This SSD1306 driver enables them to be rendered to the device. Sample Python font files are included. https://github.com/peterhinch/micropyth ... er/SSD1306.

Aside from general use it is intended as a practical demonstrator for a suggested way of handling one bit per pixel fonts in MicroPython. The solution is intended to be device independent and to support the official framebuffer module. The proposal defines the file format, the utility for creating them and suggests device driver design guidelines for their use. Details are here https://github.com/peterhinch/micropyth ... -to-py.git (currently these docs are a work in progress).

Re: Larger fonts on SSD1306 OLED displays

Posted: Tue Nov 15, 2016 10:41 am
by kfricke
Sounds cool! I gave not had any time to look into this. But how about font licences? We must not ignore those!

Re: Larger fonts on SSD1306 OLED displays

Posted: Tue Nov 15, 2016 12:43 pm
by kfricke
Yesterday I did start to rework the display driver from mbirth to work with the current (re-iterated) machine API. Adding the frambuffer support and/or bytearray() backed buffer is next on my list.

Will this automatically enable the use of your recent work in this area? As far as i have gathered by a quick read all of the "font-work" is done on the framebuffer, right?

Re: Larger fonts on SSD1306 OLED displays

Posted: Tue Nov 15, 2016 2:38 pm
by pythoncoder
kfricke wrote:As far as i have gathered by a quick read all of the "font-work" is done on the framebuffer, right?
Yes, it works on the framebuffer's underlying bytearray. But the framebuffer's scroll method is buggy. Owing to the moratorium on PR's I implemented a workround in Python in my SSD1306 driver.

Re font licensing. My code merely converts one file format to another. As far as I'm concerned the user must take responsibility for the legality of the source, but perhaps I should put a warning in my docs. I believe that the example files I provided with the SSD1306 example are appropriately licensed.

Re: Larger fonts on SSD1306 OLED displays

Posted: Sun Jan 27, 2019 12:03 pm
by walterheisenberg
I can't get bigger fonts to work. I (think) have added the correct Pins to ssd1306_setup.py, but it isn't working. I managed to make normal Text and Images (framebuf) work on my OLED.

It is a 128x64 px OLED on a Heltec Wifi ESP32 board.

Here is the modified code in ssd1306_setup.py
---
rstPin = machine.Pin(16, machine.Pin.OUT)
pscl = machine.Pin(15, machine.Pin.OPEN_DRAIN)
psda = machine.Pin(4, machine.Pin.OPEN_DRAIN)
rstPin.value(1)
---
There is a need for the Reset-Pin set to HIGH to make the display work.
What I'm doing wrong?
---------------------------------------------------------------
>>> import writer_demo
Test assumes a 128*64 (w*h) display. Edit WIDTH and HEIGHT in ssd1306_setup.py for others.
Device pinouts are comments in ssd1306_setup.py.
Issue:
writer_demo.test() for an I2C connected device.
writer_demo.test(True) for an SPI connected device.
>>> writer_demo.test()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "writer_demo.py", line 61, in test
AttributeError: 'I2C' object has no attribute 'line
---------------------------------------------------------------
Thx

Edit:
I tried also the code from here: viewtopic.php?t=5589#p32228
but I get:
------------------------------------------------
wri2 = Writer(ssd, courier20, verbose = False)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "writer.py", line 70, in __init__
File "writer.py", line 45, in _get_id
ValueError: Device must be derived from FrameBuffer.
------------------------------------------------
>>> dir(ssd)
dir(oled)
['__class__', '__dict__', '__init__', '__module__', '__qualname__', 'addr', 'buffer', 'fill', 'framebuf', 'invert', 'pixel', 'scroll', 'text', 'width', 'i2c', 'height', 'external_vcc', 'pages', 'poweron', 'init_display', 'write_cmd', 'show', 'poweroff', 'contrast', 'write_framebuf', 'temp']
------------------------------------------------
'framebuf' is there ...
I'm relativly new to Python coding, so please excuse any beginners mistakes ;)

Re: Larger fonts on SSD1306 OLED displays

Posted: Tue Jan 29, 2019 9:14 am
by pythoncoder
Device must be derived from FrameBuffer.
This suggests you're using out of date firmware. Please update to the newest version (V1.10).
File "writer_demo.py", line 61, in test
AttributeError: 'I2C' object has no attribute 'line
This has me foxed as writer_demo.py ends at line 58.

Please ensure that all modules are up to date.

Re: Larger fonts on SSD1306 OLED displays

Posted: Sat Feb 02, 2019 3:13 pm
by walterheisenberg
With fresh installation of Micropython 1.1 and fresh downloaded modules, everything is working now
Thx for your help

BTW: I could test writer_tests.py only after commenting out this line:
from writer_gui import Label, Meter
There is no writer_gui.py in the repo. Also not in https://github.com/peterhinch/micropython-tft-gui

Re: Larger fonts on SSD1306 OLED displays

Posted: Sun Feb 03, 2019 2:33 pm
by pythoncoder
Thank you for pointing that out: writer_gui.py now added.

Re: Larger fonts on SSD1306 OLED displays

Posted: Tue Jul 16, 2019 4:08 pm
by Vendox
Hello all! :)

I'm new to circuitpython and programing overall. I did a simple project with SSD1306 OLED and DHT22. I would like to change a font size, the basic font is to small. Do I need to use some additonal library to change anything? Can anyone give me some advice what library I miss and give me some example code how to set up a font size?

Here is my code so far with basic font:

import time
import board
import busio
import adafruit_dht
import adafruit_ssd1306
# Create the I2C interface.
i2c = busio.I2C(board.SCL, board.SDA)
# Create the SSD1306 OLED class and DHT class
display = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3c)
dht = adafruit_dht.DHT22(board.D9)

while True:

display.text("Temperature:", 0, 0, 1)
display.text("Humidity:", 0, 10, 1)
display.text(str(dht.temperature), 75, 0, 1)
display.text(str(dht.humidity), 75, 10, 1)
display.show()
time.sleep(10)
display.fill(0)
display.show()

Re: Larger fonts on SSD1306 OLED displays

Posted: Wed Jul 17, 2019 6:44 am
by pythoncoder
This forum supports MicroPython. CircuitPython is the Adafruit fork of MicroPython, and their SSD1306 driver differs from the MicroPython version.

I don't know if Adafruit support using different fonts. A search on their forum or a query there might produce results.

There is unofficial MicroPython support for arbitrary fonts here, via the Writer class. This has only been tested with the official SSD1306 driver. From a quick look at the Adafruit code you might have success. You might like to give it a try and report back.