Friday, August 10, 2012

Cloning Bootable Linux Flash Drives

I'm forever forgetting the Linux command to clone Linux flash drives. It comes in handy because it's really easy to accidentally trash the file system if your PC crashes or you accidentally perform and un-graceful shut-down. Keep many and make frequent back-up of your work in progress if you're doing on a flash drive!

Here's the command:

    dd if=/dev/sdc of=/dev/sdd

This is a very powerful command! You will need to invoke the power of sudo! Make sure that if the PC has a hard drive that you don't point the "of" (output file) at it our you'll wipe out what every operating system was on it. Remember that you also need to run this from a drive that isn't your input or output flash drive. For this reason you may need as many as three USB devices to complete this operation. 

Do not run this command verbatim! First do an ls to determine what your current drives are, and make sure to keep them out of this command. Then plug in the source drive, and use ls to find its name (i.e. sdc). Next plug in the destination drive, and again determine its name. Only then run the command. You will find that a 4GB flash drive may take quite a while to copy.

Wednesday, July 4, 2012

Getting the time date stamp into the file name

We just returned from a two week trip to China on which we took 3000 photos with four different cameras. Now we need select a hundred or so to put on our web page. The problem is that most image previewers sort by file name. This means the photos are each grouped by camera.


require 'rubygems'
require 'exifr'

mypix = Dir.glob(ARGV[0] +"/*.{jpg,JPG}")
    somepix = mypix.sort_by \
        { |a| EXIFR::JPEG.new(a).exif.to_hash[:date_time_original] }
    somepix.each do |pic_file| 
 regex = /[\/\.]/
 system("mv " + pic_file + " " + 
            pic_file.to_s.split(regex)[0] + "/" +
            pic_file.to_s.split(regex)[0] + "_" + 
            EXIFR::JPEG.new(pic_file).exif.to_hash[:date_time_original].strftime("%Y-%m-%d_%H%M%S") + 
            ".jpg")

end

The run the app

$ruby rename_pix.rb trip12a


And now you can sort your pix.

Fixing Mini-blinds - Fishing Supplies to the Rescue

Many of us have mini-blinds or honeycomb shades at home. These are usually special-ordered and custom cut to fit your windows. For the most part you get the same style for the whole house.

When part of the mechanism on one of our honeycomb shades broke, the left side hung lamely when I pulled the cord to let some light into the bedroom. Our shades are old, and I'm pretty sure that I wouldn't be able to find an exact match if I wanted to replace it. I thought to myself, "this is going to be a real mess to fix." Then it occurred to me that someone had to assemble these shades in the first place, and I'm at least as handy as that person.



I found the there were end caps that easily snapped off, and a plastic cover that slid away to reveal a drawstring. the drawstring had become severed after years of sliding over the bale that held the shades in the open position. The drawstring was a tough, finely braided, but small diameter cord. I took a sample of the drawstring to a craft store that sold DIY drapery supplies. They had something similar, but it was far to big to fit through the bale mechanism. Then I went to a big-box home improvement store - no dice. Where have I seen this stuff before? Fishing!

I went to a fishing supply store and showed them the cord and they said, "We've got something like that. It's a little thiner and if you don't mind the white and green color, it's 6 cents per foot".

"Yeah? Gimme a hundred feet then"!

I believe the stuff is called braided fishing line. I got a lot of it because:

a) it was cheap.
b) who knows when another shade will break?
c) it looked like really useful stuff to have at the workbench.


I pulled all the old string out of the shade. Holding the shade closed, I was easily able to thread the line through the honeycomb fabric using a rather large needle. I replaced all three lines, threaded them through the locking bale and re-hung the shade. I pulled the cord and the shade lifted smoothly and evenly. I snapped the cords to the left to latch the shade in the up position, released the cords, and the shade fell on windowsill with a bang. The cords were too thin for the locking bale! As a quick and dirty fix, I cut a strip of metal from a can and wrapped it through the bale to make it just a little thicker. I had to be careful that none of the rough edges would rub and abrade the strings. If I ever re-do this I'm going to cut some thin pieces of plastic and crazy-glue them inside the bale instead.

Now our honeycomb shades let the sun shine through again. I've used the fishing line on mini-blinds too, and even though the mechanism is quite different, I found it works quite well.

Saturday, February 25, 2012

Improving Battery Tester Accuracy

In earlier experiments I found that when powering the Arduino from USB, the battery voltage measurements were all over the place. This is because when the Arduino uses its power supply as the reference voltage for analog conversion, and the power supply isn't precise, neither is the analog measurement precise. It turns out USB power can vary +/-10% and still be in spec.

Accuracy can be improved by adding a reference voltage. I used an LM431Adjustable Precision Zener Shunt Regulator. By the way, when looking for spec sheets it's best to go to the manufacturer's site or to a vendor site, otherwise you may end up in the land of pop-up hell or you may run the risk opening malevolent PDFs.

Normally one would connect the reference output to Vref, but since my battery voltages are over over 2.5 volts, I connected it to one of the analog inputs such as A0.

I then applied the measured reference voltage as a correction factor to each measurement.

batt01 = (float)a1 * 2.5 / (float)a0;

This resulted in much more stable measurements, but unfortunately it didn't improve the repeatably. I repeated charged and discharged the batteries and although some generalizations about each battery can be made, I doesn't seem like it will be possible to compare a battery from one set to a battery in another set. I want to be able to do this so I can regroup the batteries into better performing sets.

Better, but still not good enough. To be able to compare batteries from different sets I would need to see the discharge curve for each battery overlay itself in these test runs. Perhaps the problem is related to the charger. I'll try a different charger and repeat the experiment.

One final improvement I want to make is to the resolution of the graphed data. I'm rounding off the results to to two decimal places. The A-D converter has twice that resolution, so in the future I'll increase the output to three decimal places.

The source code for this project can be found on GitHub as usual.