Skip to content

Instantly share code, notes, and snippets.

@imrehg
Last active September 1, 2015 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imrehg/338824a63de21a82eb1a to your computer and use it in GitHub Desktop.
Save imrehg/338824a63de21a82eb1a to your computer and use it in GitHub Desktop.
System monitoring with 16x2 LCD screen
""" 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