Last active
January 2, 2026 16:15
-
-
Save gmacario/2b901a3cb4ff73992a3cd5de7954c7a6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # demo_oled.py | |
| import math | |
| import ssd1306 | |
| import time | |
| from machine import Pin, I2C | |
| OLED_WIDTH = 128 | |
| OLED_HEIGHT = 64 # 32 | |
| # OLED_I2C_ADDR=0x3c # 0.91in (burned pixels) | |
| OLED_I2C_ADDR=0x3d # Adafruit 1.3in (https://adafru.it/938) | |
| # setup the screen | |
| i2c = I2C(0, scl=Pin(1), sda=Pin(0), freq=400000) | |
| oled = ssd1306.SSD1306_I2C(OLED_WIDTH, OLED_HEIGHT, i2c, addr=OLED_I2C_ADDR) | |
| oled.fill(0) | |
| display = oled | |
| for x in range(0, OLED_WIDTH // 2, 3): | |
| x1 = x | |
| x2 = OLED_WIDTH - 2 * x | |
| y1 = x | |
| y2 = OLED_HEIGHT - 2 * x | |
| # print(f"Draw rect: {x1},{y1} - {x2},{y2}") | |
| oled.rect(x1, y1, x2, y2, 1) | |
| oled.show() | |
| time.sleep(10) | |
| # Draw the MicroPython logo and print some text: | |
| # See https://docs.micropython.org/en/latest/esp8266/tutorial/ssd1306.html | |
| # | |
| 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) | |
| display.text('MicroPython', 40, 0, 1) | |
| display.text('SSD1306', 40, 12, 1) | |
| display.text(f'OLED {OLED_WIDTH}x{OLED_HEIGHT}', 40, 24, 1) | |
| display.show() | |
| time.sleep(10) | |
| oled.poweroff() | |
| # EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment