Archive for December, 2008

Daily Yard Picture

5 November 2008

5 November 2008

Being that sort of bear, I took a picture of the back yard from our patio every day at 7 am wall-clock time. DST/EST changeovers threw their usual monkey wrenches into the mix, not to mention my lack of attention to the camera’s internal clock settings, but I eventually got 321 pictures of the same scene at more or less the same time of day.

That’s all well and good, but this is the movie age…

The plan: use ffmpeg or maybe mencoder to convert the still images into a movie.

  • Zero: copy the files to a unique subdirectory to protect the originals!
  • One: sort & rename by date
  • Two: resize images
  • Three: convert to a movie
  • Four: . . . profit!
10 November 2008

10 November 2008

I’d uploaded the files whenever I used the camera for something else, so the actual file dates were fairly well scrambled and didn’t correspond to the EXIF data inside the image file. Digikam‘s batch file rename operation can sort out the files in ascending order of EXIF date and rename them into something a bit more uniform & boring like 0001.jpg, which is vital for ffmpeg.

I used the camera’s full resolution, which is much too large for video, so I created Yet Another Subdirectory called Smaller to hold the reduced-size images. Imagemagick‘s convert program then squishes them down:

for f in *jpg ; do convert -verbose -resize 640x480 $f Smaller/$f; done

You can smash them even further to get a teeny postage-stamp movie for your media player.

Make the movie:

ffmpeg -r 3 -i %04d.jpg daily-3.mp4

The file specifier %04d must exactly match the filename sequence and a missing file will stop ffmpeg dead in its tracks. The file names coming out of your camera won’t work if they’re not exactly sequential, which is highly unlikely over the course of the year.

You can use mencoder:

mencoder "mf://*.jpg" -mf fps=10 -o daily800.avi -ovc lavc -lavcopts vcodec=msmpeg4v2:vbitrate=800

Then it’s showtime! I’d upload it, but you don’t have a need to know for our backyard activiites.

There, now, wasn’t that easy?

I didn’t actually figure all this out from first principles, of course. The basics are out there if you rummage around for a while with the obvious keywords.

Memo to self: affix a stable camera platform to the side of the house!

1 Comment

Unusual Tea Additive

Green tea is supposed to be good for you and Tazo China Green Tips is supposed to be pretty good tasting, so I’ve been sipping a cuppa or two in the morning. Teabags are a spendy way to buy tea, so I’ve been buying half a kilo at a shot from cooking.com, storing it in glass jars, and teaspooning it into a tea ball infuser over the course of the next year.

This interesting additive appeared in one of my teaballs; fortunately I was awake enough to notice it before it wound up in hot water.

Beetle found in Tazo Green Tea

Beetle found in Tazo Green Tea

It looked pretty much like the hull of a generic Asian Garden Beetle, although we haven’t seen anything quite like it in our gardens. Not a big deal, as garden beetles are fairly inoffensive critters, but not something that should make its way into a bag of lah-dee-dah tea. On the other paw, it’s hard to filter stuff like that out of the stream.

Fought my way through the Flash-saturated Tazo site, sent a note to the Customer Service folks, eventually had a pleasant phone chat. After convincing her that I wasn’t rabidly angry and that it really was one of their beetles, she dispatched fifteen bucks worth of Starbucks gift card.

It seems Starbucks either owns Tazo, both of ’em are controlled by the same outfit, or something like that. She was in the Starbucks Customer Service chain o’ command, anyway.

Beetle bottom view

Beetle bottom view

So I picked up three boxes of Tazo tea bags at the local Starbucks: more China Green Tips and some Green Tea with Lemon Grass (which doesn’t appear on their website). Left me with three cents on the card; I’m not a regular customer, so it’s now in the pile of cards I use as measurement shims in the workshop.

I’d been adding lemon grass from our garden to the morning cuppa for a pleasant lemon scent. The Tazo version includes Lemon Verbena, some mint, and other flavors that cranked the scent up to 11 and the taste far into my ptui range. Unpleasant, indeed.

For what it’s worth, if you’ve tried & disliked other green teas, give Tazo China Green Tips a shot. It’s delicate and much better than the other (far cheaper) green teas I’ve tried; Salada Green Tea is particularly noxious.

One of the China Green Tips reviewers on cooking.com comments “I found a rather long, nasty, kinky hair … I was shocked. I threw out the whole bag  … I was unable to drink tea for a week”.

Mexican Bean Beetle on Soybeans

Mexican Bean Beetle on Soybeans

Now, party people, I’m here to tell you that food just doesn’t pop out of the ground in a pristine state. Maybe it’s because we eat a lot of food from our own gardens, but passengers like that, let alone the odd hair, just aren’t an issue. Consider, for example, this critter that made it all the way into the house on some soybeans: he’s likely related to the Asian Garden Beetle family and not all that far back in their family trees.

If you want to really worry about something, ask yourself whether your tea grew downwind of, say, Zhejiang Happy Face Metal Refinery Complex Number Six. No way to tell about that, other than through a detailed chemical analysis of every cuppa.

Bon appétit!

Leave a comment

Udev rule to create /dev/scanner

For some unknown reason, Kubuntu 8.04 doesn’t create a /dev/scanner link while it’s figuring out all the SCSI devices. I wanted to make the link sort of generic for any scanner that I might plug in, but I had to settle for a unique udev match.

The scanner popped out of udev as /dev/sg5 this time and

udevinfo --query=all --attribute-walk --name=/dev/sg5

emits this useful chunk:

looking at parent device '/devices/pci0000:00/0000:00:1e.0/0000:05:05.0/host4/target4:0:2/4:0:2:0':
    KERNELS=="4:0:2:0"
    SUBSYSTEMS=="scsi"
    DRIVERS==""
    ATTRS{device_blocked}=="0"
    ATTRS{type}=="3"
    ATTRS{scsi_level}=="3"
    ATTRS{vendor}=="HP      "
    ATTRS{model}=="C7670A          "
    ATTRS{rev}=="3945"
    ATTRS{state}=="running"
    ATTRS{timeout}=="0"
    ATTRS{iocounterbits}=="32"
    ATTRS{iorequest_cnt}=="0x656"
    ATTRS{iodone_cnt}=="0x656"
    ATTRS{ioerr_cnt}=="0x2"
    ATTRS{modalias}=="scsi:t-0x03"
    ATTRS{evt_media_change}=="0"
    ATTRS{queue_depth}=="2"
    ATTRS{queue_type}=="none"

Plucking the readable bits out produces this stanza for/etc/udev/rules.d/60-symlinks.rules

#-- hack to create /dev/scanner
SUBSYSTEMS=="scsi", ATTRS{vendor}=="HP", ATTRS{model}=="C7670A", SYMLINK+="scanner"

Then you can use that to fire up xsane thusly:

sane hp:/dev/scanner

With that in hand, edit GIMP’s ~/.gimp-whatever/menurc and ~/.gimp-whatever/pluginrc to replace sg5 (or whatever) with scanner.

Works like a champ…

The straight dope on writing udev rules is at http://www.reactivated.net/writing_udev_rules.html

Memo to self: there’s got to be a way to make this generic, perhaps by piggybacking on whatever udev stanza assigns the scanner group to that /dev/sg? device.

Update: make sure you’re in the scanner group

sudo usermod -a -G scanner username

1 Comment

Pocket Stationery

Being that sort of bear, I must carry paper for notes, sketches, and suchlike. Years ago the Levenger catalog tempted me with the notion of 3×5-inch stationery, but the notion of paying 5 cents per piece of scratch paper just didn’t titilate my inner cheapskate.

Part of my chandelier o’ gear (props to Neal Stevenson) is an ancient Zire 71 PDA that’s about the right size to sit atop a 3×5-inch sheet of paper. Some experimentation showed that five cuts could produce six sheets of pocket stationery from a single letter-size page. I used QCAD to lay down a nice 200-mil grid with my contact info on the top, duplicated it six times, and added cut lines.

Part of the trick is figuring out how to get the cut lines at the right spot so the paper divides neatly into thirds and halves. Trial and error is your friend.

Print it on heavy card stock, whack the paper cutter along the lines, and it’s all good.

After a while, you’ll realize you can print it to a PostScript file, then just print that without firing up QCAD every time.

QCAD screen with stationery

QCAD screen with stationery

Better than scribbling on the back of a biz card, as there’s plenty of room, and my contact info is right on the front where it won’t get lost.

Actually, the real reason my Zire 71 case fits that paper is because Mary made it years ago for my HP-15C calculator. The stationery fit that case, so when the Zire came out, well, why change anything else?

1 Comment

Updating Dynamic DNS in Kubuntu

Of course I do remote admin for my mother’s PC, which means I must know its IP address, which means it’s running ddclient and updating an entry at dyndns.

The setup seems straightforward. In /etc/ddclient.conf you find:

# Configuration file for ddclient generated by debconf
#
# /etc/ddclient.conf

pid=/var/run/ddclient.pid
daemon=3600
protocol=dyndns2
ssl=yes
use=web web=checkip.dyndns.com
use=web web=checkip.dyndns.com/, web-skip="IP Address"
syslog=yes
server=members.dyndns.org
login=your-own-id-here
password='make-up-your-own'
hostname-at-dyndns

[Update: Something about checkip changed enough that the old line didn’t work. The web-skip made it work again. ]

But, as the comment in that file shows, that’s not where you configure ddclient in (K)Ubuntu. You actually tweak the entries in /etc/default/ddclient so the right answer pops out when ddclient gets reconfigured by something or another.

It’s not clear to me how ddclient figures out when to update the DNS entry (when an update is “necessary”), so I also force an update by putting this in /etc/rc.local:

ddclient -force

Actually, I added that tweak when I was setting up another, slightly newer, PC for her and managed to fire off ddclient from my network. That aimed the DNS entry at my IP address and, had I not already been signed into her system, would have locked me until her ddclient grabbed it back.

I hate it when that happens.

Memo to self: make sure the defaults match the current configuration.

Leave a comment

Oscilloscope Screen Shots

A long time ago I got an HP54602B oscilloscope with a serial port data link. HP provided a sample app that snarfed screenshots & data from the scope, but it wasn’t really ready for prime time and, besides, I vastly preferred to use OS/2 (!) and then Linux rather than Windows.

Here’s my Kermit script to fetch screenshots. All the software comes more-or-less standard in Ubuntu Linux and (I presume) in most others. If you’re running Windows, you’re on your own.

Scope Setup

HP54602B Serial Setup Screenshot

HP54602B Serial Setup Screenshot

The oscilloscope’s HP Plotter setting spits out bog-standard HPGL commands in flat ASCII. I’ve always meant to investigate what HP Printer does, but …

I wish the scope ran faster than 19200 b/s, but that speed works reliably over generic USB-to-serial converters (and the scope can’t feed data that fast, anyway). The other choice, back in the day, was HPIB / GPIB; I’d have had to buy three or four different adapters to suit all the PC data buses since then: ISA, EISA, VLB, PCI …

Xon/Xoff flow control (a.k.a. handshaking) works better than hardware flow control, simply because the cable’s easier to build.

The Factors setting adds a bunch of text to the end of the data stream that’s not useful, except for the fact that an HPGL LB instruction follows all of the useful data and gives the Kermit script something to look for. Otherwise, the only way to detect the end of the stream is to time out after a looong time.

I haven’t the foggiest idea what Resolution does, but High seems appropriate.

Hardware Notes

The scope requires a Null Modem in front of a standard DB-25 to DB-9 cable. I’ve been meaning to rewire my standard cable to eliminate the Null Modem, but …

Adding an LED breakout / monitoring adapter to the serial port loads the signals too much and can lead to puzzling errors. Maybe it’s just my adapter: YMMV.

I’ve run the cable all the way across my basement lab with no problem. This is, after all, good old RS-232, not some high-falutin’ USB or Firewire interconnect.

Taking the Shot

Get a picture you like, poke the Print Screen button, then quick like a bunny run the script. The scope copies the current screen into an internal buffer, then sends out a torrent of HPGL commands. The script will capture the data and eventually spit out a PNG file.

You may want to Stop the trace, rather than leave it running.

In XY mode, the scope seems to have trouble copying the entire trace. I tap Auto Store twice, then Stop, then Print Screen. It’s fuzzier, but copies the whole thing.

What Happens

The script captures the incoming serial data into a log file, processes that text through the hp2xx program to get an Encapsulated Postscript EPS file, then runs that though convert to get a PNG file. The bank shot off EPS results in better-looking output, for reasons I don’t understand.

The 240-second timeout value for the Input command seems long, but it takes a lot of plotter commands to define a four-trace plot. A too-short timeout chops off the tail end of the HPGL stream and prompts bizarre error messages from hp2xx.

The parameters for hp2xx and convert came from protracted and tedious twiddling. The ‘scope image is 512 dots across and 300-some-ish vertically; the output mimics the not-quite-square graticule aspect ratio on the actual screen. If HP thinks it looks good, then it looks good to me.

The active (bright) traces use Pen 2, which I’ve set to Blue (color 4). The graticule, annotations, and stored traces all use Pen 1, which appears as Black (color 1). Tweak -c 14 as you wish.

The pen widths (set by -p 34) don’t actually seem to do very much, although I vaguely recall that using the default width of 1 makes the output entirely too faint.

The PNG has a transparent background that turns white when you actually use it in a document; I suppose you could overlay it atop a background image if you wanted to get cute.

When the dust settles and the smoke clears, you get PNG images like this. It’s an XY plot, so the blue section appears as a bright trace on the oscilloscope’s screen.

BH curve for LC0263-A coil

BH curve for LC0263-A coil

Kermit Script

#!/usr/bin/kermit +
# Fetches screen shot from HP54602B oscilloscope
# Presumes it's set up for plotter output...
# Converts HPGL to PNG image

set modem none
set line /dev/ttyS0
set speed 19200
set flow xon/xoff
set carrier-watch off

# Make sure we have a param
if not defined %1 ask %1 {File name? }

set input echo off
set input buffer-length 150000

# Wait for PRINT button to send the plot
echo Set HP54602B for HP Plotter, FACTORS ON, 19200, XON/XOFF
echo Press PRINT SCREEN button on HP54602B…

log session “%1.hgl”

# Wait for end of data stream
input 240 lb

echo … got final lb command

close session
close

echo Converting HPGL in
echo — %1.hgl
echo to PNG in
echo — %1.png

# without labels = no terminating lb info
#run hp2xx -m png -a 1.762 -h 91 -c 14 “%1.hgl”
#run mogrify -density 300 -resize 200% “%1.png”

# with labels = terminating lb
run hp2xx -q -m eps -r 270 -a 0.447 -d 300 -w 130 -c 14 -p 34 “%1.hgl”
run convert -density 300 -resize 675×452+2+2 “%1.eps” “%1.png”

echo Finished!

exit 0

Leave a comment

Inductor Saturation

While writing a column for Circuit Cellar, I managed to utterly botch the choice of a boost converter inductor. The inductor (the rightmost one in the lineup) was a common-mode choke from a power supply, so I figured it had enough meat for 300 mA of boost current.

Salvaged Inductors

Salvaged Inductors

Bzzzzt! Wrong choice!

So it’s time to document how to measure this stuff. The intent is to plot a BH curve: core flux density B versus magnetizing force H.

Quick inductor tutorial using (ptooie) Imperial units and avoiding Greek letters for simplicity:

Magnetomotive force mmf = 0.4 * pi * (N = turns) * (I = current)

induced voltage e = – N * (d phi / d t) * (10^-8) where phi = flux linking the N turns

Magnetizing force H = mmf / (MPL = mean path length around core)

Flux density B = phi / (Ac = effective core area)

also B = (mu = permeability) * H

You might think that B & H are lashed linearly together, but mu is most savagely nonlinear. It depends on H, temperature, core material, and a bunch of other stuff you don’t want to know about. So, by and large, plotting B against H shows you how mu varies: it’s the slope of the curve at any point. Vertical slope = high mu (good), horizontal slope = zero mu (bad).

Stirring all that together, you get the Fundamental Transformer Equation:

E in RMS volts = 4 * F * f * N * Ac * B * (10^-8)

F = form factor = rms / average

  • sine = 1.11
  • bipolar square = 1.00
  • unipolar square = 1.41

So…

  • H is proportional to mmf and thus to primary current
  • B is proportional to phi and thus the integral of secondary voltage

Sounds scary, but primary current & secondary voltage are easy to measure.

Inductor measurement test setup

Inductor measurement test setup

The basic lashup goes a little something like this: stick a sampling resistor in the primary, run the secondary through an RC integrator, feed both into an oscilloscope that can do XY plotting, drive the primary from a Variac, turn the knob, and watch at the results. You might want a bit more finesse than this, but, eh, it works.

The primary voltage will be relatively low, so plug a 12 VAC wall wart into the Variac. This gives you galvanic isolation from the power line, finer control over the primary voltage (more of a full turn on the Variac), and will prevent you from killing yourself or burning out your basement laboratory. You want a fairly husky wart if you’re measuring husky inductors. Remember: this is an AC measurement, so you want an AC wall wart, not one with a nice filtered DC output.

The resistance of the sampling resistor should be much less than the inductive reactance of the coil. We’ll measure it at 60 Hz because that’s easy, so for a coil of inductance L, the reactance at 60 Hz is 2 * pi * 60 * L. That simplifies to 377 * L, so a 1 mH coil has about 400 m-ohm reactance. I have a nearly infinite stash of 100 m-ohm sandbox power resistors, so that’s what we’ll use; you’d want less, but this is quick & easy.

If the inductor doesn’t have a secondary, poke some magnet wire through the core. Use some simple number of turns and remember that number, just in case you want to calibrate the results.

The time constant of the RC integrator must be a lot bigger than the frequency you’re integrating. For a 60 Hz signal, you want maybe a 6 Hz integrator: 60 Hz -> 17 ms, so pick 200 ms. Having a nice 1 uF film cap in my heap, the resistor works out to (200×10^-3) / (1×10^-6) = 200 k. Anything in that range will work fine. A larger cap gives you a smaller resistor and more signal to the scope.

Wired it up about like that and here’s what happens for the inductor I picked

BH curve for Bel 0571-0033-02 choke

BH curve for Bel 0571-0033-02 choke (rightmost)

The calibration of H is 100 mV / amp (from the 100 m-ohm resistor) and the scope display is thus 2 A/div. The calibration for B is whatever the secondary winding provides, scaled by 1/RC from the integrator.

For this coil, the value of mu is essentially infinite (B rises vertically for changes in H), but the core saturates at very small values of H (and thus primary current). It was a common-mode choke for a power supply, so that’s exactly what you want: high inductance for very small currents and no need for much in the way of core flux because the opposing line currents in the windings cancel.

I harvested some inductors from a bunch of dead power supplies in my heap and measured them similarly, using an existing winding as the secondary wherever possible. The results look like this:

BH curve for for coil with blue dot

BH curve for for coil with blue dot (3rd left)

BH curve for 40580-R01 coil

BH curve for 40580-R01 coil (2nd left)

BH curve forLC0263-A coil

BH curve for LC0263-A coil (leftmost)

The area inside the loop is proportional to the core power loss, so it’s obvious that some inductors are better than others.

If you’re going to do this for real, you’ll want actual calibrations for both axes. You can work the numbers out from the equations and read real values for both B and H directly from the ‘scope graticule. Pretty slick, mmm?

The primary current can get surprisingly high, so turn the Variac knob up, make your measurement, and turn it back down again. The sampling resistor and the core can get scary hot if you let ’em cook while pondering the ‘scope display. A storage scope is most helpful, which comes pretty much for free with digital scopes these days.

I wrote about all this in more detail in the context of a resistance soldering unit in my February 08 Circuit Cellar column, so I should have known better.

Memo to self: measure first, write later.

And remember to turn off the WordPress Smiley option (Dashboard → Settings → Writing) so equations don’t get cutsy artwork instead of numbers. Feh!

2 Comments