diff --git a/python-examples/OLEDimage.py b/python-examples/OLEDimage.py index b02a1a6..96433bb 100644 --- a/python-examples/OLEDimage.py +++ b/python-examples/OLEDimage.py @@ -2,11 +2,11 @@ # Meant for use with the Raspberry Pi and an Adafruit monochrome OLED display! -# This program takes any image (recommended: landscape) and converts it into a black and white image which is then -# displayed on one of Adafruit's monochrome OLED displays. +# This program takes any image (recommended: landscape) and converts it into a black and white image which is then +# displayed on one of Adafruit's monochrome OLED displays. # To run the code simply change directory to where it is saved and then type: sudo python OLEDimage.py -# For example: sudo python OLEDimage.py penguins900x600.jpg +# For example: sudo python OLEDimage.py penguins900x600.jpg # The image penguins900x600.jpg is included in this repo as an example! Download any image that you want and simply change the # image name! @@ -14,6 +14,8 @@ # Imports the necessary software - including PIL, an image processing library import gaugette.ssd1306 +import gaugette.platform +import gaugette.gpio import time import sys from PIL import Image @@ -26,10 +28,20 @@ DC_PIN = 16 # WiringPi pin 16 is GPIO15. width = 128 height = 32 +spi_bus = 0 +spi_device = 0 +gpio = gaugette.gpio.GPIO() +spi = gaugette.spi.SPI(spi_bus, spi_device) -led = gaugette.ssd1306.SSD1306(reset_pin=RESET_PIN, dc_pin=DC_PIN) +# Very important... This lets py-gaugette 'know' what pins to use in order to reset the display +led = gaugette.ssd1306.SSD1306(gpio, spi, reset_pin=RESET_PIN, dc_pin=DC_PIN, rows=32, cols=128) # Change rows & cols values depending on your display dimensions. led.begin() led.clear_display() +led.display() +led.invert_display() +time.sleep(0.5) +led.normal_display() +time.sleep(0.5) # This bit converts our image into black and white and resizes it for the display @@ -46,3 +58,4 @@ led.draw_pixel(x,y,bool(int(image_bw.getpixel((x,y))))) led.display() +