/ examples / ssd1306_pillow_image_display.py
ssd1306_pillow_image_display.py
 1  # This example is for use on (Linux) computers that are using CPython with
 2  # Adafruit Blinka to support CircuitPython libraries. CircuitPython does
 3  # not support PIL/pillow (python imaging library)!
 4  #
 5  # Ported to Pillow by Melissa LeBlanc-Williams for Adafruit Industries from Code available at:
 6  # https://learn.adafruit.com/adafruit-oled-displays-for-raspberry-pi/programming-your-display
 7  
 8  # Imports the necessary libraries...
 9  import sys
10  import board
11  import digitalio
12  from PIL import Image
13  import adafruit_ssd1306
14  
15  # Setting some variables for our reset pin etc.
16  RESET_PIN = digitalio.DigitalInOut(board.D4)
17  
18  i2c = board.I2C()
19  oled = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3D, reset=RESET_PIN)
20  
21  # Clear display.
22  oled.fill(0)
23  oled.show()
24  
25  # Open, resize, and convert image to Black and White
26  image = (
27      Image.open(sys.argv[1])
28      .resize((oled.width, oled.height), Image.BICUBIC)
29      .convert("1")
30  )
31  
32  # Display the converted image
33  oled.image(image)
34  oled.show()