Datasheet

Using the subprocess class, python can utilize linux commands to access the Pi's system information. This
loop updates the screen at 10 times a second.
That's all there is to the stats.py code!
More Demos & Examples
You can check out our other examples in the example, just make sure to edit each one with nano animate.py for
example, and find the line that says:
and change it to:
and make sure that the configuration section where you choose which type of display, looks like this
while True:
# Draw a black filled box to clear the image.
draw.rectangle((0,0,width,height), outline=0, fill=0)
# Shell scripts for system monitoring from here : https://unix.stackexchange.com/questions/119126/command-to-display-memory-usage-disk-usage-and-cpu-load
cmd = "hostname -I | cut -d\' \' -f1"
IP = subprocess.check_output(cmd, shell = True )
cmd = "top -bn1 | grep load | awk '{printf \"CPU Load: %.2f\", $(NF-2)}'"
CPU = subprocess.check_output(cmd, shell = True )
cmd = "free -m | awk 'NR==2{printf \"Mem: %s/%sMB %.2f%%\", $3,$2,$3*100/$2 }'"
MemUsage = subprocess.check_output(cmd, shell = True )
cmd = "df -h | awk '$NF==\"/\"{printf \"Disk: %d/%dGB %s\", $3,$2,$5}'"
Disk = subprocess.check_output(cmd, shell = True )
# Write two lines of text.
draw.text((x, top), "IP: " + str(IP), font=font, fill=255)
draw.text((x, top+8), str(CPU), font=font, fill=255)
draw.text((x, top+16), str(MemUsage), font=font, fill=255)
draw.text((x, top+25), str(Disk), font=font, fill=255)
# Display image.
disp.image(image)
disp.display()
time.sleep(.1)
# Raspberry Pi pin configuration:
RST = 24
# Raspberry Pi pin configuration:
RST = None # PiOLED does not require reset pin
© Adafruit Industries https://learn.adafruit.com/adafruit-pioled-128x32-mini-oled-for-raspberry-pi Page 12 of 15