Last active
September 1, 2015 07:09
-
-
Save imrehg/338824a63de21a82eb1a to your computer and use it in GitHub Desktop.
System monitoring with 16x2 LCD screen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" System monitoring with a Grove LCD RGB Backlight, connected to | |
the present machine over I2C | |
""" | |
from __future__ import division | |
# the following library is from https://github.com/youngage/grove-lcd | |
import display | |
from smbus import SMBus | |
import psutil | |
import time | |
d = display.Display(SMBus(2)) # Adjust the I2C bus number to your case | |
block = chr(255) | |
while True: | |
# Get Readings | |
cpu = psutil.cpu_percent(interval=0) | |
cpublockcount = int(round(cpu / 100 * 8)) | |
cpublocks = cpublockcount * block + (8-cpublockcount) * " " | |
mem = psutil.virtual_memory().percent | |
memblockcount = int(round(mem / 100 * 8)) | |
memblocks = memblockcount * block + (8-memblockcount) * " " | |
# Set colours | |
r = int(cpu/100.0 * 255) | |
b = int(mem/100.0 * 255) | |
g = 255 - max(r, b) | |
# Display data | |
d.color(r, g, b) | |
d.move(0, 0) | |
d.write("CPU:%3d%%%s" %(cpu, cpublocks)) | |
d.move(0, 1) | |
d.write("MEM:%3d%%%s" %(mem, memblocks)) | |
time.sleep(0.1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment