Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Gavin
Published

Computer Running Status Monitor

Use Raspberry Pi RP2040 & WizFi360 to display your computer status(AIDA64) on the screen(GC9A01)

IntermediateFull instructions provided2,055
Computer Running Status Monitor

Things used in this project

Hardware components

WizFi360-EVB-Pico
WIZnet WizFi360-EVB-Pico
×1
RP2040
Raspberry Pi RP2040
×1
GC9A01 1.28 Inch Round LCD
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Computer_Running_Status_Monitor_Schmatic

Code

Computer Running Status Monitor(AIDA64)

Arduino
/*
 WizFi360 example: WebClient

 This sketch connects to google website using a WizFi360 module to
 perform a simple web search.
*/

#include "WizFi360.h"
#include <RingBuf.h>
#include <ArduinoJson.h>

#include <Arduino_GFX_Library.h>
Arduino_GFX *tft = create_default_Arduino_GFX();

RingBuf<uint8_t, 3072> myBuffer;

typedef enum 
{   
  connect_to_pc = 0,
  send_aida64_request,
  display_status, 
}STATE_;
STATE_ currentState;

/* Wi-Fi info */
 char ssid[] = "wiznet";       // your network SSID (name)
 char pass[] = "KUvT5sT1Ph";   // your network password

char Aida64IpAddr[] = "10.0.1.42";

uint8_t data_now;
uint8_t value;  
bool json_start;
String json_String; 
bool find_n;

int16_t Cpu_frequency;
int16_t memory_usage;
int16_t GPU_Frequency;
uint8_t ip_uint8[4];
int8_t Temperature;

int status = WL_IDLE_STATUS;  // the Wifi radio's status

// Initialize the Ethernet client object
WiFiClient client;
    
void setup() {
  // initialize serial for debugging  
  Serial.begin(115200);

  tft->begin();
  pinMode(22, OUTPUT); 
  digitalWrite(22, HIGH); 
  
  display_dashboard();       

  // initialize serial for WizFi360 module
  Serial2.setFIFOSize(3072);
  Serial2.begin(2000000);
  WiFi.init(&Serial2);

  // check for the presence of the shield
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue
    while (true);
  }
  
  // attempt to connect to WiFi network
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network
    status = WiFi.begin(ssid, pass);
  }
  Serial.println("Starting connection to server...");

//  while (!Serial) {
//    ; // wait for serial port to connect. Needed for native USB port only
//  }
  currentState = connect_to_pc;
}

void loop(){
  switch(currentState){
    case connect_to_pc:
       {
        // if you get a connection, report back via serial
        if (client.connect(Aida64IpAddr, 80)) {
          Serial.println("Connected to server");
          // Make a HTTP request
          client.println(String("GET /sse HTTP/1.1"));
          client.println(String("Host: ") + (String)Aida64IpAddr);
          client.println("Connection: close");
          client.println();
          data_now = 0;
          json_String = "";
        }
        currentState = send_aida64_request;
       }
      break;
      
    case send_aida64_request:
       {          
          while (client.available()) {
            myBuffer.push(client.read()); 
            data_now =1;
          }
          if(data_now)
          {
              json_start = false;
              while (myBuffer.pop(value)) {
                Serial.print((char)value);
                if(json_start)
                {
                  json_String += (char)value;
                }
                if(value == 10) //ascii "\n"
                {
                   if(find_n == true)
                   {
                      json_start = true;                       
                      find_n = false;
                   }
                   else
                   {
                      json_start = false;
                      find_n = true;
                   }                  
                }
                else
                {
                    find_n = false;
                }
            }
            Serial.println("json_String:");
            Serial.println(json_String);
            uint16_t dataStart = 0;
            uint16_t dataEnd = 0;
            String dataStr;
            //json_String = "data: Page0|{|}Simple1|CPU Frequency 998 MHz{|}Simple2|Memory Usage 43%{|}Simple3|GPU1 Usage 0%{|}Simple4|GPU2 Core Frequency 350 MHz{|}Simple5|IP Address 10.0.1.42/{|}Simple6|Motherboard Temperature 47{|}";
            dataStart = json_String.indexOf("CPU Frequency") + strlen("CPU Frequency");
            dataEnd = json_String.indexOf("MHz", dataStart);
            dataStr = json_String.substring(dataStart, dataEnd);
            Cpu_frequency = dataStr.toInt();
            Serial.print("CPU Frequency:");         
            Serial.print(Cpu_frequency);     
            Serial.println("MHz");   
            
            dataStart = json_String.indexOf("Memory Usage") + strlen("Memory Usage");
            dataEnd = json_String.indexOf("%", dataStart);
            dataStr = json_String.substring(dataStart, dataEnd);
            memory_usage = dataStr.toInt();
            Serial.print("Memory Usage:");         
            Serial.print(memory_usage);   
            Serial.println("%");             

            dataStart = json_String.indexOf("GPU Frequency") + strlen("GPU Frequency");
            dataEnd = json_String.indexOf("MHz", dataStart);
            dataStr = json_String.substring(dataStart, dataEnd);
            GPU_Frequency = dataStr.toInt();
            Serial.print("GPU frequency:");         
            Serial.print(GPU_Frequency);   
            Serial.println("MHz");
            
            dataStart = json_String.indexOf("Temperature") + strlen("Temperature");
            dataEnd = json_String.indexOf("C", dataStart);
            dataStr = json_String.substring(dataStart, dataEnd);
            Temperature = dataStr.toInt();  
            Serial.print("Temperature:");
            Serial.print(Temperature); 
            Serial.println("C");
            
            dataStart = json_String.indexOf("IP Address") + strlen("IP Address");
            dataEnd = json_String.indexOf("/", dataStart);
            dataStr = json_String.substring(dataStart, dataEnd);
            Serial.print("IP Address:");  
            Serial.print(dataStr);
            Serial.println("/");
            
            dataEnd = dataStr.indexOf(".", 0);
            ip_uint8[0] = (dataStr.substring(0, dataEnd)).toInt();
            Serial.println(ip_uint8[0]);
            dataStart = dataEnd+1;
            dataEnd = dataStr.indexOf(".", dataStart);
            ip_uint8[1] = (dataStr.substring(dataStart, dataEnd)).toInt();
            Serial.println(ip_uint8[1]);
            dataStart = dataEnd+1;
            dataEnd = dataStr.indexOf(".", dataStart);
            ip_uint8[2] = (dataStr.substring(dataStart, dataEnd)).toInt();
            Serial.println(ip_uint8[2]);
            dataStart = dataEnd+1;
            dataEnd = dataStr.indexOf(".", dataStart);
            ip_uint8[3] = (dataStr.substring(dataStart, dataEnd)).toInt();
            Serial.println(ip_uint8[3]);
            
            client.stop();
            delay(1000);
            data_now = 0;
            currentState = display_status;
          }
       }
      break;
      
    case display_status:
       {
          if(Temperature < 60)
          {
            tft->fillCircle(120,120,39,GREENYELLOW);
          }
          else if(Temperature < 85)
          {
            tft->fillCircle(120,120,39,ORANGE);
          }
          else
          {
            tft->fillCircle(120,120,39,RED);
          }
          tft->setTextColor(WHITE);
          tft->setCursor(85, 104);
          tft->setTextSize(4);
          tft->println(Temperature);
          tft->setCursor(140, 112);
          tft->setTextSize(3);
          tft->println("C");
          tft->setCursor(133, 99);
          tft->setTextSize(2);
          tft->println("o");
          
          tft->fillRect(43,30,70,25,ORANGE);
          tft->setTextColor(WHITE);
          tft->setCursor(43, 30);
          tft->setTextSize(3);
          tft->println(Cpu_frequency);
          
          tft->fillRect(132,30,35,25,GREEN);
          tft->setTextColor(WHITE);
          tft->setCursor(132, 30);
          tft->setTextSize(3);
          tft->println(memory_usage);
          
          tft->fillRoundRect(136,58,54,14,8,GREEN);
          uint8_t memory_uint8 = memory_usage*54/100;
          tft->fillRoundRect(136,58,memory_uint8,14,8,WHITE);
          
          tft->fillRect(31,165,80,25,YELLOW);
          if(GPU_Frequency>=1000)
          {
            tft->setCursor(43, 165);
          }
          else
          {
            tft->setCursor(58, 165);
          }            
          tft->setTextSize(3);
          tft->println(GPU_Frequency);

          tft->setTextSize(2);
          tft->setCursor(131, 168);
          tft->println(ip_uint8[0]);
          tft->setCursor(176, 168);
          tft->println(ip_uint8[1]);
          tft->setCursor(131, 191);
          tft->println(ip_uint8[2]);
          tft->setCursor(176, 191);
          tft->println(ip_uint8[3]);
            
          currentState = connect_to_pc;
       }
      break;

  }
}

void display_dashboard()
{
  tft->fillArc(120,120, 46, 120, 0, 90, OLIVE);
  tft->fillRect(150,123,100,27,WHITE);
  tft->setTextColor(OLIVE);
  tft->setCursor(175, 125);
  tft->setTextSize(3);
  tft->println("LAN");
  tft->fillArc(120,120, 117, 120, 0, 90, OLIVE); 
  tft->fillArc(120,120, 46, 48, 0, 90, OLIVE); 
  
  tft->fillArc(120,120, 46, 120, 90, 180, YELLOW);
  tft->fillRect(0,123,100,27,WHITE);
  tft->setTextColor(YELLOW);
  tft->setCursor(15, 125);
  tft->setTextSize(3);
  tft->println("GPU");
  tft->fillArc(120,120, 117, 120, 90, 180, YELLOW); 
  tft->fillArc(120,120, 46, 48, 90, 180, YELLOW); 

  tft->fillArc(120,120, 46, 120, 270, 360, GREEN);
  tft->fillRect(150,90,100,27,WHITE);
  tft->setTextColor(GREEN);
  tft->setCursor(175, 92);
  tft->setTextSize(3);
  tft->println("RAM");
  tft->fillArc(120,120, 117, 120, 270, 360, GREEN); 
  tft->fillArc(120,120, 46, 48, 270, 360, GREEN); 
  
  tft->fillArc(120,120, 46, 120, 180, 270, ORANGE); 
  tft->fillRect(0,90,100,27,WHITE);
  tft->setTextColor(ORANGE);
  tft->setCursor(15, 92);
  tft->setTextSize(3);
  tft->println("CPU");
  tft->fillArc(120,120, 117, 120, 180, 270, ORANGE); 
  tft->fillArc(120,120, 46, 48, 180, 270, ORANGE); 

  tft->drawRoundRect(126,165,45,20,10,WHITE);
  tft->drawRoundRect(127,166,43,18,9,WHITE);
  tft->drawRoundRect(126,188,45,20,10,WHITE);
  tft->drawRoundRect(127,189,43,18,9,WHITE);
  tft->drawRoundRect(171,165,45,20,10,WHITE);
  tft->drawRoundRect(172,166,43,18,9,WHITE);
  tft->drawRoundRect(171,188,45,20,10,WHITE);
  tft->drawRoundRect(172,189,43,18,9,WHITE);     
  
  tft->fillArc(120,120, 39, 45, 0, 360, WHITE);
  tft->fillCircle(120,120,39,GREENYELLOW);

  tft->setTextColor(WHITE);
  tft->setTextSize(3);
  
  tft->setCursor(43, 55);
  tft->println("MHz");  
  tft->setCursor(175, 30);
  tft->println("%");
  tft->setCursor(58, 192);
  tft->println("MHz"); 
  
  tft->drawRoundRect(132,55,60,20,10,WHITE);
  tft->drawRoundRect(133,56,58,18,9,WHITE);
}

Credits

Gavin

Gavin

24 projects • 23 followers
Make it Funny.

Comments