Adsense HTML/JavaScript

Friday, September 11, 2020

MicroPython on pyboard to display text on OLED (with I2C interface ssd1306)

It's a 0.96 inch 128x64  OLED displays with ssd1306 driver using I2C interface. This example show how to display text on it with pyboard using MicroPython ssd1306 library.

Connection between pyboard and OLED:
pyboard 3V3 connected to ssd1306 VCC
pyboard GND connected to ssd1306 GND
pyboard X12 connected to ssd1306 SCL
pyboard X11 connected to ssd1306 SDA


Download the MicroPython ssd1306 library HERE, ans save it to pyboard flash.

MicroPython script, pyb_i2c_ssd1306.py:

# Download ssd1306
# https://github.com/micropython/micropython/blob/master/drivers/display/ssd1306.py
# and save to pyboard flash

import ssd1306
import machine
import time

WIDTH = const(128)
HEIGHT = const(64)

ssd1306_scl = machine.Pin('X12', machine.Pin.OUT_PP)
ssd1306_sda = machine.Pin('X11', machine.Pin.OUT_PP)
i2c_ssd1306 = machine.I2C(scl=ssd1306_scl, sda=ssd1306_sda)

print(i2c_ssd1306.scan())
oled = ssd1306.SSD1306_I2C(WIDTH, HEIGHT, i2c_ssd1306)
oled.fill(0)

oled.text("MicroPython", 0, 0)
oled.text("OLED(ssd1306)", 0, 10)
oled.text("pyboard", 0, 20)
oled.show()

while True:
    time.sleep(1)
    oled.invert(1)
    time.sleep(1)
    oled.invert(0)


No comments:

Post a Comment