MicroPython-Examples/Example - SPI OLED Display/main_OLED.py

28 lines
770 B
Python
Raw Normal View History

2024-05-10 13:26:38 +02:00
from machine import Pin, SoftSPI
import ssd1306
2024-08-06 03:40:51 +02:00
sck = Pin(18) # D0
scl = Pin(19) # D1
2024-05-10 13:26:38 +02:00
spi = SoftSPI(baudrate=500000, polarity=1, phase=0, sck=sck, mosi=scl, miso=Pin(12))
2024-08-06 03:40:51 +02:00
rst = Pin(20) # reset
dc = Pin(17) # data/command
cs = Pin(16) # chip select, some modules do not have a pin for this
2024-05-10 13:26:38 +02:00
display = ssd1306.SSD1306_SPI(128, 64, spi, dc, rst, cs)
# display.text('Hello, World!', 0, 0, 1)
# display.show()
display.fill(0)
display.fill_rect(0, 0, 32, 32, 1)
display.fill_rect(2, 2, 28, 28, 0)
display.vline(9, 8, 22, 1)
display.vline(16, 2, 22, 1)
display.vline(23, 8, 22, 1)
display.fill_rect(26, 24, 2, 4, 1)
2024-08-06 03:40:51 +02:00
display.text('MicroPython', 40, 0, 1) # Yellow
display.text('SSD1306', 40, 12, 1) # Yellow
display.text('OLED 128x64', 40, 24, 1) # Blue
2024-05-10 13:26:38 +02:00
display.show()