USB CPU and Memory Monitor
![SAM_0835.JPG](/proxy/?url=https://content.instructables.com/F31/WTB4/GQOCAQOO/F31WTB4GQOCAQOO.jpg&filename=SAM_0835.JPG)
![SAM_0834.JPG](/proxy/?url=https://content.instructables.com/F8A/GQ8Z/GQOCAQOI/F8AGQ8ZGQOCAQOI.jpg&filename=SAM_0834.JPG)
![SAM_0836.JPG](/proxy/?url=https://content.instructables.com/FU0/OWQD/GQOCAQP4/FU0OWQDGQOCAQP4.jpg&filename=SAM_0836.JPG)
![SAM_0839.JPG](/proxy/?url=https://content.instructables.com/F75/461V/GQOCAQPC/F75461VGQOCAQPC.jpg&filename=SAM_0839.JPG)
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.
What Do You 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.
The Circuit
![CPUmonitorsch.png](/proxy/?url=https://content.instructables.com/FBY/MSMD/GQOCAQGD/FBYMSMDGQOCAQGD.png&filename=CPUmonitorsch.png)
![CPUmonitorbrd.png](/proxy/?url=https://content.instructables.com/FL8/FJ6I/GQOCAQG2/FL8FJ6IGQOCAQG2.png&filename=CPUmonitorbrd.png)
![CPUmonitorbrd2.png](/proxy/?url=https://content.instructables.com/F9A/IHS2/GQOCAQG7/F9AIHS2GQOCAQG7.png&filename=CPUmonitorbrd2.png)
![SAM_0813.JPG](/proxy/?url=https://content.instructables.com/FQF/GYK4/GQOCAQO6/FQFGYK4GQOCAQO6.jpg&filename=SAM_0813.JPG)
![SAM_0809.JPG](/proxy/?url=https://content.instructables.com/F82/3B5T/GQOCAQNY/F823B5TGQOCAQNY.jpg&filename=SAM_0809.JPG)
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.
Programming
![programming.jpg](/proxy/?url=https://content.instructables.com/FX7/X58U/G9C6ZAMM/FX7X58UG9C6ZAMM.jpg&filename=programming.jpg)
![SAM_0819.JPG](/proxy/?url=https://content.instructables.com/F8U/PA51/GQOCAQOB/F8UPA51GQOCAQOB.jpg&filename=SAM_0819.JPG)
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.
The Python Script
![python-logo.png](/proxy/?url=https://content.instructables.com/F23/2RIA/GP2DLEP7/F232RIAGP2DLEP7.png&filename=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