CPU and MEMORY monitor
The Arduino sketch receives the data from a PC and displays it on 3.2 inch TFT LCD.
The arduino displays
- CPU Core Activity as percentage bars with green, orange and red statuses.
- The overall processor activity as a chronological graph that continually wraps back to the start (red bar denotes current position).
- Used memory as a chronological graph that continually wraps back to the start (red bar denotes current position).
- Date and Time.
- System up time.
The data is sent to the Arduino from either the C# or a Python apps (see the the source code in the repository)
Arduino Sketch (SystemStats.ino)
The sketch was written for an Arduino MEGA with a 3.2 Inch 320 X 480 TFT LCD Display Module.
The graphics were rendered using the UTFT Library
In the arduino source code the line UTFT myGLCD(HX8357B,38,39,40,41); may require changing depending on your TFT screen.
Here is is good youtube video outlining how to get the 3.2inch TFT working with UTFT https://www.youtube.com/watch?v=sNvRhkkOxaY
I got my Arduino MEGA (Clone) and screen from bangood.com for 20 euro.
This project would work even better with an arduino due as the faster processor would facilitate more refreshes per second resulting in smoother CPU core bars.
The Python app was created so this project would work on multiple platforms.
I have tested the Python app on Ubuntu only but it should work on other platforms as it used the psutils library
Psutils currently supports Linux, Windows, OSX, Sun Solaris, FreeBSD, OpenBSD and NetBSD.
You may have to change the line port = '/dev/ttyACM0' in the python script if your Arduino is using a different port (on windows it would be COM3 or whatever).
You might have to run this script as sudo on linux to allow access to the serial ports.
The C# app was created because this is my main working language and it was pretty straight forward.
I have tested this on Win 10, Win 7 and Win XP.
Its a console app but the class that does all the work is abstracted into a seperate class StatsMonitor. It would be easy to convert the app to run as a service.
To compile this code you will have to reference the System.Management library as this project uses some wmi queries to retrieve % used memory.
The app takes the serial port as a command line argument. e.g. com3.
The data transfer protocol
The data block starts with the character }
Next sequence of bytes are sent one for every CPU core, each byte has a value between 0 and 100, a | character is sent to signal the end of the CPU core data.
the rest of the data stream has the following structure
<PROCESSOR % as 1 BYTE> | <MEMORY % as 1 BYTE> | <TIME AS CHAR SEQUENCE> | <DATE AS CHAR SEQUENCE> | <UPTIME AS CHAR SEQUENCE> ~
The '~' character represents the end of the data stream and the arduino updates the screen.
The C# or Python app waits for a response from the arduino and then send the next status up date.
Typically with the MEGA I am getting around two updates a second. You would probably get more with a DUE.