From 0e458f6d2765864b664d80df2c0dc0323edd398f Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Thu, 7 Nov 2019 17:15:52 -0800 Subject: [PATCH] Now works with 128x64 displays, added Pillow Demo --- adafruit_ssd1305.py | 2 +- examples/ssd1305_pillow_demo.py | 63 +++++++++++++++++++++++++++++++++ examples/ssd1305_simpletest.py | 8 +++++ 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 examples/ssd1305_pillow_demo.py diff --git a/adafruit_ssd1305.py b/adafruit_ssd1305.py index 14526f7..38b630e 100644 --- a/adafruit_ssd1305.py +++ b/adafruit_ssd1305.py @@ -109,7 +109,7 @@ def init_display(self): # timing and driving scheme 0xd5, 0x80, #SET_DISP_CLK_DIV 0xa0 | 0x01, # column addr 127 mapped to SEG0 SET_SEG_REMAP - 0xa8, 0x1f,#SET_MUX_RATIO + 0xa8, self.height - 1, #SET_MUX_RATIO 0xd3, 0x00, #SET_DISP_OFFSET 0xad, 0x8e, #Set Master Configuration 0xd8, 0x05, #Set Area Color Mode On/Off & Low Power Display Mode diff --git a/examples/ssd1305_pillow_demo.py b/examples/ssd1305_pillow_demo.py new file mode 100644 index 0000000..7619dc2 --- /dev/null +++ b/examples/ssd1305_pillow_demo.py @@ -0,0 +1,63 @@ +""" +This demo will fill the screen with white, draw a black box on top +and then print Hello World! in the center of the display + +This example is for use on (Linux) computers that are using CPython with +Adafruit Blinka to support CircuitPython libraries. CircuitPython does +not support PIL/pillow (python imaging library)! +""" + +import board +import digitalio +from PIL import Image, ImageDraw, ImageFont +import adafruit_ssd1305 + +# Define the Reset Pin +oled_reset = digitalio.DigitalInOut(board.D4) + +# Change these +# to the right size for your display! +WIDTH = 128 +HEIGHT = 64 # Change to 32 if needed +BORDER = 8 + +# Use for SPI +spi = board.SPI() +oled_cs = digitalio.DigitalInOut(board.D5) +oled_dc = digitalio.DigitalInOut(board.D6) +oled = adafruit_ssd1305.SSD1305_SPI(WIDTH, HEIGHT, spi, oled_dc, oled_reset, oled_cs) + +# Use for I2C. +#i2c = board.I2C() +#oled = adafruit_ssd1305.SSD1305_I2C(WIDTH, HEIGHT, i2c, addr=0x3c, reset=oled_reset) + +# Clear display. +oled.fill(0) +oled.show() + +# Create blank image for drawing. +# Make sure to create image with mode '1' for 1-bit color. +image = Image.new('1', (oled.width, oled.height)) + +# Get drawing object to draw on image. +draw = ImageDraw.Draw(image) + +# Draw a white background +draw.rectangle((0, 0, oled.width, oled.height), outline=255, fill=255) + +# Draw a smaller inner rectangle +draw.rectangle((BORDER, BORDER, oled.width - BORDER - 1, oled.height - BORDER - 1), + outline=0, fill=0) + +# Load default font. +font = ImageFont.load_default() + +# Draw Some Text +text = "Hello World!" +(font_width, font_height) = font.getsize(text) +draw.text((oled.width//2 - font_width//2, oled.height//2 - font_height//2), + text, font=font, fill=255) + +# Display image +oled.image(image) +oled.show() diff --git a/examples/ssd1305_simpletest.py b/examples/ssd1305_simpletest.py index 7af604d..d057e68 100644 --- a/examples/ssd1305_simpletest.py +++ b/examples/ssd1305_simpletest.py @@ -21,3 +21,11 @@ display.fill(0) display.show() + +# Set a pixel in the origin 0,0 position. +display.pixel(0, 0, 1) +# Set a pixel in the middle 64, 16 position. +display.pixel(64, 16, 1) +# Set a pixel in the opposite 127, 31 position. +display.pixel(127, 31, 1) +display.show()