-
Notifications
You must be signed in to change notification settings - Fork 1
/
ssd1306_display_module.py
34 lines (27 loc) · 1.64 KB
/
ssd1306_display_module.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'''
Enable larger fonts for the OLED display:
https://github.com/peterhinch/micropython-font-to-py
https://www.youtube.com/watch?v=bLXMVTTPFMs
https://blog.miguelgrinberg.com/post/micropython-and-the-internet-of-things-part-vi-working-with-a-screen
'''
def disp_setup(scl_pin, sda_pin, width, height, id = 0, addr = 0x3C):
from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
i2c = I2C(id, scl=Pin(scl_pin), sda=Pin(sda_pin), freq=400000)
oled = SSD1306_I2C(width, height, i2c, addr)
return oled
def disp_string(oled, x, y, str, disp_logo = True):
import framebuf
import writer
import freesans20
# Raspberry Pi logo as 32x32 bytearray
logo = bytearray(b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00|?\x00\x01\x86@\x80\x01\x01\x80\x80\x01\x11\x88\x80\x01\x05\xa0\x80\x00\x83\xc1\x00\x00C\xe3\x00\x00~\xfc\x00\x00L'\x00\x00\x9c\x11\x00\x00\xbf\xfd\x00\x00\xe1\x87\x00\x01\xc1\x83\x80\x02A\x82@\x02A\x82@\x02\xc1\xc2@\x02\xf6>\xc0\x01\xfc=\x80\x01\x18\x18\x80\x01\x88\x10\x80\x00\x8c!\x00\x00\x87\xf1\x00\x00\x7f\xf6\x00\x008\x1c\x00\x00\x0c \x00\x00\x03\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
oled.fill(0)
font_writer = writer.Writer(oled, freesans20, False) # disable verbose mode
font_writer.set_textpos(x, y)
font_writer.printstring(str)
if disp_logo:
fb = framebuf.FrameBuffer(logo, 32, 32, framebuf.MONO_HLSB) # load the framebuffer
# MONO_HLSB: monochrome, horizontally mapped - each byte occupies 8 horizontal pixels with bit 0 being the leftmost
oled.blit(fb, 96, 0) # blit the image from the framebuffer to the display
oled.show()