6 de enero de 2021

RPi4 System monitoring with python3 in lcd display 20x4

Python3 script:

#!/usr/bin/python3

#Librerias
from time import sleep
from lcd_display import lcd
from gpiozero import CPUTemperature

import psutil

lcd = lcd()

temp1 = str(CPUTemperature())
temp2 = temp1.split("=")     
temp3 = "CPU.temp: "+temp2[1][:-1] + " C"

cpu1 = "CPU.load: " + str(psutil.cpu_percent()) + " %"
ram1 = "RAM.use: " + str(psutil.virtual_memory().percent) + " %"


while True:
    #print ("temp:",temp3)
    #print ("cpu: ", cpu1)
    #print ("ram: ", ram1)
    #print ("------------------")
    lcd.clear()
    sleep(0.3)
    lcd.display_string("--- RPi4.monitor ---",1)
    lcd.display_string(temp3,2)
    lcd.display_string(cpu1,3)
    lcd.display_string(ram1,4)
    sleep(15)

  

Bibliografía:

https://raspberrypi.stackexchange.com/questions/85415/how-to-directly-get-cpu-temp-in-python

https://stackoverflow.com/questions/276052/how-to-get-current-cpu-and-ram-usage-in-python

No hay comentarios:

Publicar un comentario