USB CPU and Memory monitor by janw
Featured
This little device shows you the CPU-load, how much physical and virtual memory is used. It shows this data per 10% on 3 ledbars. To do so it uses a VCP (Virtual COM Port), so that it can be connected to a PC via a USB connection to receive the data. Collecting the data and sending it to the device is done by a Python script.

By building my own onboard UART to USB converter and using SMD, I was able to make a relatively small device.

As always, comments and constructive criticisme are very much appreciated.



Step 1: What do you need?

To build this device, you will need:
  • An attiny2313 (datasheet)
  • A FT232RL Uart to USB converter (datasheet)
  • A Mini USB B connector
  • 3 x Kingbright DC-10EWA Ledbar(datasheet)
  • 10 x 150Ohm resistor
  • A ferrite bead
  • 2 x 100nF capacitor
  • A 10nF capacitor
  • A 4.7uF capacitor
  • A 6pin female header
  • Materials to make a PCB or some veroboard
  • A Programmer and compiler of your choice

To run the python script on your pc, you will need:

As always, you can use thru-hole components instead of smd parts.

Step 2: The circuit

CPUmonitorsch.png
CPUmonitorbrd.png
CPUmonitorbrd2.png
SAM_0813.JPG
SAM_0809.JPG
The circuit for this project is fairly easy. The USB part of the schematic can be found in the datasheet of the FT232RL as a USB-powered device with a microcontroller.

There are 2 connections from the FT232RL to the attiny2313: RX and TX (actually we need only The TX of the FT2313RL to the RX of attiny but connecting both lines makes debugging the microcontroller a lot easier).

The 3 ledbars are multiplexed. Their cathodes are connected to Port B, PortD.5 and PortD.6. The anodes are connected to Portd.2 - 4.

Miso, Mosi, SCK and Reset are connected to the header for programming together with VCC and GND.

Step 3: Programming

programming.jpg
SAM_0819.JPG
Once everything is soldered together and tested, you can load the actual code.

My code is written in BascomAVR so I added the original .bas-file here for other Bascom users and the code in a .txt-file as reference for C-programmers. I also added a .hex-file so that you can use it immediately.

The code receives the data via the USB and and multiplexes it into the 3 ledbars. The first one is the CPU-load, the second one is the physical memory and the last one is the virtual memory.

Step 4: The Python script

python-logo.png

'And now for something completely different...'

Indeed, a bit of Python.

I wrote the script in Python 2.7 while using PySerial and Psutil. You´ll need to download those 2 modules (links can be found in Step 1).

The script collects the CPU and Memory data via the Psutil-module and sends them over the virtual COM-port to the device.

_____________________________________________________________________________________________________________

import sys
import serial
import psutil
ser = serial.Serial(2)   #Change this according to your own COM-port. Remeber that the value you should add is one less than the      
                                     number of your COM-port.
while True:

q = psutil.cpu_percent(interval=1)
q = q/10
cpuload = '%.0f'%(q)
cpuload = 'a'+ cpuload
print cpuload
ser.write(cpuload)
q = psutil.phymem_usage()
mem = '%.0f'%(q.percent/10)
mem = 'b'+mem
print mem
ser.write(mem)
q = psutil.virtmem_usage()
virtmem = '%.0f'%(q.percent/10)
virtmem = 'c'+virtmem
print virtmem
ser.write(virtmem)
ser.close


 

cpumonitor.py504 bytes
AJC894 says: Jan 5, 2012. 9:58 AM
Can you run analog gauges from it in place of led bar graph.
janw (author) says: Jan 5, 2012. 10:28 AM
It is possible but you would need a totally different circuit. This ledbars have a connection for each led so the microcontroller chooses a led to light up according to the data. To drive analog gauges, you would need a digital to analog converter to drive the gauges.
MRedu says: Oct 28, 2011. 8:50 AM
This looks like a really cool gadget but it would be even cooler if it were bluetooth making it wireless. Is that possible?
janw (author) says: Oct 28, 2011. 11:32 AM
All kinds of wireless communication are possible but an USB cable is one of the easiest ways to communicate.
shabaki says: Aug 12, 2011. 1:45 PM
It would be awesome if you could make something like this to show the available/used memory on like an external hardrive
BodenM says: Aug 11, 2011. 8:22 AM
When you say "ferrite beads", do you mean this sort of thing: http://lairdtech.thomasnet.com/viewitems/ferrite-beads-on-wire/axial-lead-beads-power-filtering?forward=1
BodenM says: Aug 2, 2011. 5:22 AM
I'm looking at building this, so I have to ask if it is possible to have 2 cores showing independently, and just the free physical memory, instead of the setup shown here? And if so, could you please show me the changes I need to make (I'm a Python newbie)?
janw (author) says: Aug 2, 2011. 5:51 AM
I wrote you a code for the dual core setup. If you use this code with the same hex-file loaded in the microcontroller then the first bar is core1, the second is core2 and the last is your physical memory.

Good luck with your project.
BodenM says: Aug 2, 2011. 3:03 PM
Thank you!
stan4 says: Jul 30, 2011. 1:31 PM
Awesome work buddy.

You just inspired me, I was looking for something pretty to put on my computer, and be able to call it "mod".
janw (author) says: Jul 30, 2011. 1:41 PM
Thanks!
stan4 says: Jul 30, 2011. 1:52 PM
I read through everything in detail, also the documentation for psutil, I couldn't spot a "function" to read the GPU usage, can you give me a few tips? perhaps another library, thanks in advance.
janw (author) says: Jul 30, 2011. 1:57 PM
There are indeed no functions to readout the graphic processing unit. Psutil workks only for CPU, memory and disks.
Megrathea69 says: Jul 30, 2011. 10:58 AM
was thinking,maybe you could add another 2 led bars onto it for Hard Driv(C drive) temperature and fan speed readings as well.
janw (author) says: Jul 30, 2011. 12:32 PM
I is very easy to do indeed as there are still 2 free I/O pins on the Attiny. It can also be reprogrammed so that it gives the CPU-load of the 2 separate cores instead of the total CPU-load.
imBobertRobert says: Jul 30, 2011. 12:05 PM
good idea!
mathman47 says: Jul 29, 2011. 1:45 PM
Interesting application. I use several Widgets on a 2 monitor setup to monitor system activity so I don't really need this, but I'm glad you showed how to do it. It reminds me of why people climb mountains - because they are there. In this case, it is because you can. Great job. Exposure to the code is enough for me.
janw (author) says: Jul 29, 2011. 2:16 PM
Great to see that there are people who understand that 'because I can' is a great motivation to build stuff. Most of my projects are not really original or pretty but build to see whether I can build it and to learn from it.
bertus52x11 says: Jul 30, 2011. 3:01 AM
I wish I masterd these skills though...
janw (author) says: Jul 30, 2011. 3:08 AM
I learned these skills by building stuff like this and learning from it but you will never hear me say that I mastered them. Every day I learn new things and for me thats the main drive to keep building these little projects.
ynze says: Jul 29, 2011. 8:41 AM
I'm not very much into devices like this, but... What's the use of having a hardware device like this? Aren't there applications around that monitor data like this under Windows (I use a mac, and there are lots of "under the hood" apps available to do stuff like this...)

I'm pretty impressed by the simple fact that you can MAKE a device like this, anyway...

Cheers,

Y.
janw (author) says: Jul 29, 2011. 12:25 PM
There are indeed enough applications that can show you the data on the screen but when you run full-screen applications (like games), it can be handy to see the data without having to close your application.

It would be easier to read when you have an LCD but I had those bars for a while and so this was a nice opportunity to use them.
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!