error hinzugefügt

This commit is contained in:
hubobel 2026-01-11 18:42:42 +01:00
parent 7fc8488fde
commit a79f4e44c7
6 changed files with 156 additions and 3 deletions

72
Python/test.py Normal file
View file

@ -0,0 +1,72 @@
import board
import digitalio
from PIL import Image, ImageDraw, ImageFont
import adafruit_ssd1306
import socket
import time
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80)) # keine echte Verbindung, nur Routing
ip_address = s.getsockname()[0]
s.close()
# Initialize OLED display dimensions
WIDTH = 128
HEIGHT = 64
# Set up I2C communication with the OLED display
i2c = board.I2C() # Utilizes board's SCL and SDA pins
oled = adafruit_ssd1306.SSD1306_I2C(WIDTH, HEIGHT, i2c, addr=0x3C)
# Clear the OLED display
oled.fill(0)
oled.show()
# Create a new image with 1-bit color for drawing
image = Image.new("1", (oled.width, oled.height))
# Obtain a drawing object to manipulate the image
draw = ImageDraw.Draw(image)
# Draw a filled white rectangle as the background
draw.rectangle((0, 0, oled.width, oled.height), outline=255, fill=255)
# Define border size for an inner rectangle
BORDER = 5
# Draw a smaller black rectangle inside the larger one
draw.rectangle(
(BORDER, BORDER, oled.width - BORDER - 1, oled.height - BORDER - 1),
outline=0,
fill=0,
)
# Load the default font for text
font = ImageFont.load_default()
def getfontsize(font, text):
# Calculate the size of the text in pixels
left, top, right, bottom = font.getbbox(text)
return right - left, bottom - top
# Define the text to be displayed
text = ip_address
# Get the width and height of the text in pixels
(font_width, font_height) = getfontsize(font, text)
# Draw the text, centered on the display
draw.text(
(oled.width // 2 - font_width // 2, oled.height // 2 - font_height // 2),
text,
font=font,
fill=255,
)
# Send the image to the OLED display
oled.image(image)
oled.show()
DISPLAY_ON_TIME = 10 * 60
time.sleep(DISPLAY_ON_TIME)
# --- OLED sauber ausschalten ---
oled.poweroff()