Skip to content

Commit 0e458f6

Browse files
committed
Now works with 128x64 displays, added Pillow Demo
1 parent 1569414 commit 0e458f6

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

adafruit_ssd1305.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def init_display(self):
109109
# timing and driving scheme
110110
0xd5, 0x80, #SET_DISP_CLK_DIV
111111
0xa0 | 0x01, # column addr 127 mapped to SEG0 SET_SEG_REMAP
112-
0xa8, 0x1f,#SET_MUX_RATIO
112+
0xa8, self.height - 1, #SET_MUX_RATIO
113113
0xd3, 0x00, #SET_DISP_OFFSET
114114
0xad, 0x8e, #Set Master Configuration
115115
0xd8, 0x05, #Set Area Color Mode On/Off & Low Power Display Mode

examples/ssd1305_pillow_demo.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
"""
2+
This demo will fill the screen with white, draw a black box on top
3+
and then print Hello World! in the center of the display
4+
5+
This example is for use on (Linux) computers that are using CPython with
6+
Adafruit Blinka to support CircuitPython libraries. CircuitPython does
7+
not support PIL/pillow (python imaging library)!
8+
"""
9+
10+
import board
11+
import digitalio
12+
from PIL import Image, ImageDraw, ImageFont
13+
import adafruit_ssd1305
14+
15+
# Define the Reset Pin
16+
oled_reset = digitalio.DigitalInOut(board.D4)
17+
18+
# Change these
19+
# to the right size for your display!
20+
WIDTH = 128
21+
HEIGHT = 64 # Change to 32 if needed
22+
BORDER = 8
23+
24+
# Use for SPI
25+
spi = board.SPI()
26+
oled_cs = digitalio.DigitalInOut(board.D5)
27+
oled_dc = digitalio.DigitalInOut(board.D6)
28+
oled = adafruit_ssd1305.SSD1305_SPI(WIDTH, HEIGHT, spi, oled_dc, oled_reset, oled_cs)
29+
30+
# Use for I2C.
31+
#i2c = board.I2C()
32+
#oled = adafruit_ssd1305.SSD1305_I2C(WIDTH, HEIGHT, i2c, addr=0x3c, reset=oled_reset)
33+
34+
# Clear display.
35+
oled.fill(0)
36+
oled.show()
37+
38+
# Create blank image for drawing.
39+
# Make sure to create image with mode '1' for 1-bit color.
40+
image = Image.new('1', (oled.width, oled.height))
41+
42+
# Get drawing object to draw on image.
43+
draw = ImageDraw.Draw(image)
44+
45+
# Draw a white background
46+
draw.rectangle((0, 0, oled.width, oled.height), outline=255, fill=255)
47+
48+
# Draw a smaller inner rectangle
49+
draw.rectangle((BORDER, BORDER, oled.width - BORDER - 1, oled.height - BORDER - 1),
50+
outline=0, fill=0)
51+
52+
# Load default font.
53+
font = ImageFont.load_default()
54+
55+
# Draw Some Text
56+
text = "Hello World!"
57+
(font_width, font_height) = font.getsize(text)
58+
draw.text((oled.width//2 - font_width//2, oled.height//2 - font_height//2),
59+
text, font=font, fill=255)
60+
61+
# Display image
62+
oled.image(image)
63+
oled.show()

examples/ssd1305_simpletest.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,11 @@
2121
display.fill(0)
2222

2323
display.show()
24+
25+
# Set a pixel in the origin 0,0 position.
26+
display.pixel(0, 0, 1)
27+
# Set a pixel in the middle 64, 16 position.
28+
display.pixel(64, 16, 1)
29+
# Set a pixel in the opposite 127, 31 position.
30+
display.pixel(127, 31, 1)
31+
display.show()

0 commit comments

Comments
 (0)