DIY PC Stats Monitor
DIY Arduino Project with Python to Display your PC's stats (CPU temp, CPU load, GPU temp and GPU load)
Components and supplies
1
LCD 3,5" Screen
1
Arduino UNO
Apps and platforms
1
Arduino IDE
Project description
Code
PC_Stats_Monitor
arduino
1#include <UTFTGLUE.h> //use GLUE class and constructor 2#include <string.h> 3UTFTGLUE myGLCD(0,A2,A1,A3,A4,A0); //initiate screen 4 5void setup() 6{ 7 randomSeed(analogRead(0)); 8 Serial.begin(115200); 9 Serial.setTimeout(1); 10 11 //Print the basic layout of the Display 12 myGLCD.InitLCD(0); 13 myGLCD.setFont(BigFont); 14 15 myGLCD.setColor(255, 255, 255); 16 myGLCD.fillRect(0, 0, 319, 479); 17 18 myGLCD.setBackColor(255, 255, 255); 19 myGLCD.setColor(0, 0, 0); 20 21 myGLCD.print("CPU TEMP: ", LEFT, 30); 22 myGLCD.print("C ",300, 30); 23 24 myGLCD.print("CPU LOAD: ", LEFT, 30+135); 25 myGLCD.print("%", 300, 30+135); 26 27 myGLCD.print("GPU TEMP: ", LEFT, 30+135*2); 28 myGLCD.print("C", 300, 30+135*2); 29 30 myGLCD.print("GPU LOAD: ", LEFT, 30+135*3); 31 myGLCD.print("%", 300, 30+135*3); 32 33 myGLCD.setFont(SevenSegNumFont); 34 35 //End of the basic layout 36} 37 38void loop() 39{ 40 String x= " "; 41 42 char str[20]; 43 char s[2] = ","; 44 char *token; 45 int aux[4]; 46 47while (!Serial.available()); //Get data from the PC 48 x = Serial.readString(); 49 x.toCharArray(str,20); 50 token = strtok(str, s); //Conversions to split the string and get the data of each field. 51 int i=0; 52 while( token != NULL ) { 53 aux[i]=atoi(token); 54 i++; 55 token = strtok(NULL, s); 56 } 57 58 59 String cputemp, cpuload, gputemp, gpuload; 60 String bcputemp, bcpuload, bgputemp, bgpuload; 61 62 bcputemp=cputemp; 63 cputemp=String(aux[0]); 64 if( bcputemp != cputemp){ //If the new read is different do a new print 65 if(aux[0]<10){ //Due to limitations of my screen I can't afford to clear the string so I print a "0" if the temp is lower than 10 66 cputemp="0"+cputemp; 67 } 68 if(aux[0]==100){ //Same but for 3 digits 69 cputemp="99"; 70 } 71 myGLCD.print(cputemp, 200, 30-10); 72 } 73 74 bcpuload=cpuload; 75 cpuload=String(aux[1]); 76 if( bcpuload != cpuload){ 77 if(aux[1]<10){ 78 cpuload="0"+cpuload; 79 } 80 if(aux[1]==100){ 81 cpuload="99"; 82 } 83 myGLCD.print(cpuload, 200, 30+135*1-10); 84 } 85 86 bgputemp=gputemp; 87 gputemp=String(aux[2]); 88 if( bgputemp != gputemp){ 89 if(aux[2]<10){ 90 gputemp="0"+gputemp; 91 } 92 if(aux[2]==100){ 93 gputemp="99"; 94 } 95 myGLCD.print(gputemp, 200, 30+135*2-10); 96 } 97 98 bgpuload=gpuload; 99 gpuload=String(aux[3]); 100 if( bgpuload != gpuload){ 101 if(aux[3]<10){ 102 gpuload="0"+gpuload; 103 } 104 if(aux[3]==100){ 105 gpuload="99"; 106 } 107 myGLCD.print(gpuload, 200, 30+135*3-10); 108 } 109 110 111 delay (1000); 112}
Python Script
python
More info in my github: https://github.com/bykape/Stat_Screen_Monitor
1#main Python script 2 3import GPUtil 4import psutil 5import wmi 6import math 7import serial 8import time 9 10 11arduino = serial.Serial(port='COM8', baudrate=115200, timeout=.1) #open serial port 12 13def write_read(x): #function to send data to the arduino board 14 arduino.write(bytes(x,'utf-8')) 15 16 17while 1: 18 w = wmi.WMI(namespace="root\\OpenHardwareMonitor") #open Hardware Monitor 19 temperature_infos = w.Sensor() 20 value=0 21 22 for sensor in temperature_infos: #Search for the CPU temperature. Due to lack of OpenHardwareMonitor limitation with 11th Intel Family I only get the core 0 temp. 23 #It is posible to do the mean of all your processor temps. 24 if sensor.SensorType==u'Temperature' and sensor.Parent==u'/lpc/nct6798d' and sensor.Name==u'Temperature #1': 25 value=sensor.Value 26 27 gpu = GPUtil.getGPUs()[0] 28 29 A = str(round(value,2)) 30 B = str(round(psutil.cpu_percent(),2)) 31 C = str(round(gpu.temperature,2)) 32 D = str(round(gpu.load*100,2)) 33 finalString = A + "," + B + "," + C + "," + D + "\ 34" #Create the String to send to arduino 35 write_read(finalString) #calling the send function
PC_Stats_Monitor
arduino
1#include <UTFTGLUE.h> //use GLUE class and constructor 2#include <string.h> 3UTFTGLUE myGLCD(0,A2,A1,A3,A4,A0); //initiate screen 4 5void setup() 6{ 7 randomSeed(analogRead(0)); 8 Serial.begin(115200); 9 Serial.setTimeout(1); 10 11 //Print the basic layout of the Display 12 myGLCD.InitLCD(0); 13 myGLCD.setFont(BigFont); 14 15 myGLCD.setColor(255, 255, 255); 16 myGLCD.fillRect(0, 0, 319, 479); 17 18 myGLCD.setBackColor(255, 255, 255); 19 myGLCD.setColor(0, 0, 0); 20 21 myGLCD.print("CPU TEMP: ", LEFT, 30); 22 myGLCD.print("C ",300, 30); 23 24 myGLCD.print("CPU LOAD: ", LEFT, 30+135); 25 myGLCD.print("%", 300, 30+135); 26 27 myGLCD.print("GPU TEMP: ", LEFT, 30+135*2); 28 myGLCD.print("C", 300, 30+135*2); 29 30 myGLCD.print("GPU LOAD: ", LEFT, 30+135*3); 31 myGLCD.print("%", 300, 30+135*3); 32 33 myGLCD.setFont(SevenSegNumFont); 34 35 //End of the basic layout 36} 37 38void loop() 39{ 40 String x= " "; 41 42 char str[20]; 43 char s[2] = ","; 44 char *token; 45 int aux[4]; 46 47while (!Serial.available()); //Get data from the PC 48 x = Serial.readString(); 49 x.toCharArray(str,20); 50 token = strtok(str, s); //Conversions to split the string and get the data of each field. 51 int i=0; 52 while( token != NULL ) { 53 aux[i]=atoi(token); 54 i++; 55 token = strtok(NULL, s); 56 } 57 58 59 String cputemp, cpuload, gputemp, gpuload; 60 String bcputemp, bcpuload, bgputemp, bgpuload; 61 62 bcputemp=cputemp; 63 cputemp=String(aux[0]); 64 if( bcputemp != cputemp){ //If the new read is different do a new print 65 if(aux[0]<10){ //Due to limitations of my screen I can't afford to clear the string so I print a "0" if the temp is lower than 10 66 cputemp="0"+cputemp; 67 } 68 if(aux[0]==100){ //Same but for 3 digits 69 cputemp="99"; 70 } 71 myGLCD.print(cputemp, 200, 30-10); 72 } 73 74 bcpuload=cpuload; 75 cpuload=String(aux[1]); 76 if( bcpuload != cpuload){ 77 if(aux[1]<10){ 78 cpuload="0"+cpuload; 79 } 80 if(aux[1]==100){ 81 cpuload="99"; 82 } 83 myGLCD.print(cpuload, 200, 30+135*1-10); 84 } 85 86 bgputemp=gputemp; 87 gputemp=String(aux[2]); 88 if( bgputemp != gputemp){ 89 if(aux[2]<10){ 90 gputemp="0"+gputemp; 91 } 92 if(aux[2]==100){ 93 gputemp="99"; 94 } 95 myGLCD.print(gputemp, 200, 30+135*2-10); 96 } 97 98 bgpuload=gpuload; 99 gpuload=String(aux[3]); 100 if( bgpuload != gpuload){ 101 if(aux[3]<10){ 102 gpuload="0"+gpuload; 103 } 104 if(aux[3]==100){ 105 gpuload="99"; 106 } 107 myGLCD.print(gpuload, 200, 30+135*3-10); 108 } 109 110 111 delay (1000); 112}
Downloadable files
Schematics
Quite simple
Schematics

Schematics
Quite simple
Schematics

Comments
Only logged in users can leave comments