"Task Man": DIY Hardware Resource Monitor W/ Graphs!
by maxybar88 in Circuits > Computers
115 Views, 1 Favorites, 0 Comments
"Task Man": DIY Hardware Resource Monitor W/ Graphs!
This is a guide for building a Task Manager style resource monitor called "Task Man" using an rp2040 microcontroller and a SSD1306 OLED display. I came up with this idea when I wanted to see my CPU and GPU Utilization of my computer without having to open a new window, taking me out of the immersion of my fullscreen gaming experience.
Features:
- Graphs: 4 graphs tracking CPU, GPU, network, and disk performance, along with side bar showing ram utilization.
- Optional Button: to cycle through fullscreen graphs of individual statistics, and power off the device.
- Auto Power Off: when data isn't received for 3 seconds.
How It Works:
A python script runs on startup and collects data using the psutil library. It then sends this over a COM port through USB to the physical device, an rp2040 based microcontroller connected to a SSD1306 OLED display, to be graphed in real time!
Drawbacks:
- Currently does not support AMD or Intel graphics cards, only Nvidia.
- Untested on Mac or Linux, but should work. Check psutil docs for more info.
Extra:
Keep in mind that I am no expert in any of this. I have created something that I use every day, and I hope to share it with you. Some of methods I use are probably 'incorrect'. However, I hope that does not undermine this project, or prevent you from taking inspiration from this, and then doing it the 'right' way. This is a peer to peer guide. NOT teacher to student.
For the 'Build a Tool' contest, I am 16 years old, and a student of Franklin High School in Portland, Oregon.
Supplies
- Computer with supported OS and Nvidia graphics card
- Microcontroller more powerful than an Arduino UNO (Not enough ram) I used a "Waveshare rp2040-zero" from AliExpress
- SSD1306 Display, supports 128x64 and 128x32
- Optional: headers to plug in button and:
- unused pc case switch
- button with female connector to plug in
- Suitable case
- you will have to make this yourself, or leave it open!
- USB-C Cable
- Soldering iron
Estimated cost: $5-$10 dollars.
My cost: $9 with shipping.
Prototype Hardware
The first step I recommend is to prototype the physical circuit. For a microcontroller, I recommend using an rp2040 based MCU, although a Mega2560 or an ESP32 would likely work as well.
Requirements:
- SSD1306 OLED display connected to appropriate pins on microcontroller.
- Optional button from any digital pin to gnd (I used a digital output to supply ground).
Code Microcontroller
- Download the latest release source code from the github repo and unzip the file.
- If using windows and it is desired, download the exe file as well. This file will likely trigger antivirus, but it was made using pyinstaller.
- Open the .ino file in the Arduino IDE.
- You might need to install the required libraries through the library manager.
- If you are using a rp2040 board you will need to use a port. I use arduino-pico by Earle Philhower. Installation Guide
- Change any configuration variables or definitions you want:
- Pins:
- If not using a button, choose an unused pin.
- If using a board that does not require manual i2c pin assignment, comment out lines 7,8,93, and 94.
- Use lines 15 and 16 to set certain pins high or low, allowing you to solder the display directly to four digital pins, and then use two of them for vcc and gnd... or leave empty.
- Timing: If desired, change the timing (all in milliseconds) of the board.
- BOUNCE is the debounce duration.
- HOLD is the time required holding the button to turn the device off.
- TIMEOUT is the amount of time to wait for new data until automatically powering off.
- OLED parameters: width, height, and i2c address.
- 128x64 and 128x32 will work, 128x64 looks much nicer.
- The i2c address should be 0x3C or 0x3D.
- Upload!
Testing:
To test, open the serial monitor and send a message like: <C98|G34|M32|D50|U3|R210|W123|>
When you send it, you should see the data appear on screen as shown in the photo, if it does, you're ready to move on to the python program! If not, check that the display is properly connected, the correct i2c address is used, and the serial communication is functioning properly.
If using a button, you can press it to cycle through screens, hold it to power it off, and the press it again to turn back on.
Python Program
- In the previously downloaded folder from the github repo, open up the .pyw file in IDLE or your preferred development environment.
- Use the requirements.txt file to install the dependencies.
- Run the command in cmd: pip install -r requirements.txt
- I think the correct way to do this is something about a virtual environment but I'm a beginner to that 🤷♂️
- Open the config file in a text editor like notepad, and enter your config info:
- Line 1: Serial port
- Line 2: Update period (in seconds)
- Line 3: GPU index (usually zero)
- Line 4: Disk read maximum speed (MB/s) (Maximum speeds are the level that the top of the graph is, any value above this will get clipped to the top.)
- Line 5: Disk write maximum speed (MB/s)
- Line 6: Download maximum speed (Mbps)
- Line 7: Upload maximum speed (Mbps)
- Line 8: Disk name (Usually PhysicalDrive0) or 'ALL' in order to take the sum of all disk activity. Use psutil.disk_io_counters(perdisk=True) in the IDLE shell to decide on a disk if not using 'ALL'.
- Now run the program, you should see the data in the shell, and also on the OLED screen.
- You will likely get an error "nvml.dll not found":
- create a folder NVSMI in C:\Program Files\NVIDIA Corporation\
- Then copy nvml.dll from C:\Windows\System32 to C:\Program Files\NVIDIA Corporation\NVSMI
- OPTIONAL: If desired, package the python file into an exe using pyinstaller.
- Alternatively, you can use the .pyw file, or download the .exe file from github.
- Run the command: pyinstaller Task_Man.pyw -F
- The exe file will be in the dist folder.
- Now put all the files in a folder. I put this folder in my documents folder. Ensure you have:
- Task_Man.pyw
- replace with Task_Man.exe if created in optional previous step
- Task_Man_Config.txt
- TM.ico
- The remaining files can stay here as well.
- Create a shortcut to the .pyw/.exe file
- Place this shortcut in %AppData%\Microsoft\Windows\Start Menu\Programs\Startup
- This makes the program run on startup.
- When the program runs, a tray icon will appear. In order to stop the program, right click the tray icon, and and click Stop Task Man
- In order to start the program after stopping it, double click the .pyw/.exe file.
Assemble
- Begin by soldering together all the components.
- I unfortunately do not have the plans for my original CNC milled wooden enclosure. You will have to design and create your own case.
- Plug it in an you are done!
I hope that you consider creating this project. I would be happy to answer any questions you have in the comments.