Jan-04-2021, 11:22 AM
(This post was last modified: Jan-04-2021, 11:22 AM by redfirebrooks.)
Hello,
I began in python few month ago and wrote a script for a raspberry pi to display on a ssd1306 oled screen some informations.
Everyhting was fine but since few weeks the code does not run anymore.
I have this error each time I try to launch the script(but it used to work):
My code is
I began in python few month ago and wrote a script for a raspberry pi to display on a ssd1306 oled screen some informations.
Everyhting was fine but since few weeks the code does not run anymore.
I have this error each time I try to launch the script(but it used to work):
Error:pi@domoticz:~/scripts $ python /home/pi/scripts/simpletime01.py &
[1] 24405
pi@domoticz:~/scripts $ Traceback (most recent call last):
File "/home/pi/scripts/simpletime01.py", line 192, in <module>
display_info()
File "/home/pi/scripts/simpletime01.py", line 140, in display_info
disp.display()
File "build/bdist.linux-armv7l/egg/Adafruit_SSD1306/SSD1306.py", line 167, in display
File "build/bdist.linux-armv7l/egg/Adafruit_SSD1306/SSD1306.py", line 129, in command
File "build/bdist.linux-armv7l/egg/Adafruit_GPIO/I2C.py", line 116, in write8
File "build/bdist.linux-armv7l/egg/Adafruit_PureIO/smbus.py", line 256, in write_byte_data
IOError: [Errno 121] Remote I/O error
python /home/pi/scripts/nano time01.py^C
[1]+ Termine 1 python /home/pi/scripts/simpletime01.pyCoils someone help me to resolve this / understand why it suddenly stopped to work pleaseMy code is
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import datetime,time
import subprocess
import Adafruit_GPIO.SPI as SPI
import Adafruit_SSD1306
import os
import locale
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
import RPi.GPIO as GPIO
# Set up GPIO with internal pull-up
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# Set et initialize OLED display
RST = None
disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST)
disp.begin()
disp.clear()
disp.display()
width = disp.width
height = disp.height
image = Image.new('1', (width, height))
draw = ImageDraw.Draw(image)
draw.rectangle((0,0,width,height), outline=0, fill=0)
padding = -2
top = padding
bottom = height-padding
x = 0
# Set fonts
font1 = ImageFont.truetype("/home/pi/scripts/Tahoma.ttf", 12)
font2 = ImageFont.truetype("/home/pi/scripts/Tahoma.ttf", 24)
font3 = ImageFont.truetype("/home/pi/scripts/Tahoma.ttf", 10)
prev_millis = 0
display = 0
# Define refresh delay
now = datetime.datetime.now()
nextSecond = now+datetime.timedelta(seconds=1)
nextSecondHalf = now+datetime.timedelta(seconds=.5)
# Define temperature
temp = os.popen("vcgencmd measure_temp").readline()
temperature = temp.replace("temp=","")
# Define WIFI signal
signal = os.popen("iwconfig wlan0|awk '/Link Quality/{split($2,a,\"=|/\");print int((a[2]/a[3])*100)\"%\"}'").readline()
signal_int = int(signal.replace("%",""))
#signal_int = os.popen("iwconfig wlan0|awk '/Link Quality/{split($2,a,\"=|/\");print int((a[2]/a[3])*100)}'").readline()
def display_time(temperature,signal,signal_int):
global font1, font2, font3
locale.setlocale(locale.LC_TIME, 'fr_FR.utf8')
current_time = time.strftime("%H:%M:%S")
current_date = time.strftime("%a %d %b %Y")
date = current_date.decode('utf-8')
draw.rectangle((0,0,width,height), outline=0, fill=0)
x = 0
draw.ellipse((x, 0 , x+8, 8), outline=255, fill=0)
x = 11
draw.ellipse((x, 0 , x+8, 8), outline=255, fill=0)
x = 22
draw.ellipse((x, 0 , x+8, 8), outline=255, fill=0)
x = 33
draw.ellipse((x, 0 , x+8, 8), outline=255, fill=0)
if int(signal_int) > 25:
x = 0
draw.ellipse((x+2, 2 , x+6, 6), outline=255, fill=255)
if int(signal_int) > 50:
x = 11
draw.ellipse((x+2, 2 , x+6, 6), outline=255, fill=255)
if int(signal_int) > 75:
x = 22
draw.ellipse((x+2, 2 , x+6, 6), outline=255, fill=255)
if int(signal_int) > 99:
x = 33
draw.ellipse((x+2, 2 , x+6, 6), outline=255, fill=255)
# font = font3
# x = (disp.width)-64-(string_width(font,signal))
# draw.text((x, top+12), signal, font=font3, fill=255)
font = font1
x = (disp.width)-(string_width(font,temperature))
draw.text((x, top), temperature, font=font1, fill=255)
font = font2
x = (disp.width/2)-(string_width(font,current_time)/2)
draw.text((x, top+16), current_time, font=font2, fill=255)
font = font1
x = (disp.width/2)-(string_width(font,date)/2)
draw.text((x, top+40),date, font=font1, fill=255)
disp.image(image)
disp.display()
def display_blank():
draw.rectangle((0,0,width,height), outline=0, fill=0)
disp.image(image)
disp.display()
def display_info():
global font1, font2, font3
draw.rectangle((0,0,width,height), outline=0, fill=0)
cmd = "hostname -I | cut -d\' \' -f1"
IP = subprocess.check_output(cmd, shell = True )
essid = os.popen("iwconfig wlan0|grep 'ESSID'|awk -F ' ' '{print $4}'").readline()
link_quality = os.popen("iwconfig wlan0 | grep 'Link' | awk -F ' ' '{print $1,$2}'").readline()
signal_level = os.popen("iwconfig wlan0 | grep 'Signal' | awk -F ' ' '{print $3,$4,$5}'").readline()
draw.text((x, top), str(essid), font=font1, fill=255)
draw.text((x, top+16), "IP: " + str(IP), font=font1, fill=255)
draw.text((x, top+30), str(link_quality), font=font1, fill=255)
draw.text((x, top+44), str(signal_level), font=font1, fill=255)
disp.image(image)
disp.display()
def display_info2():
global font1, font2, font3
draw.rectangle((0,0,width,height), outline=0, fill=0)
cmd = "hostname -I | cut -d\' \' -f1"
IP = subprocess.check_output(cmd, shell = True )
essid = os.popen("iwconfig wlan0|grep 'ESSID'|awk -F ' ' '{print $4}'").readline()
link_quality = os.popen("iwconfig wlan0 | grep 'Link' | awk -F ' ' '{print $1,$2}'").readline()
signal_level = os.popen("iwconfig wlan0 | grep 'Signal' | awk -F ' ' '{print $3,$4,$5}'").readline()
draw.text((x, top), str(essid), font=font1, fill=255)
draw.text((x, top+16), "IP: " + str(IP), font=font1, fill=255)
draw.text((x, top+30), str(link_quality), font=font1, fill=255)
draw.text((x, top+44), str(signal_level), font=font1, fill=255)
disp.image(image)
disp.display()
def string_width(fontType,string):
string_width = 0
for i, c in enumerate(string):
char_width, char_height = draw.textsize(c, font=fontType)
string_width += char_width
return string_width
while True:
now = datetime.datetime.now()
millis = int(round(time.time() * 1000))
if now > nextSecond:
temp = os.popen("vcgencmd measure_temp").readline()
temperature = temp.replace("temp=","")
signal = os.popen("iwconfig wlan0|awk '/Link Quality/{split($2,a,\"=|/\");print int((a[2]/a[3])*100)\"%\"}'").readline()
signal_int = int(signal.replace("%",""))
nextSecond = now+datetime.timedelta(seconds=1)
if((millis - prev_millis) > 300):
# Cycle through different displays
if(not GPIO.input(18)):
display += 1
if(display > 2):
display = 0
prev_millis = int(round(time.time() * 1000))
if(display == 0):
display_time(temperature,signal,signal_int)
elif(display == 1):
display_info()
elif(display == 2):
display_blank()
# Turn off the display after a delay
if((millis - prev_millis) > 600000):
display = 2
prev_millis = int(round(time.time() * 1000))
time.sleep(0.1)
