Skip to content

Instantly share code, notes, and snippets.

@raspberrytipsnl
Created March 6, 2017 13:36
Show Gist options
  • Save raspberrytipsnl/2385d0a0a8196b5f20bb6bec03b8fed2 to your computer and use it in GitHub Desktop.
Save raspberrytipsnl/2385d0a0a8196b5f20bb6bec03b8fed2 to your computer and use it in GitHub Desktop.
import time
import sys
import subprocess
import Adafruit_GPIO.SPI as SPI
import Adafruit_SSD1306
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
from time import sleep
# commandline instructies om de gegevens op te vragen
GET_LOADAVG_CMD = "grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage }'"
GET_TEMP_CMD = "/opt/vc/bin/vcgencmd measure_temp"
def run_cmd(cmd):
return subprocess.check_output(cmd, shell=True).decode('utf-8')
def write_load():
load = float ( run_cmd(GET_LOADAVG_CMD)[:-1] )
cpu = "CPU {:.2f}% \n".format(load)
draw.text((8, 7), cpu, font=font, fill=255)
def write_temp_mem():
cputemp = "TEMP {} C".format( run_cmd(GET_TEMP_CMD)[5:9] )
draw.text((8, 19), cputemp, font=font, fill=255)
disp = Adafruit_SSD1306.SSD1306_128_32(rst=24)
disp.begin()
disp.clear()
disp.display()
# Lege afbeelding voorbereiden
width = disp.width
height = disp.height
image = Image.new('1', (width, height))
draw = ImageDraw.Draw(image)
# Apple 2 font moet in dezelfde map staan als het script
font = ImageFont.truetype('Apple2.ttf', 8)
# loop voor het weergeven van de informatie
while True:
draw.rectangle((0,0,width-1,height-1), outline=1, fill=0)
write_load()
write_temp_mem()
disp.image(image)
disp.display()
sleep(3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment