I’ve recently come across two interesting projects and web sites: openaerialmap.org and openstreetmap.org. These two projects are efforts to collect and share freely-available map information.
One may wonder what the point is, since you can get all kinds of free map tools through the likes of Google Maps, Google Earth, MapQuest, and the like. But although those tools are available at no cost, they have limitations on what you can do with them. Because the underlying data is owned and copyrighted by commercial companies or governments who spend money and manpower surveying and updating the information, you are restricted from copying the data and you are limited in using it for other purposes. In Europe, even the government-created map data is copyrighted and you can’t copy it for your own use. And if you find mistakes, you can’t fix them.
But simply knowing the names of streets and where they are located cannot be copyrighted, and anyone can make their own maps if they want to do so. A futile and daunting proposal for an individual, but what if you could harness other technology like GPS and the Internet?
Like the open-source software movement, there is an open data movement happening. The world is full of data, but making is useful and accessible has been the hard part. The Internet is changing that.
The OpenStreetMap project is working toward making an entire street map of the world, freely accessible to everyone and freely copyable for anyone’s use.
In the United States this doesn’t sound too unusual, since all federally-produced data is by law public domain. The freely-available data from the US Census is not quite accurate, though, and needs corrections. In other countries, it means starting from scratch.
The OpenStreetMap (“OSM”) software infrastructure is designed around the idea of collecting GPS data logs (“GPS tracks”) and then drawing and labeling streets and features on top of them. Where aerial or satellite photos are freely available, they can be used as tracing sources also.
I’ve been working on fixing up the map for my neighborhood. While the vast majority of the streets are there already, many of them are out of alignment or proportion, and recent developments are missing. Although I have had an interest in maps my whole life, this is the first time I’ve been able to make or work on a map that other people may actually find useful. Fun stuff.
Anne and I saw a Canadian lynx outside a local veterinarian’s office. He was waiting in the car with his owners for the vet, which handles all sorts of animals besides just cats and dogs. The owners of the lynx have an exotic animal refuge.
This cat’s name is Tucker, and he was quite friendly. He let us pet him and stroke his very soft fur. He has a pink nose just like a house cat, and his paws were HUGE.
The owners take him everywhere, and I would too if I had one. What a fabulous, beautiful animal.
When I fixed up an old drill press, I found that the switch plate for the on/off switch was fairly worn. The original paint and lettering was worn away, so that the start/stop wording was almost unreadable. Even though I am clever enough to figure out that the big red button means “stop”, it needed a clearly readable switch plate label.
The basic process is fairly simple:
Photograph or scan the original label
Edit the picture on the computer using free software
Print the new picture on glossy photo paper
Trim label and cut out holes
Place over original label and cover with clear packing tape
For those of you who need more details (or just can’t get enough of my snarky comments), read on for more.
Photograph or scan the original label
First you need an accurate picture of the original label. You can take a close-up photo with a digital camera. Take the picture directly above the label, as perpendicular as possible to the label surface. Holding the camera farther away and zooming in with the lens may work better than holding the camera up close. Try several shots and see which comes out the best. You’ll want the clearest picture you can get, with no glare or shadows. Unless you want those in the final label for that artsy look; I didn’t.
If the label is flat, you’ll probably get better results using a flat-bed scanner. I tried it with the drill press switch plate, but it didn’t work. The label is riveted to a switch plate, with prongs that stick up on each side of the start button to guard the button from accidentally being pressed. They moved the label too far from the surface of the scanner, putting it out of focus. Darn safety features. Oops, I mean, hey, good thing for those safety features, huh?
Make sure you get a good picture before doing too much cleaning on the original label. I did, but only because I was lucky. I mean, good thing I planned it that way. After I took the picture, I thought it would be a good idea to clean off the dirt, grease and oil from the label plate. I soaked it in citrus cleaner, and it cleaned it all right. It removed nearly all of the rest of the paint right off the label plate. Ooops.
Edit with free software
Once you have the picture, it’s time to edit it. You’ll need some graphics software for that. I like using free, open source software, because I dislike the Evil Empire to the North in Redmond and their predatory strangle-hold on the computing industry, and I support freedom with liberty and justice for all. Oh yeah, and I’m a cheap tightwad too. I mean frugal.
For photo editing, my tool of choice is the GIMP. It does nearly everything the big expensive commercial programs do, like that well-known one that everybody pirates at home. I also use Inkscape for drawings. Both GIMP and Inkscape are freely available on Mac, Linux, and that other operating system I have to use at work because the man says so.
The first thing to do is crop the picture and straighten it out. It is easiest to rotate it first so that you have straight horizontal and vertical edges, and then crop it.
Now you need to touch it up. That was the whole point of this, remember? This is where I use the “layers” feature in GIMP. I put the original photo in the bottom layer, and then create a new layer or two for the changes. That way I can easily switch back and forth between the original view and the new retouched result and admire the improvement. I have a fragile ego and I need that constant affirmation, you know.
I did not completely restore and refinish this drill press, so I thought it would be interesting to leave a little of the original character of it in the new label. The switch plate was pretty scratched and worn from years of use. It is quite easy in the software to use the orange color of the label body and draw shapes to completely cover those sections, masking all of the original scratches and character. But with one little adjustment, the new section can be made partially transparent. The parts of the old label which were still orange in good condition will look the same. The parts that were scratched and worn will show through just a little bit, in a subtle way. (So much for not wanting that artsy look. Hey, it’s my project, OK? OK.)
The remaining part is the lettering. I used another layer in GIMP for the lettering, to place it on top of the orange mask layer. The “START” and “STOP” wording is easy enough, but the manufacturer name presented a difficulty as it curved along a smooth arc.
There may be a way to fit text along an arc and easily adjust it to line up properly in the GIMP, but I couldn’t find it. So instead I used Inkscape. Inkscape has feature exactly for that, fitting text along a path. It also has easy adjustments for the height, width, and spacing of text, to line up exactly with the original.
I loaded the photo into Inkscape, and drew a curved path along the base of the original lettering. Then I put in new text along the path, and lined it up on top of the original to match. Once I put all of the text for the label in place, I deleted the photo, leaving just the new text, and I saved it as a PNG bitmap image.
I brought the text bitmap image into the GIMP and put it into the top layer. This gave me a stack of three layers: new text, semi-transparent orange paint, and original photo. The editing was done.
At this point some smart guy will tell me how I could have saved myself a lot of work with only $600 worth of software. That’s probably true. Why, I could even pay for it by turning in 12000 soda cans for their deposit and come out even. Or perhaps not. I’ll stick with the free software.
Print the new label
Next I needed to print the new label at exactly the right size. (I’m skipping the surrealism at this point and just going for the realistic look.)
Both GIMP and Inkscape allow you to measure things on the screen in your choice of units, such as pixels, inches or millimeters. This makes it easier to get your image to print out at exactly the right size. Easier, but not foolproof. I’m a better fool than they expected.
For some reason, I could not get the size quite right. When I printed it out, the height was correct but the width was slightly too narrow. The easiest solution was to save a copy of the whole layered image as a new PNG bitmap image, and then play around with scaling that image. When I widened it by about 4%, it came out perfect. A little extra work, but good results. Of course, if only I had those 12000 soda cans, I could have skipped this part.
I printed the label on glossy 4-inch by 6-inch photo paper on an inkjet printer. Since digital cameras and photo printing have become so popular, it is quite easy and inexpensive to get excellent prints. No more waiting like Snow White (“Some day, my prints will come….” Ouch.)
Cut out the new label
This is the easy part. Once it was printed at the right size, I simply cut the margins off the label and cut out the button holes. You certainly can use scissors, but I used a sharp utility knife and a straightedge for nice clean lines. On the straight parts, anyways. Not the circles.
There were several holes to cut for this label: the main holes for the start and stop buttons, the slots for the start button guard prongs, and the two small holes for the mounting screws. I did the big ones with the knife and did the screw holes with a punch, the kind that is a sharp-ended tube which you smack with a hammer. Ouch, not again! I said smack the punch, not my thumb!
Place over original label
If you have lived through the previous part, now you are ready to put the label in place. Finally.
My preferred method is just to tape it down with clear packing tape. It protects the surface of the print from getting smudged, and can be peeled off if needed. Pull out a length of packing tape longer than you need, and place the middle of it over the middle of the label. Press it down and smooth it out, starting in the middle and smoothing outward toward the edges. Tiny bubbles are great for Hawaiian music, but not for your label. Then place the label and tape onto the surface where it goes. Cut the excess tape off, smooth it down, and step back and admire your work.
In this case, since this label was part of a switch plate, I taped the label to the plate and then screwed the plate to the machine, so that the plate screws also held the label on. Be careful when tightening the screws; if you overdo it you will twist up the packing tape or maybe even the label. If you do that, all is lost! You can’t just go back and reprint another one! Oh wait, yes you can. Nevermind. These aren’t the droids you’re looking for. Move along.
This method worked so well for my drill press that I have been using it for other projects also, such as my grinder. I hope you give it a try, and have fun.
My new grinder needed some task lighting for the grinding wheels. I decided to build a dedicated lamp for each side, controlled by the grinder power switch. This worked in perfectly with my latest obsession, I mean interest, which is LED lighting.
Power
My first obstacle was the fact that the grinder runs of 240 volts, which is double the standard voltage in the US. My 20 amp power outlet and cord only provided the straight 240 volts; no neutral center tap was available to get 120v. For the LEDs, I needed a power supply which could accept 240v.
Fortunately, I had a couple of discarded laptop power supplies which would accept 240v, thanks to their international design. I used an HP Omnibook power supply which produces 19v DC output.
I bent some scrap sheet metal from an old VCR case into a small bracket that just fit the power supply, and painted the power supply and bracket both grey to match the grinder. I attached it to the back of the grinder in a convenient spot.
I ran the input power cord from the power supply down the side of the grinder stand, and attached it to the main power output terminals inside the relay box.
LEDs
For the lamps, I made flexible necks by coiling solid copper wire around a rod. I left the insulation on the wire, and spray-painted it black using vinyl dye from the auto parts store. I ran the 19v output wire from the power supply up through the middle of the coil. The lamp shades at the end are PVC pipe caps from the hardware store, spray-painted silver.
Inside the PVC cap lamp shades are the LED arrays. Since white LEDs typically use around 3.3 to 3.5 volts, the 19 volts from power supply should be perfect to drive 5 LEDs in series, with a little left over for a current-limiting resistor. I measured the output of the power supply with my meter, and found that it actually produced 19.5 volts.
I used the LED resistor calculator to find that I would need a resistor of around 100 ohms in series with the LEDs. I wired up the 5 LEDs and the 100 ohm resistor in series, and tried it out with the power supply. They lit up nice and bright.
LEDs need to have the current limited externally, typically by a resistor as mentioned, and the average LED needs 20 milliamps. I measured the amperage in my circuit using my multimeter, and found that the actual current draw was 30 milliamps. While it might be fine, I decided to be a little more conservative and stick to the advised 20 milliamps.
The five LEDs were actually dropping 3.3 volts each, leaving 3 volts going through the resistor. 3 volts through the resistor at 100 ohms makes 30 milliamps. To reduce it to 20 milliamps, I changed the resistor to 150 ohms. Another check with the meter showed 20 milliamps as expected.
With that determined, I soldered the 5 LEDs and resistor to the ends of the 19v power wires sticking through the PVC cap. After wrapping the leads with electrical tape, I stuffed the LED array into the cap and pulled the slack out of the wire.
Results
I used a few zip ties to secure the wires, and with that, I was done. Starting the grinder turned on the lights. With the copper wire neck, I can bend it to point the light at whatever angle is best on the grinding wheel. It didn’t take too long, and produces a decent light. I might just have to do this to all my tools.
Any trained machinist will tell you that a drill press with a cheap jig is no substitute for a proper lathe. I’m not a trained machinist, so now that I’ve said that, let’s get on to accomplishing something interesting.
I recently saw an idea for using a drill press as a simple vertical lathe. If you make a “live center” and attach it to the drill press table, you can do some basic wood turning in a vertical position. A live center is a pointed shaft on a bearing, which rotates with the work being turned on the lathe.
This is not a new idea. One has been sold commercially for years as the Vertilathe, and Grizzly sells a lathe attachment for a drill press also. It has shown up in several books, including “200 Original Shop Aids & Jigs for Woodworkers” by Rosario Capotosto, “New Wood Puzzle Designs” by James Follette, and “Eccentric Cubicle” by Kaden Harris.
Needless to say, I had to try it out. If you want to make one like me (which of course you don’t because such endeavors are both tedious and hazardous), you might (or might not) do it as follows:
Acquire a bicycle wheel. This will be found rusting next to the apartment dumpster, or perhaps readily retrieved from the neighbor’s garbage can. Do not take the wheel off your neighbor’s working bicycle; they will frown upon this. Make sure you grab the cheap wheel with nuts that hold it on a solid axle, not the one with the cool and coveted lever clamp through a hollow axle. (Actually, snag that one too, but keep it for later.)
Remove the spokes from the hub. If you got the rusty one from next to the dumpster, you’re in luck because half the spokes will snap right off quite easily. If you are impatient and/or feeling destructive, use some heavy wire cutters to clip the remaining spokes. If you are feeling a little more retentive, remove the tire and unscrew the nuts holding the spokes to the rim. Toss the spokes and rim into the nearest metal recycling bin. We don’t need them for this project. If we need some for another project later, well there’s no shortage of rusty bicycle wheels in the world, now is there?
Disassemble the hub and axle. Unscrew the nuts on each end of the axle. You should find that both ends simply unscrew, and that the axle is just one long threaded rod. Behind the nuts there should be some ball bearings. Take it all apart and soak it with your favorite rust remover, such as WD40. Don’t use water; it isn’t a good rust remover.
Clean the parts. Use a rotating wire wheel to remove the rust from the hub, axle, and nuts. Chuck the wire wheel into the drill press and start cleaning the parts. You do have a drill press, right? This lathe jig isn’t going to work with a hand drill. And don’t accidentally clean your fingers with the wire wheel; it hurts. Don’t ask how I know.
Put a point on the axle. Use a grinder or file to make a rough point on one end of the axle. Then chuck the axle into the drill press and use a file to make it nice and pretty. And centered. That’s more important than the pretty part. Mostly.
Grease and reassemble. Load up the bearings with grease and reassemble the hub. Just like those Brady boys on TV, working on their bikes instead of riding them. OK, I never actually saw them reassemble a hub on one of their bikes. In fact, while they appeared to be working on their bikes, I don’t think I ever saw them actually fix anything. Hmmm.
Once you have done all this, you will have a rather hazardous-looking sharp pointy bolt that rotates. My wife says it looks like something Speed Racer would have coming out of the side of the Mach 5, so he could pop the tires of the other cars in the Grand Prix. Why were all the races always called the Grand Prix? Aggh, stupid TV. Where was I?
Now we need to hold it to the drill press table.
Cut a piece of wood to size. Make it fit the size of your drill press table, so you can clamp it or bolt it down. (This is where those cool bike axles with the lever clamp come in, if you were lucky enough to find some.)
Drill a hole in the center. Make it large enough to fit the other end of the axle, which will stick through the wood and drill press table. We want the axle to rotate freely, and not bind against the wood. That would defeat the whole purpose of those fancy ball bearings in the hub, now wouldn’t it?
Paint the wood to look official. Perhaps a nice gloss grey, just like they would do in the Navy when using a piece of wood and an old bike wheel to make a lathe out of a drill press. Ahem.
Screw the hub to the wood. OK, the real part you were waiting for. Put some screws through a couple of those little spoke holes in the hub to secure it to your fancy-pants painted board. Make sure the screws don’t go all the way through the wood and scratch up your nice drill press table.
Congratulations! You have built yourself a live center. You have now completed half of the project. You’re in good company, because I’ve only completed this much also. I’m too impatient to wait, so let’s see some results now.
Line up the live center on the drill press table directly beneath the chuck, and clamp it down to the table. Put a wood screw into the top of your piece of wood and chuck up the screw, or chuck up a Forstner drill bit to press into the end of the wood. Raise the table or lower and lock the chuck to hold the wood firmly between the chuck and the live center. Now you can spin the wood. Give it a short spin, then tighten the gap again after the live center presses into the bottom of the piece.
Spinning wood is fun, but shaping it is even more fun. We are only half done, because we don’t have a tool rest to use for any carving tools. But I can’t wait that long, so we can use a wood rasp and files for some quick wood turning results.
This is the point where you go read up on safety somewhere. Holding a jaggedy rasp against a spinning piece of wood is a recipe for having a tool thrown at a vulnerable spot on your person, or some other such hazard. Seriously, be careful with this stuff.
Having said that, the rasp and files actually work nicely. Using combinations of straight, half-round, and rat-tail files, you can actually produce a moderately interesting piece of turned wood with this little jig.
Experienced people tell me that you should always get the best tools you can buy, because there is no substitute for the proper tool for a job. Don’t be fooled into buying cheap tools, because you will be disappointed when the tool doesn’t provide precision results or it breaks down on you.
I agree that in home improvement, woodworking, metal working, and other pursuits, it is always important to have the proper tool for the job. But what is the proper tool for the job, and how much should you spend on it?
I’ll share my thoughts on how, why, and when you might want to spend less on tools.
Investing Your Money
Everyone agrees that investing your money is wise. But there are multiple ways to invest money, and this applies with tools also.
Spending money on high-quality tools is an investment. The money you spend will save you time and hassle; it is an investment in productivity. If you just want to get a job done, buy a good tool and get on with it.
But spending money on cheap tools can be an investment also. If you are like me and have a short attention span, ahem, I mean a broad variety of interests, there are many repairs, activities, and hobbies you might like to try. If you buy the best tool available for each one, you may spend a fortune on equipment that you rarely use. Buying a cheap tool can be an investment in your education, allowing you to try out many things that you could not otherwise afford. Once you have tried things out and know what you are likely to pursue further, and have a better idea of what features in a tool matter to you, then you can spend more money on selected better tools.
Cheap Retail Tools
Modern manufacturing has brought the ability to mass produce complex items at incredibly low costs. Today, Asia is the low-cost manufacturing powerhouse. The U.S. is hard pressed to compete with overseas manufacturing.
Harbor Freight Tools is a nationwide chain of stores in the U.S., selling primarily Asian import power tools and hand tools. While they are not top-quality and most won’t stand up to heavy use, they are incredibly inexpensive. I signed up for their email mailing list where they send weekly advertisements and coupons, and have gotten some excellent deals. They send out 15% off coupons on a regular basis, which are even good on sale items. I bought a bench-top drill press for $35. A drill press like this might typically sell for $80 to $100 in most stores. Harbor Freight normally sells it for $70. It was on sale for $40, and I had a 15% off coupon, and they have a store within driving distance so I didn’t have to pay shipping. Getting deals this cheap requires some patience, waiting for sales to come up and keeping track of the coupons. But in this case it was worth it.
For higher-quality large power tools, Grizzly Industrial imports power tools built in Taiwan. Better quality but still good prices.
Used Tools
The other way to get good tools inexpensively is to buy them used. Most American power tools built in the last century were made to last and will keep on running, given some cleanup and care.
I bought a tablesaw at a local estate sale for about $20. A comparable saw at the store would probably cost about $100 or more. Mine is fairly solid, and I got the advantage of the previous owner’s upgraded motor. It took some cleanup but mostly worked fine immediately.
I certainly like the satisfaction of taking an old piece of equipment with some history and personality, and adding some more life back into it with some cleaning, oiling, and perhaps a little paint. There is too much waste in our society in my opinion. Just as I get satisfaction from using tools to fix things, I enjoy fixing the tools also.
One thing to watch out for if the tools are more than a few decades old is the safety features, or lack thereof. I added some guards on to my tablesaw, and you’ll want to watch for similar situations with older power tools.
Balance
At some point you have to make the decision on when to buy a more expensive tool. This is a personal judgment call, which needs to fit in with your values of time and money.
I bought a cheap heat gun from Harbor Freight for $10. I had not owned one before, so I didn’t know how much I would use it. I ended up using it a lot. I burned it out, bought another one for $10, and ended up breaking that one also. By that point I knew this was a useful tool to me, so I went to another store and bought a better one for $30. It has performed great and I expect it will last a long time. Was this a waste? I don’t think so. I spent $50 altogether and ended up with a good tool that will last. If I hadn’t shopped around, I might have spent that much anyways. I balance this against all the other expensive tools I didn’t buy for occasional use, and I have definitely saved money.
Status Symbols
Some people like to buy expensive tools because they see them as a status symbol, for showing off. I don’t think tools (or other material items for that matter) should be used in this way, but the reality is that our posessions do reflect something of our values to other people. Therefore, I like to reflect the values of not wasting money and being creative with less. Using an inexpensive tool to get the job done, or better yet fixing up an old tool to do it, is quite satisfying to me, and I hope it inspires others to do the same.
Many people have light-up Christmas decorations in their yard. A popular one is the white-wire reindeer, covered with mini lights. Having another yard with another reindeer sounded boring. What really sounded good would be to have what almost nobody else has: a moose.
I bought a reindeer from the store and overhauled it. I studied pictures of moose, and got an idea of how their heads and shoulders varied from deer. And, of course, the antlers. I sketched the new shape in full size on paper, tracing around the existing wire deer head.
I got some heavy-gauge steel wire from the hardware store, and bent it to match my drawing. I scraped off the white paint from the deer head where the wires met, and soldered it together with a propane torch. Then I painted it with white spray paint.
Since the head and antlers were bigger than before, it needed more mini lights. I got more lights and redid the shoulders, head and antlers. The result: a one-of-a-kind Christmas moose. Merry Chrismoose!
I have an old laser printer which does not have a decent standby power-saving mode. I built a computer-controlled power switch for it, so the computer turns on the printer when there is a print job, then turns it off again later.
The printer is not near to the family computer, but in an out-of-the-way place in the basement. Because it doesn’t have a power-saver mode, it has been on a mechanical timer switch. Turn the knob, and the printer will stay on for 45 minutes. We had to go down and turn on the printer, go back up to the computer and print, then go down and get the printout from the printer. Good exercise, but annoying.
Existing solutions
I could have used off-the-shelf units from the X10 control system. This home automation system has been around for years and is well known and reliable. Since I don’t know much about electronics and have not built a computer-controlled real-world interface before, this would have been a good simple solution to the problem. But I have more fun breaking, I mean making things myself, so I built my own solution. Other people have done similar things, and I’m learning from their examples.
Design parameters
My laser printer is an Apple LaserWriter Pro 630. Its label says it can pull up to 5 amps of current. This would represent the highest load possible, most likely at power-on when the fuser is warming up. I want my switch to accommodate this plus some safety margin, so I’m using 7 amps as a minimum figure to be extra safe.
I send print jobs to the printer from my Linux server, using the CUPS print spooler system and the NetAtalk software. It sends the print jobs over Ethernet to the LaserWriter using the AppleTalk PAP protocol.
The software needs to turn on the power switch, wait until the printer is ready to respond, send the print job, and then turn off the power switch afterwards.
Serial port
There are many ways that a computer can interface to the outside world. Two common and popular choices on PC hardware are the RS232 serial port (“COM”) and the Centronics parallel port (“LPT”). I selected the serial port, since my server has two available and I’m not using them for anything else.
In reading up on serial ports, people caution that you should not try to draw too much current from the serial port or you could burn it out. A number of references said that you should not draw more than about 5 milliamps. This is a very small amount of electricity, and is not going to be enough to drive a good-size relay big enough to switch 7 amps. Therefore I will need something in between the RS232 signal and the 7A relay coil.
Electrically, the RS232 signal is interesting. The voltage can vary anywhere from around 4V to 20V. A binary one is a positive voltage, and a binary zero is a negative voltage.
If I knew more about electronics, I’d cook up a circuit with a voltage regulator and transistor and some other neat gizmos to drive a big relay. But I took the easy way out and just selected a solid-state relay in series with a diode. The diode makes sure the RS232 negative voltage for the binary zero is filtered out, so only a binary one will activate the solid-state relay. The SSR takes very little current, and operates from 3V to 24V input, which matches RS232 nicely. I bought the SSR from the local electronics store, and I pulled the diode out of a broken radio.
The solid-state relay, in turn, activates the mechanical relay with the high-current contacts. I used an SSR with 120VAC output, and a mechanical relay with a 120VAC coil, so I didn’t need any power source other than the RS232 signal and the 120VAC line power.
Software
To drive the switch, I need to turn on the DTR signal of the serial port when the printer should turn on, and turn off the DTR pin when the printer should turn off. I decided to activate the printer at the start of a print job, and deactivate it after a fixed period of time (30 minutes by default), if no new print jobs have shown up.
I found that the Linux serial port device drivers will control the DTR signal according to their own whims when a program opens or closes the port. Therefore I need a constantly-running background daemon to open the port, and then toggle the DTR signal as needed.
There are many ways to communicate with a background daemon. I chose the simple approach of a control file. When the file is created, the daemon turns on DTR. When the file is deleted, or the timestamp of the file is too old, the daemon turns off DTR. So when a print job needs to turn on the printer, a simple “touch” of the control file will turn it on.
Construction
With the software working, I assembled the hardware. I first connected the components together with alligator clips to make sure it worked. The big relay clicked on and off to match the DTR signal, as I had hoped.
I used a clear plastic mayonaise jar as a case, and cut holes in the lid for the power outlet and master switch. The two-pole master switch allows the power output to be always off, always on, or controlled by the relay.
Silicone sealer
To keep things neat, I mounted the two relays and the diode on a piece of plastic (actually a lid from a can). I was short on shrink-wrap tubing, so I covered the exposed wire connections with clear silicone sealer to prevent shorts.
I tested it one more time, and made a strange discovery. The power output was stuck on, regardless of the state of the DTR line. Somehow my circuit was shorted out. I double-checked my connections, and could not find any wires out of place. Then I found the culprit: I had not used silicone sealer. I had used clear latex caulk. Latex caulking is water-based, and water conducts electricity. Even after drying for more than a day, it still was conducting electricity and shorting my circuit. I scraped off all of the latex caulk, and then it worked.
End result
The end result was a nice power switch that works as well as I had hoped. My daughter the artist helped me make a fancy label using the GIMP, which we printed on photo paper and stuck inside. Success!
Code listing
Here is the Perl code for the background daemon which monitors the control file and sets the DTR line to match.
port-handler.pl
#!/usr/bin/perl -w
# Serial port line control
# Control a relay hooked to the serial port using DTR line. # Run as a daemon.# Monitor file for control action# – If file created recently, turn on line.# – If file deleted or too old, turn off line.
#——————————————–# Modules/directivesuse strict;use Device::SerialPort qw( :PARAM :STAT 0.07 );use Getopt::Long;
#————————————–
my $CheckTimeSeconds=10; # seconds between file checksmy $ControlFileName=”/var/run/port-dtr”; # file to monitormy $TimeoutMinutes=45; # turn off after this much time- 30 minutesmy $SerialPort=”/dev/ttyS0″;my $debug=0;
my ( $result, @filestat, $filetime, # last mod timestamp of control file );
$result=GetOptions ( “checktimeseconds=i” => $CheckTimeSeconds, “timeoutminutes=i” => $TimeoutMinutes, “portname=i” => $SerialPort, “debug=i” => $debug, “controlfile=i” => $ControlFileName );
# Open portDebugMsg ( “Starting with:n”, ” checktimeseconds=$CheckTimeSecondsn”, ” timeoutminutes =$TimeoutMinutesn”, ” portname =$SerialPortn”, ” controlfile =$ControlFileNamen”);
DebugMsg ( “Open portn”);
my $PortObj = Device::SerialPort->new($SerialPort) or die “Error: cannot open serial port: $! n”; ;
# Turn off status$result=$PortObj->dtr_active(0);
while (1) {
if ( -f $ControlFileName ) { @filestat = stat $ControlFileName; $filetime = $filestat[9]; if ( ( time – $filetime) > ( $TimeoutMinutes * 60 ) ) { # file expired; turn off DebugMsg ( “File expired; Turn off dtrn”); $result=$PortObj->dtr_active(0); } else { # file is recent; turn on DebugMsg ( “File is recent; Turn on dtrn”); $result=$PortObj->dtr_active(1); } # if time } else { DebugMsg ( “File is gone; Turn off dtrn”); $result=$PortObj->dtr_active(0); } # if controlfile exists
sleep $CheckTimeSeconds;
} # while
#—————————–sub DebugMsg { my @Message =@_;
if ( $debug ) { print STDERR “@Messagen”; } } # sub DebugMsg
/usr/lib/cups/backend/pap
added just before the pap command is run:
# Turn on power switchtouch /var/run/port-dtr# See if printer is therePrinterFound=` $nbplkup $nbpname | wc -l `while [ $PrinterFound -eq 0 ] ; do sleep 20 PrinterFound=` $nbplkup $nbpname | wc -l ` sleep 10done