Benutzer-Werkzeuge

Webseiten-Werkzeuge


Seitenleiste


C - Programmierung am Raspberry  Schaltpläne und Bauteilbeschreibungen  Adapterkabel  Mechanik  EDV-Literatur deutsch 



    FIAN Österreich     Marktplatz Natur    
    Bäckerei Freitag

disp_oled_ep0060

OLED Modul EP-0060

V1.00.0

Dieses winzige OLED Display Modul mit einer Diagonale von 2,3cm bietet Platz für vier Zeilen Text mit etwa 20 Zeichen (je nach verwendetem Font) oder/und einfache Grafiken.
Die Auflösung beträgt 128×32 Pixel.
Als Controler wird der Grafikchip ssd306 verwendet.
Der Anschluß am Raspberry ist unspektakulär, das Display wird einfach am GPIO Port an den Anschlüssen 1,3,5,7, und 9 angeschlossen. Laut einiger Foren kann das Display mit Kabeln am RPi angeschlossen werden, um es in einem Gehäuse besser plazieren zu können, die Kabel dürfen aber nicht zu lange sein. Im Zweifelsfall einfach ausprobieren.

Adafruit bietet auf seiner Webseite die entsprechenden Libarys und Beispiele an.

Als erstes die RPi.GPIO Libary und die Python Imaging Libary installieren:

sudo apt-get update
sudo apt-get install build-essential python-dev python-pip
sudo pip install RPi.GPIO 

sudo apt-get install python-imaging python-smbus

Nun den aktuellen Adafruit SSD1306 python library Code und die Beispiele runterladen und installieren:

sudo apt-get install git
git clone https://github.com/adafruit/Adafruit_Python_SSD1306.git
cd Adafruit_Python_SSD1306
sudo python setup.py install

Wenn noch nicht geschehen, I²C am Raspberry einschalten. An der Konsole

sudo raspi-config

eingeben und im Kofifgurationsfenster Punkt 5 Interfacing Options und anschließend Punkt P5 I2C auswählen und I²C einschalten. Mit

sudo i2cdetect -y 1

kontrollieren, ob das Display gefunden wird. Es muss die Adresse 0x3c angezeigt werden.

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- 3c -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

Im Verzeichnis Adafruit_Python_SSD1306 kann das erste Beispiel aufgerufen werden

sudo python examples/stats.py

Default Screen


Am Display sollte nun die IP-Adresse, die CPU-Last, der Arbeitsspeicher und die Festplattenauslastung angezeigt werden.

Eigene Anzeige erstellen

Je nach Bedarf kann die Anzeige nach eigenen Bedürfnissen angepasst werden. Im folgenden Script ist eine Anzeige des Servernamens, der IP-Adresse und des Datums mit Uhrzeit beschrieben.

sudo nano /home/pi/script/status.py
status.py
# Partial Copyright (c) 2017 Adafruit Industries
#
# Author: Tony DiCola & James DeVito
import time
 
import Adafruit_GPIO.SPI as SPI
import Adafruit_SSD1306
 
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
 
import subprocess
 
# Raspberry Pi pin configuration:
RST = None     # on the PiOLED this pin isnt used
 
# 128x32 display with hardware I2C:
disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST)
 
# Initialize library.
disp.begin()
 
# Clear display.
disp.clear()
disp.display()
 
# Create blank image for drawing.
# Make sure to create image with mode '1' for 1-bit color.
width = disp.width
height = disp.height
image = Image.new('1', (width, height))
 
# Get drawing object to draw on image.
draw = ImageDraw.Draw(image)
 
# Draw a black filled box to clear the image.
draw.rectangle((0,0,width,height), outline=0, fill=0)
 
# Draw some shapes.
# First define some constants to allow easy resizing of shapes.
padding = -2
top = padding
bottom = height-padding
 
# Move left to right keeping track of the current x position for drawing shapes.
x = 0
 
# Load default font.
font = ImageFont.load_default()
 
# Alternatively load a TTF font.  Make sure the .ttf font file is in the same directory as the python script!
# Some other nice fonts to try: http://www.dafont.com/bitmap.php
# font = ImageFont.truetype('Minecraftia.ttf', 8)
 
while True:
 
    # Draw a black filled box to clear the image.
    draw.rectangle((0,0,width,height), outline=0, fill=0)
 
    # Shell scripts for system monitoring from here : https://unix.stackexchange.com/questions/119126/command$
    cmd = "hostname -I | cut -d\' \' -f1"
    IP = subprocess.check_output(cmd, shell = True )
    cmd = "hostname"
    Hostname = subprocess.check_output(cmd, shell = True )
    cmd = "date +'%d.%m.%Y  %H:%M UTC'"
    Datum = subprocess.check_output(cmd, shell = True )
 
    # Write four lines of text.
 
    draw.text((x, top),      "Mailserver - " + str(Hostname),  font=font, fill=255)
    draw.text((x, top+12),   "  " +  str(IP),  font=font, fill=255)
    draw.text((x, top+25),   str(Datum),  font=font, fill=255)
 
    Display image.
    disp.image(image)
    disp.display()
    time.sleep(.1)

Mit diesem Script wird die folgende Seite angezeigt:

status.py beim Booten laden

Wenn das Script beim Booten des RPi geladen werden soll, ist ein Eitrag in der rc.local notwendig.

sudo nano /etc/rc.local 

In der rc.local muss die Zeile

sudo python /home/pi/script/status.py  &

am Ende der Datei vor der Zeile exit 0 eingetragen werden. Nicht das kaufmännische & am Ende der Zeile vergessen, damit das Script im Hintergund ausgeführt wird.

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
 
# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi
 
sudo python /home/pi/script/status.py  &
 
exit 0

Nach dem nächsten Reboot wird das Script ausgeführt.

Quellenverzeichnis

disp_oled_ep0060.txt · Zuletzt geändert: 2020/02/02 22:32 von administrator