[Solved] Larger fonts with OLED SH1106..?
Posted: Sun Nov 07, 2021 12:38 pm
Hi All 
I had a few SH1106 OLED's and I thought I'll try one with my Teensy 4.0.
Did a 'Hello World' with normal built-in font of micropythonl, it worked as expected
but found the 8x8 font a bit hard to see with these aging eyes...
Then I discovered 'MicroPython font handling' by @pythoncoder, but was not sure
if it would work with SH1106 OLED driver by @robert-hh and @deshipu...
This near novice to MicroPython did a hack/bodge and came up with the code shown below...
I have four files in the root of the Teensy file system, freesans20.py sh1106.py writer.py and
writer_demo.py file as shown above...
Below is the is the result, did a Ctrl D via Thonny IDE 3.3.14 console before executing
writer_demo.py ...
Three errors showed, the 1st 'line 17' refers to my hack/bodge code shown above...
The next two come from writer.py, 'line 64' and 'line 39' are shown below...
Is my bodge code above faulty, or the sh1106 driver unable to work with
'MicroPython font handling' by @pythoncoder for the moment...?

I had a few SH1106 OLED's and I thought I'll try one with my Teensy 4.0.
Did a 'Hello World' with normal built-in font of micropythonl, it worked as expected
but found the 8x8 font a bit hard to see with these aging eyes...

Then I discovered 'MicroPython font handling' by @pythoncoder, but was not sure
if it would work with SH1106 OLED driver by @robert-hh and @deshipu...
This near novice to MicroPython did a hack/bodge and came up with the code shown below...
Code: Select all
import machine
from writer import Writer
from sh1106 import SH1106_I2C
# Font
import freesans20
WIDTH = const(128)
HEIGHT = const(64)
# Create the I2C interface.
i2c = machine.I2C(0)
ssd = SH1106_I2C(WIDTH, HEIGHT, i2c)
print("I2C Address : "+hex(i2c.scan()[0]).upper()) # Display device address
print("I2C Configuration: "+str(i2c)) # Display I2C config
wri = Writer(ssd, freesans20)
Writer.set_textpos(ssd, 0, 0) # verbose = False to suppress console output
wri.printstring('Hello World\n')
ssd.show()
writer_demo.py file as shown above...
Below is the is the result, did a Ctrl D via Thonny IDE 3.3.14 console before executing
writer_demo.py ...
Code: Select all
MPY: soft reboot
MicroPython v1.17-135-gc9c55032d on 2021-11-05; Teensy 4.0 with MIMXRT1062DVJ6A
Type "help()" for more information.
>>> %Run -c $EDITOR_CONTENT
I2C Address : 0X3C
I2C Configuration: I2C(0, freq=400000)
Traceback (most recent call last):
File "<stdin>", line 17, in <module>
File "writer.py", line 64, in __init__
File "writer.py", line 39, in _get_id
ValueError: Device must be derived from FrameBuffer.
>>>
Code: Select all
wri = Writer(ssd, freesans20)
Code: Select all
.....
self.devid = _get_id(device)
.....
raise ValueError('Device must be derived from FrameBuffer.')
.....
'MicroPython font handling' by @pythoncoder for the moment...?
