Tag Archive: Python

Analog RAM and CPU Meters: Update

So I finally found time to fiddle with the CPU and RAM meters again today. Between Uni assignments and The Witcher 2, I haven’t really had much time for hacking, but after finishing The Witcher 2, I had to do something to procrastinate.

So I sat down and wrote a little Python script to grab the current CPU load and RAM usage. To do this, a module needed to be imported into the script. WMI. Windows management instrumentation. Other given modules are also needed. For example, serial and time. So we can actually TALK to the Arduino. You know, I hear that’s handy for what I’m doing…


As you can see, I’m sending the data as a string of characters, with a begin and end byte.

So, I’ve got the data, and I’m pushing it to the Arduino, now all I need to do is get the Arduino to do something with it! Remember those bytes I put in between the data bytes? Yep. Let’s use those to tell the micro controller what data packet is going to which display.
Basically, on Serial.available > 0, we check the byte, if it’s the byte that precedes the CPU byte, we set a flag as 1, if it’s the byte that precedes the RAM byte, we set the flag as 0, if it’s the byte at the end of the stream, do nothing, we don’t need that data. Ultimately I could remove it, but I like having the option for letting the micro controller know that the transmission is finished, but I digress. With any other byte, we check the flag and output the value to the corresponding meter. Simple.

Arduino Source

I originally tried to be all fancy like and send it in 2 data packets with the Most significant nibble of each byte in the first packet, then the least significant byte as the second packet. Basically multiplexing the data. For no real reason but to try and implement something I had learnt in my communications theory class. Well, as you can see, that fell through. The Python script managed to encode and send the data, but for the life of me I couldn’t get the Arduino to decode the data. I’ll probably keep fiddling, but for now, it’s working.


The left meter is RAM and the right is CPU. You can also see where I’m working on the SD card interface.
The CPU output is quite jumpy because the CPU load is changing all the time, I’m working on some action smoothing methods that I can implement on the Arduino, just something else I need to work on.

The final product plan is a mounted set of monitors with LED backlighting and a custom back planes. As you can see, I’m not really measuring mA, so I was planning on scanning in the current back planes and photoshooping some new ones that suit my project, just to give it that finished look.

Yeah I know, I’m avoiding the SD interface. I’m a little daunted by it honestly. But to be fair, I’m avoiding a lot of things, aka, uni work. So on that note, I leave you. Enjoy this quick update!


If you are a faithful reader, you might remember way back to my first post, my server. Now. That server was based on VB 6.0 and, honestly, a really really bad piece of code. So. I decided to completely re-write it in Python script.
Handy little thing python. Cross platform, easy flow control. The moment I got that server working, I knew that this was the way to do it.
To gain serial port control and the ability to import Media Monkey I had to install a couple of other libraries. Pyserial and pywin32.

Source code.

It basically waits for a connection on a specific port. Once it has gotten it, it will poll the serial port for new data and check if the current playing song has changed. When it receives data, it will act correspondingly.
As you can see I have set an escape case, the character “e”. This allows the server to close the connection and wait for a new connection. This allows us to shut down the remote without having the server still listening on the port. If the remote is turned off and then on again without sending the escape character, the remote will not reconnect to the server because the serial port is already open.

All in all, a handy little script that can be modified for any serial comms and Windows interaction.

Next, the final product! Excited? I am.