Skip to content

Instantly share code, notes, and snippets.

@44670
Created April 17, 2017 06:44
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 44670/a653bf13932780f802bcb1cd816c5fde to your computer and use it in GitHub Desktop.
Save 44670/a653bf13932780f802bcb1cd816c5fde to your computer and use it in GitHub Desktop.
lcd
#/usr/bin/python
#
# Written for PyUSB 1.0 (w/libusb 1.0.3)
#
import usb, sys # 1.0 not 0.4
import time
import psutil
sys.path.append("..")
from arduino.usbdevice import ArduinoUsbDevice
def updateLcd(lines):
theDevice.write(0xf2)
for line in lines:
for ch in line:
theDevice.write(ord(ch))
for i in range(0, 16 - len(line)):
theDevice.write(ord(' '))
theDevice.write(ord('\n'))
def setBacklight(v):
if (v) :
theDevice.write(0xf1)
else :
theDevice.write(0xf0)
try:
theDevice = ArduinoUsbDevice(idVendor=0x16c0, idProduct=0x05df)
except:
sys.exit("No DigiUSB Device Found")
setBacklight(1)
while True:
time.sleep(5)
cpuUsage = int(psutil.cpu_percent(interval=None))
mem = psutil.virtual_memory()
memUsage = int(mem.used / float(mem.total) * 100)
cpuUsage = min(cpuUsage, 99)
memUsage = min(memUsage, 99)
updateLcd(["CPU:%2d%% Mem:%2d%%" % (cpuUsage, memUsage), time.strftime("%m-%d %H:%M %a", time.localtime())])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment