Okey nice das hat jetzt funktioniert
Aber es stimmt etwas mit der OLED Ausgabe nicht.
es steht vorallem ein b'
In etwa so
b'IP-Adresse'
b'0.00'
b'MEM 57%'
b'23.0' (temperatur) b'44%' (Ram)
Okey nice das hat jetzt funktioniert
Aber es stimmt etwas mit der OLED Ausgabe nicht.
es steht vorallem ein b'
In etwa so
b'IP-Adresse'
b'0.00'
b'MEM 57%'
b'23.0' (temperatur) b'44%' (Ram)
Wie sieht der Code jetzt aus?
#!/usr/bin/python3
# Copyright (c) 2017 Adafruit Industries
# Author: Tony DiCola & James DeVito
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import os
import subprocess
import time
import Adafruit_SSD1306
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
SKRIPTPFAD = os.path.abspath(os.path.dirname(__file__))
# Raspberry Pi pin configuration:
RST = None # on the PiOLED this pin isnt used
# Note the following are only used with SPI:
DC = 23
SPI_PORT = 0
SPI_DEVICE = 0
# Beaglebone Black pin configuration:
# RST = 'P9_12'
# Note the following are only used with SPI:
# DC = 'P9_15'
# SPI_PORT = 1
# SPI_DEVICE = 0
# 128x32 display with hardware I2C:
# disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST)
# 128x64 display with hardware I2C:
disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST)
# Note you can change the I2C address by passing an i2c_address parameter like:
# disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST, i2c_address=0x3C)
# Alternatively you can specify an explicit I2C bus number, for example
# with the 128x32 display you would use:
# disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST, i2c_bus=2)
# 128x32 display with hardware SPI:
# disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST, dc=DC, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=8000000))
# 128x64 display with hardware SPI:
# disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST, dc=DC, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=8000000))
# Alternatively you can specify a software SPI implementation by providing
# digital GPIO pin numbers for all the required display pins. For example
# on a Raspberry Pi with the 128x32 display you might use:
# disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST, dc=DC, sclk=18, din=25, cs=22)
# 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(os.path.join(SKRIPTPFAD, 'Montserrat-Light.ttf'), 12)
font2 = ImageFont.truetype(os.path.join(SKRIPTPFAD, 'fontawesome-webfont.ttf'), 14)
font_icon_big = ImageFont.truetype(os.path.join(SKRIPTPFAD, 'fontawesome-webfont.ttf'), 20)
font_text_big = ImageFont.truetype(os.path.join(SKRIPTPFAD, 'Montserrat-Medium.ttf'), 19)
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…e-disk-usage-and-cpu-load
cmd = "hostname -I | cut -d\' \' -f1 | head --bytes -1"
IP = subprocess.check_output(cmd, shell=True)
cmd = "top -bn1 | grep load | awk '{printf \"%.2f\", $(NF-2)}'"
CPU = subprocess.check_output(cmd, shell=True)
cmd = "free -m | awk 'NR==2{printf \"MEM: %.2f%%\", $3*100/$2 }'"
MemUsage = subprocess.check_output(cmd, shell=True)
cmd = "df -h | awk '$NF==\"/\"{printf \"HDD: %d/%dGB %s\", $3,$2,$5}'"
cmd = "df -h | awk '$NF==\"/\"{printf \"%s\", $5}'"
Disk = subprocess.check_output(cmd, shell=True)
cmd = "vcgencmd measure_temp | cut -d '=' -f 2 | head --bytes -1"
Temperature = subprocess.check_output(cmd, shell=True)
# Icons
draw.text((x, top), chr(61931), font=font2, fill=255)
draw.text((x + 50, top + 52), chr(61888), font=font2, fill=255)
draw.text((x, top + 52), chr(62152), font=font2, fill=255)
draw.text((x, top + 15), chr(62171), font=font_icon_big, fill=255)
draw.text((18, top), str(IP), font=font, fill=255)
draw.text((x + 22, top + 12), str(CPU), font=font_text_big, fill=255)
draw.text((x, top + 36), str(MemUsage), font=font, fill=255)
# draw.text((x, top+39), str(Disk), font=font, fill=255)
draw.text((x + 66, top + 52), str(Disk), font=font, fill=255)
draw.text((x + 10, top + 52), str(Temperature), font=font, fill=255)
# Display image.
disp.image(image)
disp.display()
time.sleep(5)
Display More
Bitte lesen und Daten nachreichen
Wie frage ich nach Hilfe?
Bei Fragen zum Programmieren poste immer Deinen kompletten Code. Formatiere diesen im Editor als Codeblock:
Ein Klick auf "Quellcode" ermöglicht es, die Programmiersprache auszuwählen.
Handelt es sich um eine Compilersprache, so ist es hilfreich wenn du deinen verwendeten Compiler aufführst.
okey ich habe jetzt jede stelle wo str(memUsage) oder so ähnlich ist ersetzt. Es funktioniert einwandfrei.
Habe weiter gemacht wo ich mit Hofei aufgehört habe und es funktioniert super beim Hochfahren.
Danke allen die, die Geduld aufbrachten, mir und meinen kryptischen Angaben zu helfen.
Und damit ich es nicht vergesse und Leute die das Selbe Problem haben wie ich, fasse ich mal die gelösten Probleme zusammen:
zuerst haben wir fehlende module für python3 installiert mit :
pip3 install --user Adafruit_SSD1306
Anschließend noch ein aus unerklärlichen Gründen fehlendes Modul installiert mit:
pip3 install --user Adafruit_BBIO Adafruit_GPIO
Danach gab mir Hofei mir die richtigen Schriftarten:
(338,42 kB, 1 Mal heruntergeladen, zuletzt: Vor 8 Stunden)
(Wo genau findet man die oder findet man heraus das, dass die richtigen sind?)
Danach Script verbesserungen von @__deets__ :
str(MemUsage)
str(IP)
str(CPU)
str(DIsk)
str(Temperature)
Müssen ersetzt werden durch:
IP.decode("ascii")
CPU.decode("ascii")
MemUsage.decode("ascii")
Disk.decode("ascii")
Temperature.decode("ascii")
Und zu guter letzt von Hofei die Anleitung für die Unit Datei:
Im Terminal:
sudo nano /etc/systemd/system/test_oled.service
Und das hier als Inhalt einfügen
[Unit]
Description=OLED Test
[Service]
Type=simple
ExecStart=/usr/bin/python3 /home/pi/test/test_oled.py
User=pi
[Install]
WantedBy=multi-user.target
Am schluss noch diese Befehle ausführen:
sudo systemctl daemon-reload
sudo systemctl start test_oled.service
sudo systemctl enable test_oled.service
sudo reboot
Danke nochmal das ihr mir unter die Arme gegriffen habt
(Wo genau findet man die oder findet man heraus das, dass die richtigen sind?)
War bei mir auch nur Treffer über die Suchmaschine die wohl glücklicher waren als deine.
Das das ganze dann nicht mehr test_oled heißen muss, sondern nach deinem Belieben ist klar oder?
Achso. Hast du sowas wie Python3 Schriftarten geschrieben?
Ja aber das ist mir nicht so wichtig. Hauptsache es funktioniert 😁
Nein, einfach die 3 Namen der Schriftarten
Hallo Leute,
mein Raspberry pi ist abgeschmiert und mein backup war wohl fehlerhaft, so das ich alles wieder einrichten muss.
Ich habe zwar alles gemacht wie wir es damals taten jedoch habe ich folgende Fehlermeldung
Traceback (most recent call last):
File "Datenanzeige.py", line 73, in <module>
disp.begin()
File "/home/pi/.local/lib/python3.7/site-packages/Adafruit_SSD1306/SSD1306.py", line 148, in begin
self._initialize()
File "/home/pi/.local/lib/python3.7/site-packages/Adafruit_SSD1306/SSD1306.py", line 247, in _initialize
self.command(SSD1306_DISPLAYOFF) # 0xAE
File "/home/pi/.local/lib/python3.7/site-packages/Adafruit_SSD1306/SSD1306.py", line 129, in command
self._i2c.write8(control, c)
File "/home/pi/.local/lib/python3.7/site-packages/Adafruit_GPIO/I2C.py", line 114, in write8
self._bus.write_byte_data(self._address, register, value)
File "/home/pi/.local/lib/python3.7/site-packages/Adafruit_PureIO/smbus.py", line 327, in write_byte_data
self._device.write(data)
OSError: [Errno 121] Remote I/O error
Display More
Kann ich dich nochmal um Hilfe bitten Hofei ?
#!/usr/bin/python3
# Copyright (c) 2017 Adafruit Industries
# Author: Tony DiCola & James DeVito
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import os
import subprocess
import time
import Adafruit_SSD1306
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
SKRIPTPFAD = os.path.abspath(os.path.dirname(__file__))
# Raspberry Pi pin configuration:
RST = None # on the PiOLED this pin isnt used
# Note the following are only used with SPI:
DC = 23
SPI_PORT = 0
SPI_DEVICE = 0
# Beaglebone Black pin configuration:
# RST = 'P9_12'
# Note the following are only used with SPI:
# DC = 'P9_15'
# SPI_PORT = 1
# SPI_DEVICE = 0
# 128x32 display with hardware I2C:
# disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST)
# 128x64 display with hardware I2C:
disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST)
# Note you can change the I2C address by passing an i2c_address parameter like:
# disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST, i2c_address=0x3C)
# Alternatively you can specify an explicit I2C bus number, for example
# with the 128x32 display you would use:
# disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST, i2c_bus=2)
# 128x32 display with hardware SPI:
# disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST, dc=DC, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=8000000))
# 128x64 display with hardware SPI:
# disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST, dc=DC, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=8000000))
# Alternatively you can specify a software SPI implementation by providing
# digital GPIO pin numbers for all the required display pins. For example
# on a Raspberry Pi with the 128x32 display you might use:
# disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST, dc=DC, sclk=18, din=25, cs=22)
# 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(os.path.join(SKRIPTPFAD, 'Montserrat-Light.ttf'), 12)
font2 = ImageFont.truetype(os.path.join(SKRIPTPFAD, 'fontawesome-webfont.ttf'), 14)
font_icon_big = ImageFont.truetype(os.path.join(SKRIPTPFAD, 'fontawesome-webfont.ttf'), 20)
font_text_big = ImageFont.truetype(os.path.join(SKRIPTPFAD, 'Montserrat-Medium.ttf'), 19)
while True:
# Draw a black filled box to clear the image.
draw.rectangle((0, 0, width, height), outline=0, fill=0)
cmd = "hostname -I | cut -d\' \' -f1 | head --bytes -1"
IP = subprocess.check_output(cmd, shell=True)
cmd = "top -bn1 | grep load | awk '{printf \"%.2f\", $(NF-2)}'"
CPU = subprocess.check_output(cmd, shell=True)
cmd = "free -m | awk 'NR==2{printf \"MEM: %.2f%%\", $3*100/$2 }'"
MemUsage = subprocess.check_output(cmd, shell=True)
cmd = "df -h | awk '$NF==\"/\"{printf \"HDD: %d/%dGB %s\", $3,$2,$5}'"
cmd = "df -h | awk '$NF==\"/\"{printf \"%s\", $5}'"
Disk = subprocess.check_output(cmd, shell=True)
cmd = "vcgencmd measure_temp | cut -d '=' -f 2 | head --bytes -1"
Temperature = subprocess.check_output(cmd, shell=True)
# Icons
draw.text((x, top), chr(61931), font=font2, fill=255)
draw.text((x + 50, top + 52), chr(61888), font=font2, fill=255)
draw.text((x, top + 52), chr(62152), font=font2, fill=255)
draw.text((x, top + 15), chr(62171), font=font_icon_big, fill=255)
draw.text((18, top), IP.decode("ascii"), font=font, fill=255)
draw.text((x + 22, top + 12), CPU.decode("ascii"), font=font_text_big, fill=255)
draw.text((x, top + 36), MemUsage.decode("ascii"), font=font, fill=255)
# draw.text((x, top+39), str(Disk), font=font, fill=255)
draw.text((x + 66, top + 52), Disk.decode("ascii"), font=font, fill=255)
draw.text((x + 10, top + 52), Temperature.decode("ascii"), font=font, fill=255)
# Display image.
disp.image(image)
disp.display()
time.sleep(5)
Display More
Das kann an einer falschen oder fehlerhaften Verkabelung liegen. Bitte prüf das zunächst.
Danke jetzt funktioniert alles wieder.
Komm mir sehr dumm vor.
Aus reinem wissendurst heraus, von wo hast du da rausgelesen das es ein Verkabelungsfehler ist ?
OSError: [Errno 121] Remote I/O error
Das hab ich in die Suchmaschine getippt und mir die Suchergebnisse angeschaut
Ich verstehe.
Ich habe mir die ersten paar Zeilen gelesen und ging davon aus es ein Script Fehler ist oder wieder ein Modul fehlt.
Aufjedenfall