unable to use Bigger Fonts with OLED

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
SubrataT
Posts: 4
Joined: Mon Jun 03, 2019 3:22 pm

unable to use Bigger Fonts with OLED

Post by SubrataT » Thu Jun 27, 2019 5:01 pm

I wanted to use an OLED to display bigger characters. From Micropython Forum I came to know that to display bigger Fonts we have to use Writer class of Peter Hinch(Pythoncoder). Accordingly I used Writer class.
Hardware used:
1. ESP 8266-12E
2. 0.96" OLED display(ssd 1306) 128x64 pixel resolution with I2C interface

Connection:
1. GPIO12 used as SCL, GPIO13 used as SDA for I2C connection from ESP8266-12E to OLED

Software:
1. Ubuntu 18.04.2 installed as guest in Virtual Box(ver 6.0.8) in windows 10 Host for building Micropython flash
2. uPyCraft version 1.1 as IDE
3. For Bigger Fonts I used micropython-font-to-py-master by Peter Hinch(Pythoncoder) from Github

Condition 1:
Standard Built Micropython Flash esp8266-20190529-v1.11.bin
with following files copied to the esp module:
1. freesans20.py
2. writer.py
3. writer_demo2.py
4. on REPL Prompt
5. >>> import writer_demo2
6. >>> writer_demo2.test()
It worked fine with Bigger Fonts dispalyed on OLED as expected.

Condition 2:
As loading font files to esp modules occupies huge RAM and sometimes gives memory error also. I wanted to transfer these following modules and freeze in ESP flash.
1. freesans20.py
2. writer.py
3. ssd1306.py

For this I had to Build the Flash as per instruction of Readme file and transferred firmware-combined.bin file to esp flash. Then did the following:

4. writer_demo2.py transferred to ESP filesystem
5. >>> import writer_demo2
6. >>> writer_demo2.test()

This is throwing the following error:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "writer_demo2.py", line 28, in test
File "writer.py", line 70, in __init__
File "writer.py", line 45, in _get_id
ValueError: Device must be derived from FrameBuffer.
>>>


If I do enter the commands line by line in REPL Prompt it is throwing the same error.
given below:

>>> import machine
>>> from writer import Writer
>>> from ssd1306 import SSD1306_I2C
>>> import freesans20
>>> WIDTH = const(128)
>>> HEIGHT = const(64)
>>> i2c = machine.I2C(scl=machine.Pin(12), sda=machine.Pin(13))
>>> ssd = SSD1306_I2C(WIDTH, HEIGHT, i2c)
>>> wri = Writer(ssd, freesans20)
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.
>>>

This error condition is happening only with my own build flash.
I repeated the process with standard built Micropython Flash and it is working fine without throwing any error. Unable to figure out what mistake I have done.
Any guidance will be highly appreciated.

copy of writer_demo2.py is given below:

# This program was tested with standard built flash on 12-06-2019 - Wednesday
# and found to be working
# copy writer.py and freesans20.py in esp8266 filesystem
# in repl prompt >>> import writer_demo2
# writer_demo2.test() - this will display the string in OLED


import machine
import framebuf
from writer import Writer
from ssd1306 import SSD1306_I2C
# Font
import freesans20
WIDTH = const(128)
HEIGHT = const(64)

i2c = machine.I2C(scl=machine.Pin(12), sda=machine.Pin(13))
#ssd = SSD1306_I2C(WIDTH, HEIGHT, i2c)

def test(use_spi=False):
ssd = SSD1306_I2C(WIDTH, HEIGHT, i2c)
print(ssd)
#rhs = WIDTH -1
#ssd.line(rhs - 20, 0, rhs, 20, 1)
#square_side = 10
#ssd.fill_rect(rhs - square_side, 0, square_side, square_side, 1)

wri = Writer(ssd, freesans20)
Writer.set_textpos(ssd, 0, 0) # verbose = False to suppress console output
#wri.printstring('ABCDEFGHIJKLMNOPQRSTUVWXYZ12')
#wri.printstring('1234567890')
wri.printstring('abcdefghijklmnopqrstuvwxyz')
ssd.show()

print('Test assumes a 128*64 (w*h) display. Edit WIDTH and HEIGHT in ssd1306_setup.py for others.')
print('Device pinouts are comments in ssd1306_setup.py.')
print('Issue:')
print('writer_demo.test() for an I2C connected device.')
print('writer_demo.test(True) for an SPI connected device.')

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: unable to use Bigger Fonts with OLED

Post by pythoncoder » Fri Jun 28, 2019 7:32 am

Thanks for the comprehensive error report. The error ValueError: Device must be derived from FrameBuffer. means that your version of ssd1306.py is out of date. Acquire the latest version from the MicroPython source tree (in drivers/display).
Peter Hinch
Index to my micropython libraries.

SubrataT
Posts: 4
Joined: Mon Jun 03, 2019 3:22 pm

Re: unable to use Bigger Fonts with OLED

Post by SubrataT » Fri Jun 28, 2019 3:58 pm

Wonderful.....As suggested I downloaded the latest ssd1306 display driver dt.19-05-2019 10:06 P.M and it worked as expected. :D
Thank you once again for writing such a wonderful writer class.
Subrata Thakur

Post Reply