Who doesn't like old technologies? For example, a Motorola cell phone as heavy as a brick and built to last centuries (literally)? I do like old stuff, my dear readers. That's why when one day I came across a cool looking (and rightly priced!) antique pressure gauge on eBay I bought it with very little hesitation. Presumably, gauges like this had been used on steamboats and locomotives. I had the idea to upgrade it to use this piece of ancient technology for modern purposes, specifically to measure my home internet bandwidth utilization.
This is what I got in the mail a few days later.
Not cool. I was not ready to hang this at my desk, being too ugly even for me, not to mention my wife. What I really wanted to see was a brass bezel and black body instead of this rusty bezel and gray rusty-dusty body. I desperately needed some magic and I found it at the local hardware store: sandpaper, paint remover, and spray paint!
After applying my newly acquired magic the gauge started to look much more appealing.
That was better, but I still needed a different kind of magic to make it measure something more useful for me than steam pressure. I thought about creating an application (running on the PC) to calculate bandwidth utilization and somehow send this information to the gauge via USB.
But how would I make the needle move? The answer came from China in form of the miniature RC servo. RC servos are typically used by hobbyists in radio-controlled models and robotic applications. It’s a perfect fit for this project because:
- It’s small, so it fits the gauge easily
- It needs 5V power supply (since I am planning to use USB and it provides 5V)
- It’s easy to control
Here is the downside - an RC servo needs a precise PWM
(Pulse Width Modulation) signal for positioning. PC/Windows was born to be almost useless for generating any precise timing/pulses, so I needed something else to generate it. I elected an Atmel AVR
microcontroller for this job. Why AVR? Simply because I've used it before, know this platform reasonably well, and love it (well, sort of). Unfortunately, the smallest/simplest AVR microcontroller I had planned to use didn't support USB communication, so I had to add a USB-to-serial converter to the mix since serial protocol is easy to implement even on the tiniest microcontrollers.
Now I am ready to put it all together:
- The PC runs a .NET application which calculates bandwidth utilization and sends it to the gauge. It sends the utilization as a percentage since the gauge is calibrated 0-100
- Inside the gauge, there is a USB-to-serial converter that talks to the AVR microcontroller via asynchronous serial communication (this is just a fancy term for serial port)
- The microcontroller converts the utilization percentage to the PWM signal and sends it to the RC servo
- The RC Servo controls the needle position utilizing parts from the original mechanism
Completed gauge with scale removed.
In the picture above: RC servo (blue thing, covered with whitish mass), USB to Serial adapter (green board), and microcontroller (small 8-pins chip, to the right of the green board).
Everything was mounted inside the gauge using my favorite method - glue gun (I am pretty sure Wikipedia knows a better term for it, but "glue gun" just sounds dangerous).
Now back to the .NET application. It turns out that it's very easy to read a whole bunch of the statistical data from my home wireless router because it supports SMNP protocol. SNMP is a standard network management protocol supported by most of the network devices (computers, routers, printers, etc.). It provides access to the device's internal status/variables/parameters.
The most important variables to me were sent/received byte counters. There is one set of counters (upload/download) per each Ethernet port (my router has 5 ports), but I cared only about the Ethernet port connected to my DSL modem. By querying these counters every second it's trivial to calculate upload/download speeds. However, in order to calculate bandwidth utilization, I also needed to know my maximum Internet upload/download. Speedtest.net is a hero of determination of true Internet speed.
Cool, I can calculate both the upload and download bandwidth utilization, but which one should I use for the gauge? I tried a few options and found out that I personally like a maximum between upload and download because it tells me when to expect web surfing bog-downs.
The .NET application interface is pretty simple, nothing fancy.
This is how completed gauge looks.
Thank you for reading my humble blog and have fun hacking the stuff.
Ah right, I forgot the video of the completed system, enjoy: