Skip to main content

3 Hour Hacks: Part 1

Intro



I am planning a small series of 3 hour hacks. Each hack will be allocated a 3 hour window only. There are penalties for failing to adhere to the rules. Points will start at 100 and count down. Rules are as follows:

  1. Research is time free. It does not count towards the total time. (learning should be free, right :) )
  2. Must not go outside of 3 hours. -10 points for every 30 mins outside of this.
  3. Must use all items available. Must not purchase any items for hack. -20 points for each item purchased. (Sub-note: You are allowed to purchase the first item, the one to be hacked only)
  4. Hack must be funny, witty, clever, convoluted, impractical, or otherwise absurd.
  5. The device must serve a purpose. It must have a use. -20 for no valid use!
  6. The hack doesn't have to be nice or finished. -1 point for each stupid build mistake.
  7. Upper limit of £20 for all parts in hack, even if from junkbox. Does not include initial purchase. Estimate prices, but be conservative :). -5 points per £/$ over this.

Hack 1) Hard Drive CPU/RAM meter.


Meter Front Top section


Meter Front

It's a bit blurry!

Meter Side


Meter Back

Why

I have a giant pile of junk that I was going to throw away. I instead decided to make absurd hacks and give them away as gifts.


The first hack will be a hard disk. I think there will be a few hard disk hacks along the way as I seem to have a few.

What I made

Breaking into a harddisk and taking a look gave me a few ideas. The read head assembly is a nice place to start as it has a simple voice coil drive to move it up and down. What this means is as you induce more current in the head's coil, it generates a larger magnetic field. As the field increases, it pushes away from the fixed magnet making it move. The movement is more or less linear with voltage.

Using a few things I had on hand, I generated a PWM pulse train from an AVR that feeds into the coil via an RC filter. The RC filter allows the pulses to be smoothed to something more usable, and buffers the current to allow enough juice to move the head.

I also attached a couple of LEDs onto the chassis of the drive so that I could show which stat it was displaying.

This works in Linux and Windows with the help of some hacked and borrowed scripts, libusb, and a good SDK with the OSIF

What is the OSIF?

I will come clean, it is something I sell. I also have the plans, schematic, PCB and code available to download should you want to make your own.
The OSIF is a USB to I2C/SPI/Serial/GPIO device. It has a software USB stack running on an atmega8 an a basic chunk of code to control the outputs.

You can grab one/find out more here OSIF

The software section details where to get the stuff.

What I needed

1x OSIF
1x Hard drive
1x 1K variable Resistor
1x 1uF capactitor
1x 8x2 0.1" connector and pins
1x length of green wire
1x length of black wire
1x Plasterboard will tie thing.

Tools

Soldering iron, multimeter, optionally scope (I didn't actually need this, but was handy), screwdrivers, glue gun (double sided tape will do)

How

- Overview
I changed the OSIF firmware to allow PWM output on one of the pins. Using the Atmega8 Timer counter2 I drove PB3 to pulse. The chosen prescaler was 1 and a pwm rate at 12mhz clock.
The shared library libOSIFlib was updated with a new pwm function that allows the rate to be set. A simple test shell script was written to write a series of values to the port. It worked on the first try! I was 1 hour in. Going well.

After trying a few suitable resistors for the RC filter, I decided to use a variable resistor. This can then be calibrated to the correct value to allow proper scaling of the input and output values from the head. Much time was spent on getting a good value for the capacitor and resistor. The voice coil requires an irritating amount of current in order to move properly. A tradeoff is made with the value of 1uF for the cap. I settled on 1uF for the cap, but you might want to try some other values to see what is best for your drive. I had other polarised caps at 0.47uF and 0.63uF, but they didn't manage to power the head enough to move in the bottom end of the scale. Best visual results were from changing the PWM clock to /8 prescaler, but the audible whine was too much.


Schematic

The schematic is fairly basic, and shows what pins go to where on the OSIF. The only really important pin is PB3 (pin 8/MOSI on OSIF) which connects to the head.

- Construction guide for moving head
* Dismantle a hard drive. Take off the top cover.
* Remove the circuit board
* Look for the ribbon connector to the head assembly. Find the pins and send 3~v to them until the head shoots around. Note these pins and the polarity
* Solder the cap over the pins. Noting the polarity from before, make sure you solder the electrolytic cap in with the + to the head's ground.
* Solder the one of the outside pins from the pot to the head + line
* Solder the middle wiper pin on the pot to some red wire.
* Solder the head - to some black wire
* Connect the head + and - to the following OSIF pins: HEAD+ | MOSI (8) HEAD- | GND(3)
* Optionally- Screw the plasterboard wall tie to the hard drive.
* Hot glue the OSIF to the hard drive.

That is it.

The LEDs were added as an afterthought considering I had 1:30min to spare with this much completed.

The OSIF is capable of using the spare pins as GPIOs. I decided to glue some green leds to the hard drive to add more display output. This allows the software to toggle between states with visual output of the current state.

- Construction guide for LED portion

* Remove the motor assembly and leave the drive with a large hole. (you can put the leds wherever)
* Glue the leds to the hard drive. Make sure the legs are accessible and not touching.
* Solder the LEDs GND pins together (the flat side on the LED is GND)
* Solder a 330 ohm resistor to each LED
* Solder a wire to each resistor
* Attach the wires to OSIF pins:- LED1+ | SDA(1) LED2+ | SCL(4) GND | GND(3)

Easy.

Software

The OSIF hardware comes with a dll library (OSIFdll.dll) which was modified to allow pwm values to be sent.
Windows:
A quick and dirty C# .NET application was written that pinvokes the OSIFdll.dll and writes the new pwm value.
The software was quickly extended to allow control over the LEDs via the two GPIOs. Two windows performance counters were used to get the current CPU load and the total memory. A counter was added to toggle between the two automatically.

Linux:
A script was borrowed from Paul Colby's website that gets the total CPU load in a bash shell. This was modiified to send the pwm command to the OSIF testapp program.

# by Paul Colby (http://colby.id.au), no rights reserved ;)

PREV_TOTAL=0
PREV_IDLE=0

while true; do
  CPU=(`cat /proc/stat | grep '^cpu '`) # Get the total CPU statistics.
  unset CPU[0]                          # Discard the "cpu" prefix.
  IDLE=${CPU[4]}                        # Get the idle CPU time.

  # Calculate the total CPU time.
  TOTAL=0
  for VALUE in "${CPU[@]}"; do
    let "TOTAL=$TOTAL+$VALUE"
  done

  # Calculate the CPU usage since we last checked.
  let "DIFF_IDLE=$IDLE-$PREV_IDLE"
  let "DIFF_TOTAL=$TOTAL-$PREV_TOTAL"
  let "DIFF_USAGE=(1000*($DIFF_TOTAL-$DIFF_IDLE)/$DIFF_TOTAL+5)/10"
  echo -en "\rCPU: $DIFF_USAGE%  \b\b"

  let "DIFF_PCT=(((1000*$DIFF_USAGE)/100)*255)/1000"
  ./testapp pwm $DIFF_PCT
  # Remember the total and idle CPU times for the next check.
  PREV_TOTAL="$TOTAL"
  PREV_IDLE="$IDLE"

  # Wait before checking again.
  sleep 1
done

Windows Software is a C# App. It's pretty cheesy with some seriously sloppy coding practices!

Cheesy App

The CPU load is obtained from the windows performance counter class. This is then scaled to a 0-255 8 bit range, and sent to the OSIF.
RAM is calculated using the info from this StackOverflow question http://stackoverflow.com/questions/105031/c-how-do-you-get-total-amount-of-ram-the-computer-has

The Auto Toggle feature toggles between the 2 (working) LEDs on the drive. One is for CPU, the other RAM. You can set the toggle frequency on the num up/down box.

You can grab the app and the OSIF windows driver Here(if you must)

You can grab the source for all of the project by going to the CVS:

http://www.openservo.com/viewcvs/OpenServo/Interfaces/OpenServo_InterFace/?root=cvs

The Version_2 branch contains the proper firmwares.

Here is a video of it toggling. I also set the output to CPU and use questionable methods to test the load (shaking a window about)

Afterthoughts

If I had more time on this hack, I would have driven the output through a transistor so the AVR pin is not loaded too heavily. At the moment we rely on the cap to power the head, and it gives a horrible non linear result for the values. Meh.

If you notice the photos have 3 LEDs. I didn't check them before I glued them in and one of them was a dud. I had to disconnect it due to time constraints.

The c# application designed to make my friends life easier was compiled with the "Any CPU" setting in Visual Studio. My friend has a 64 bit machine so this meant it was running as a native 64 bit app. Problem is that the OSIFdll uses 32 bit memory maps, so it crashes hard. A quick recompile after setting to x86 solved this.

I added a larger pointer using card. This had the effect of taking the head mechanism off it's finely balanced setting. I had to counterbalance the addition with a nut and some glue.

I was going to mill a nice panel for it, but I ran out of time :( I migh revisit this project and make a nice steampunk effect CPU/x monitor.

You can build this using an arduino. The software doesn't actually support using an arduino's serial interface, as the OSIF has a software USB stack onboard. I don't have an arduino and hope to never have to purchase one, so I used what I had.

Points. So... How well did I do?

100 Points to start with!

Time: I did pretty well with this. The total hack time was 2:56 so 4 minutes to spare. 0 point penalty
Cost: No additional parts needed. In face it only needs 9 components inclusing the OSIF and drive :) 0 point penalty
Stupid mistakes: I counted 3. 1) Gluing LEDs on without testing they worked first. One didnt. -1 point. 2) I found a bug in the OSIF core the took me far too long to track down. Worked in Linux but not Windows. Bug fixed, but deserved -1 penalty. 3) I didn't take into account the cardboard changing the head balance. I had to counter it with some glue and a nut. Made it less accurate. -1

Total: -3 points: 97 Points overall.

Not bad for my first 3 hour hack!

I urge everyone to make their own 3 hour hack. It was extremely fun!