Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ initialize()

You have to use this instruction before using the display. This puts the display in its reset status.

Optional Parameters :
`pinReset` : to specify the pin connected to the reset pin on displays using this function

`i2cAddress` : to specify the i2c address of the screen, default address for the display is `0x3D`


clear_oled()
+++++++++++++++++++++++
Expand Down
8 changes: 8 additions & 0 deletions samples/hello-world/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from ssd1306 import initialize, clear_oled
from ssd1306_text import add_text
from microbit import *


initialize(pinReset=pin0)
clear_oled()
add_text(0, 0, "Salut !!!")
16 changes: 14 additions & 2 deletions ssd1306.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
# Only supports display type I2C128x64

from microbit import i2c
from microbit import *

# LCD Control constants
ADDR = 0x3C
ADDR = 0x3D
# For Adafruit OLED = 0x3D (0x7A)
# For chinesse OLED = 0x3C (0x78)
screen = bytearray(513) # send byte plus pixels
screen[0] = 0x40
zoom = 1
Expand All @@ -18,7 +21,7 @@ def command(c):
i2c.write(ADDR, b'\x00' + bytearray(c))


def initialize():
def initialize(i2cAddress = None, pinReset = None):
cmd = [
[0xAE], # SSD1306_DISPLAYOFF
[0xA4], # SSD1306_DISPLAYALLON_RESUME
Expand All @@ -41,6 +44,15 @@ def initialize():
[0xd6, 1], # zoom on
[0xaf] # SSD1306_DISPLAYON
]
if i2cAddress:
ADDR = i2cAddress
if pinReset:
pinReset.write_digital(1)
sleep(1)
pinReset.write_digital(0)
sleep(10)
pinReset.write_digital(1)
sleep(10)
for c in cmd:
command(c)

Expand Down
1 change: 1 addition & 0 deletions ssd1306_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


def add_text(x, y, text, draw=1):
id = 0
for i in range(0, min(len(text), 12 - x)):
for c in range(0, 5):
col = 0
Expand Down