Hi
Is there a way to display images and other fonts using an OLED (128×64 SSD1306) display?
Also, looking at the SSD1306 code you provide – not sure where the text method comes from. And where is it importing framebuf from?
Thanks
Tim
Hi.
Everything is done on the background with the library. You can take a look at the library in the following link and see the methods available. Including the .text method
https://github.com/RuiSantosdotme/ESP-MicroPython/blob/master/code/Others/OLED/ssd1306.py
The library we’re using doesn’t support other fonts or image.
There is another library by Adafruit that supports graphics (drawing shapes). But it is deprecated and I’m not sure if it is working or if it supports other fonts 🙁
https://github.com/adafruit/micropython-adafruit-gfx
I’m sorry that I can’t help much here.
Thank you for your interest in our projects.
Regards,
Sara
Thanks Sara.
I have found a way of doing fonts.. see:
- https://github.com/peterhinch/micropython-font-to-py/blob/master/writer/WRITER.md (can display fonts on the SSD1306 OLED)
- https://github.com/peterhinch/micropython-nano-gui (this adds more functionality, some graphics etc – although I have not yet got this working I’ll persist for a while to see if I can). Edit: Turns out nanogui.py relys on the micropython cmath library – which (according to the docs) is not available on the ESP8266).
Cheers
Tim
Hi Tim.
Thank you for sharing. I’ll have to take a look at those libraries, and maybe come up with a new tutorial in the next weeks.
Regards,
Sara
FYI – Here’s my initial demo code:
# Original source from RNTLabs MicroPython on ESP8266 book # Then modified for font and graphics from: See https://github.com/peterhinch/micropython-nano-gui# *** However, turns out nanogui.py cant be used as it requires cmath lib which is not available on ESP8266 (see cmath docs) # So instead just use Writer - see https://github.com/peterhinch/micropython-font-to-py/blob/master/writer/WRITER.md from machine import Pin, I2C import gc import ssd1306 #ESP32 Pin assignment #i2c = I2C(-1, scl=Pin(22), sda=Pin(21)) # ESP8266 - Pin assignment i2c = I2C(-1, scl=Pin(5), sda=Pin(4)) oled_width = 128 oled_height = 64 gc.collect() oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c) oled.text('Hello BOB6!', 0, 0) oled.text('Hello, World 2!', 0, 10) oled.show() # This causes the error: Import Error: cannot import name Label # *** Turns out nanogui.py cant be used as it requires cmath lib which is not available on ESP8266 (see cmath docs) #from nanogui import Label, Dial, Pointer, refresh #refresh(oled) # Initialise and clear display. from writer import Writer import arial10 # Font wri = Writer(oled, arial10, verbose=False) #The following Writer example works #wri = Writer(ssd, freesans20) # verbose = False to suppress console output Writer.set_textpos(oled, 16, 0) # In case a previous test has altered this wri.printstring('Sunday\n12 Aug 2018\n10.30am') oled.show()
Hi Tim.
Thank you so much for sharing your code.
I’ll try it out soon.
Regards,
Sara
You’re welcome.
FYI – I eventually got his font-to-py generator working to. Had some issues – but turns out my ESP8266 needed rebooting.
Take a look at: https://github.com/peterhinch/micropython-font-to-py/blob/master/FONT_TO_PY.md
I needed to use Linux to get it working.