This repository has been archived on 2024-05-23. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
PiDisplay/displaytest.py
T
2021-07-30 14:31:45 +02:00

41 lines
964 B
Python

#! /usr/bin/python3
# -*- coding: utf8 -*-
# load needed modules from luma
from luma.core.interface.serial import i2c, spi
from luma.core.render import canvas
from luma.oled.device import sh1106
from luma.core import lib
# load needed modules from RPi.GPIO
import RPi.GPIO as GPIO
# load needed modules from PIL
from PIL import ImageFont, ImageDraw, Image
#GPIO define pins
RST_PIN = 25 #Reset
CS_PIN = 8
DC_PIN = 24
serial = spi(device=0, port=0, bus_speed_hz = 8000000, transfer_size = 4096, gpio_DC = DC_PIN, gpio_RST = RST_PIN)
device = sh1106(serial, rotate=2) #sh1106
oled_font = ImageFont.load_default()
def main()
with canvas(device) as draw:
draw.rectangle(device.bounding_box, outline = "white", fill = "black")
draw.text((10, 10), "OLED-Display", font = oled_font, fill = "white")
try:
while True:
stamp = time.time()
main()
time.sleep(1)
except:
print("Stopped", sys.exc_info()[0])
raise
GPIO.cleanup()