• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Micropython for ESP8266 – Displaying an image or other fonts using on an SSD1306 OLED display

Q&A Forum › Category: ESP8266 › Micropython for ESP8266 – Displaying an image or other fonts using on an SSD1306 OLED display
0 Vote Up Vote Down
timhuffam asked 6 years ago

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

Question Tags: OLED
7 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 6 years ago

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

0 Vote Up Vote Down
timhuffam answered 6 years ago

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

0 Vote Up Vote Down
Sara Santos Staff answered 6 years ago

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

0 Vote Up Vote Down
timhuffam answered 6 years ago

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()

 

0 Vote Up Vote Down
Sara Santos Staff answered 6 years ago

Hi Tim.
Thank you so much for sharing your code.
I’ll try it out soon.
Regards,
Sara

0 Vote Up Vote Down
timhuffam answered 6 years ago

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.

0 Vote Up Vote Down
Sara Santos Staff answered 6 years ago

Hi Tim. Once again thank you for sharing.
I definitely have to take a look at those examples.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.