The Smell of Molten Projects in the Morning

Ed Nisley's Blog: Shop notes, electronics, firmware, machinery, 3D printing, laser cuttery, and curiosities. Contents: 100% human thinking, 0% AI slop.

Category: Electronics Workbench

Electrical & Electronic gadgets

  • Arduino Command Line Programming: Avrdude Puzzlement

    For all the usual reasons, I’d like to compile & download Arduino programs from the command line, rather than through the (excellent!) IDE. That is supposed to work and, for most folks, apparently it does.

    Not here, alas.

    I’ve installed the 0012 Arduino Java IDE (x86 or x86_64 as appropriate) from http://code.google.com/p/arduino/ on three different systems, all with Kubuntu 8.04:

    • Dell Dimension 9150 – x86_64, which seemed like a good idea at the time
    • Dell Inspiron E1405
    • Dell Inspiron 8100

    In all cases the IDE works perfectly, compiles & downloads programs just fine, and behaves exactly as you’d expect. I had a few minor quibbles with sorting out various paths & suchlike, but, on the whole, it has no troubles at all with either a Diecimila or a Sparkfun Arduino Pro (with a Sparkfun FTDI Basic USB gizmo).

    I tweaked ~/.arduino/preferences.txt to include:

    console.auto_clear=false
    build.verbose=true
    upload.verbose=true

    Here’s the final step in the IDE compile-and-download dance. Backslashes indicate continuations of the same line; the original is all on single line:

    hardware/tools/avrdude -Chardware/tools/avrdude.conf -v -v -v -v -pm168
    -cstk500v1 -P/dev/ttyUSB0 -b19200 -D
    -Uflash:w:/mnt/bulkdata/Above the Ground Plane/
    2009-06 Solar Data Logger/Firmware/Logger/applet/Logger.hex:i 
    
    avrdude: Version 5.4-arduino, compiled on Oct 22 2007 at 13:15:12
             Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
    
             System wide configuration file is "hardware/tools/avrdude.conf"
             User configuration file is "/home/ed/.avrduderc"
             User configuration file does not exist or is not a regular file, skipping
    
             Using Port            : /dev/ttyUSB0
             Using Programmer      : stk500v1
             Overriding Baud Rate  : 19200
    avrdude: Send: 0 [30]   [20]
    avrdude: Send: 0 [30]   [20]
    avrdude: Send: 0 [30]   [20]
    avrdude: Recv: . [14]
    avrdude: Recv: . [10]
             AVR Part              : ATMEGA168

    The IDE evidently does the reset-from-USB trick through the standard USB hardware.

    I set up the command-line Makefile from http://www.arduino.cc/en/Hacking/CommandLine, although that’s for the 0011 IDE, then made the recommended tweaks. The make section does exactly what you’d expect: compiles the source program.

    Running make upload fails every time, on every PC, with both boards. Indeed, in all cases, running avrdude on the command line produces the dreaded “not in sync” errors, showing that it’s unable to communicate with the Arduino board. Blipping the reset button on the Arduino board generally makes the USB transfer work fine, with the failures most likely due to my lack of dexterity & timing precision.

    The usual debugging suggestions aren’t relevant, as they all assume there’s a basic communication failure caused by anything from a completely dead board to mysterious library incompatibilities. In this case, however, I have an existence theorem: the IDE works perfectly before and after the command-line failure.

    It turns out that the IDE includes a specially patched avrdude, so I tried running that version from the directory where the IDE lives, using exactly the same command-line flags as the IDE does. Surprisingly, that doesn’t work. Again, backslashes indicate continuations of the same line and I added quotes to the file name to protect the blanks…

    hardware/tools/avrdude -Chardware/tools/avrdude.conf -v -v -v -v -pm168
    -cstk500v1 -P/dev/ttyUSB0 -b19200 -D
    -Uflash:w:"/mnt/bulkdata/Above the Ground Plane/
    2009-06 Solar Data Logger/Firmware/Logger/applet/Logger.hex":i
    
    avrdude: Version 5.4-arduino, compiled on Oct 22 2007 at 13:15:12
             Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
    
             System wide configuration file is "hardware/tools/avrdude.conf"
             User configuration file is "/home/ed/.avrduderc"
             User configuration file does not exist or is not a regular file, skipping
    
             Using Port            : /dev/ttyUSB0
             Using Programmer      : stk500v1
             Overriding Baud Rate  : 19200
    avrdude: Send: 0 [30]   [20]
    avrdude: Send: 0 [30]   [20]
    avrdude: Send: 0 [30]   [20]
    avrdude: Recv: . [1e]
    avrdude: stk500_getsync(): not in sync: resp=0x1e
    avrdude: Send: Q [51]   [20]
    avrdude: Recv: . [0f]
    avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x0f

    There’s no difference between the /opt/arduino/lib/librxtxSerial.so and /usr/lib/librxtxSerial.so libraries, which normally causes some confusion on x86_64 systems. I think that means the x86_64 version of the IDE has the correct library.

    I’ve also tried the stock Kubuntu avrdude, which is at V 5.5, to no avail.

    Given that the IDE works, that I’m running the same avrdude executable, and that the libraries match, I’m not sure where to go from here.

    While I’m generally dexterous enough to run make upload and blip the Arduino board’s reset button with my other hand, I’m bringing up a shield-like board that plugs atop the Arduino and, alas, lacks both a reset button and a hole over the Arduino’s button.

    The board is, of course, that one.

    Update: As a reasonable workaround, I’ve set the IDE up to use an external editor. Then I can tweak the programming, flip to the IDE, click the Download button, and away it goes. Not quite as easy as a full command-line solution, but close enough.

  • MAX4372 High-side Current Amp Gotcha

    MAX4372 output and boost transistor base drive
    MAX4372 output and boost transistor base drive

    Maxim’s MAX4372 is a high-side current sense amp that simplifies DC-DC converters, battery chargers / monitors, and stuff like that. It’s a nice gadget because it has a 28-V common-mode voltage rating that’s independent of the supply voltage. That means you can monitor the current from a relatively high voltage source with a low-resistance in series with the supply’s positive lead.

    I’m using it as part of a solar panel characterization circuit for a Circuit Cellar column, where it’s a key part of a simple DC-DC boost converter that will illustrate how maximum power point tracking works.

    The current sense resistor is a 0.5 Ω (that’s a capital Omega, if your browser just burped) resistor that produces 150 mV from the maximum 300 mA I’ll be drawing from the small panels in my collection. That’s the maximum rated full-scale sense voltage in the datasheet.

    The scope shot shows that it works like a champ, with the DC-DC converter’s transistor base drive toggling at the 100 and 200 mA setpoints. There’s a touch of deliberate hysteresis in the comparators, hence the overshoot.

    The datasheet has one Absolute Maximum Rating value that I’d managed to overlook:

    Differential Input Voltage (VRS+ - VRS-) ... ±0.3V

    What that means is that you must not, under any circumstances, apply more than 300 mV across the sense resistor. That translates into 600 mA for my circuit, which seems unlikely.

    I was bringing the board up with a bench power supply set to 4 V and connected through an 8-Ω resistor to simulate a solar panel’s declining voltage-vs-current characteristic, with the supply set to a 300 mA current limit. Worked fine until I managed to connect the power supply without the resistor, at which point the MAX4372 stopped working.

    What most likely happened was that the booster drive transistor stayed on a mite too long while the microcontroller was rebooting, which drove the inductor into saturation and put the supply directly across the sense resistor: 4 V / 0.5 Ω = 8 A, if the supply was up to it (which it isn’t). Not for very long, mind you, just long enough to kill the MAX4372 stone cold dead.

    The best solution, which doesn’t appear anywhere in the datasheet or the app notes, seems to be a Schottky diode across the sense resistor. When the sense voltage exceeds the more-or-less 300 mV diode forward threshold, it’s clamped to a (presumably) safe value.

    I haven’t tested this yet, but I don’t see any other way to prevent toasting the MAX4372 during the inevitable brief circuit glitches and faults. Even in an operational circuit, you might well see a brief short-to-ground that would apply the full supply voltage across the sense resistor: poof!

    Oh, yeah, if you’ve just blown your two samples, Maxim nails you with a $15 shipping charge (!) to order more. I picked up ten through DigiKey for 60% more per piece, but just $4 in USPS postage.

    I wanted to get some MAX4322 high-current op amps, but they’re non-stock items. Fooey!

    Memo to self: Use the diode, Ed!

    Update: see the comments for a better idea. More details later.

  • Circuit Board Grounding Point

    Instrument grounding point
    Instrument grounding point

    When you’re bringing up a new circuit board, you need a place to attach test equipment ground clips.

    Take a resistor lead from that pile you’ve been collecting (you do save snipped-off through-hole component leads, don’t you?), bend it into a sort of flattened horseshoe with the ends pointing out, and firmly solder the ends to a convenient point on the board’s ground plane, ideally near the power entry point.

    It helps if you leave a nice spot for the thing; tiny boards with all surface-mount parts pose a problem.

    Long dangly ground leads clipped to a distant part of the board are definitely not adequate for low-level or high-frequency analog probing, but when you’re just trying to figure out if the mumble thing is alive, this hack will do the trick.

    Oscilloscope probe tip ground
    Oscilloscope probe tip ground

    For detailed stuff, get up close & personal with that odd little scope probe nosepiece you’ve been keeping in a bag for some reason.

    The top board is, of course, the one you’ve seen earlier.

  • Making PCBs: Etching and Plating

    PCB Etched and Plated - Front
    PCB Etched and Plated – Front

    Continuing the saga from there, this is the etched and plated board.

    I mask around the edges with ordinary masking tape and cover the back surface with duct tape. Basically, the less copper you remove, the better and faster the job.

    I use ferric chloride etchant, formerly available in nearby Radio Shack stores. These days it’s getting harder to find, so I picked up a few kilos of dry powder on eBay. Most likely that supply will vanish, too.

    The usual directions call for heating the etchant, submerging the board, bubbling or agitating, and so forth and so on. The folks at Pulsar suggest simply rubbing the etchant on the board with a sponge and, perhaps not surprisingly, that works perfectly with boards sealed using their green film.

    I hold the board horizontally in my left hand, pour a dollop of etchant on it, then rub it with a small sponge in my right hand. The etchant gradually turns into a gel as it removes copper from the board; when the gel becomes too stiff, I just wipe it off with the sponge.

    I do this over a small glass tray and scrape the accumulated gunk off the sponge into the tray. Pulsar recommends diluting the residue in a gallon of water, but I’d just as soon not have that much spent solution sitting around.

    PCB Etched and Plated - Rear
    PCB Etched and Plated – Rear

    Wear latex gloves, an apron, and eye protection. Expect that everything within a radius of two meters will accrue small spots of ferric chloride that will instantly produce a vivid, permanent yellow stain. Repeat: everything within two meters will sprout yellow spots.

    You have been warned!

    Even if you pay attention to the board’s edges and corners, those will still be the last areas to finish etching. You’ll also learn to not run fine lines parallel to the edges right next to the masking tape, as the tape protects adjacent areas from the sponge: no contact, no etching!

    Spent ferric chloride (most likely, it’s now copper chloride or some such) disposal occurs on our town’s Household Hazmat collection days, but direct etching leaves very little bulk waste. Although it’s not particularly hazardous, the rituals should be observed.

    After eching, rinse the board, remove all the tape, and rinse the board again.

    Acetone and paper towels remove the green sealant film and the laser toner from the board, an operation best done outdoors. I have yet to find protective gloves that don’t disintegrate in acetone, so I simply try to not soak my hands in the stuff. Remember: leave the mask on the back side of the board to help protect it from the etchant when you do the front side.

    Then I silver-plate the copper with Cool-Amp Silver Plating Powder, which makes the board look and solder better. Looks are important, as the boards sometimes wind up in my Circuit Cellar columns.

    That hasn’t stopped me from hand-soldering SMD parts: the bigger the blob, the better the job.

  • Making PCBs: Masking and Fusing

    PCB Masked - Front
    PCB Masked – Front

    The next step in the process for this board: toner transfer masking.

    What you see here follows the basic process given by the folks at Pulsar, so go there for the instructions & supplies. The overall flow is:

    • Print the PCB trace pattern on the special paper
    • Align to the circuit board
    • Tape in place
    • Fuse toner to PCB
    • Apply green sealant film
    • Etch
    • Repeat for the other side

    Some tricks:

    An Eagle CAM file (found there in Useful Stuff) creates Postscript files for the top & bottom copper (and the silkscreen, although I don’t use that).

    I load those PS files in The GIMP at 600 dpi with mild antialiasing, crop (autoshrink!), combine into a single image, then print on a single sheet of paper using an HP Laserjet 1200 (obsolete, but pretty nearly any laser printer should work).

    Turn off all the toner saving features; you want a really dark image with plenty of toner!

    I run a sheet of paper through to find out exactly where the images will wind up, then tape the transfer paper atop the images (shiny side up!) using laser address labels (because they can take the heat) on the first-to-enter end of the transfer paper.

    Vital step: run that whole assembly through the printer to print a blank page. This cooks the moisture out of the transfer paper and pre-shrinks it for the next step. This might not matter for very small circuit boards, but if you’re doing anything over an inch or so, it makes a big difference.

    Run it through the printer again to print the trace patterns. They should wind up exactly in the middle of the transfer papers, although you’ll be surprised at how far off they can be from the patterns on the sheet underneath. Lasers have great dot resolution, but are not particularly accurate at locating the paper relative to the printing drum. That doesn’t matter for ordinary documents, but be sure you leave more margin on the transfer paper around your patterns than you think necessary.

    PCB Masked - Rear
    PCB Masked – Rear

    Use the printer’s manual-feed feature to queue up all three prints at once. My printer is in the basement laboratory and my comfy chair is upstairs, so that saves several trips up & down the stairs. Not that I can’t use the exercise, mind you, but it’s the principle of the thing.

    Cut the transfer paper off the backing sheet. Don’t bother trying to un-stick the labels; they’re fused solid. Stick another label on the back side of the transfer paper along shortest side.

    Alignment trick: now lay the paper pattern-side-up on a light table (I use an old fluorescent fixture with a frosted-glass lens), lay the board atop it, and adjust for best hole alignment over the whole board. The trace patterns on the paper form very nice bright spots that shine up through the holes in the circuit board. You can do it with the board on the bottom, but this way works better.

    You’ll be dismayed at how far off some of the holes are, but you should get within perhaps 10 mils all across the board. Squish the board down on the sticky side of the label and fold the label over the top of the board. That anchors the paper to the board and, because the label is fairly wide, keeps the paper from twisting relative to the board.

    Flip it over, verify that the holes still line up by looking through the paper, then apply labels to the sides to hold the transfer paper flat and in alignment. I’ve tried it without the side attachments and the result is, ahem, not quite as good. You can see the label residue on the front side in the photo above; obvously, you’ll be cleaning the gunk off before doing that side.

    I’ve tried the clothes-iron technique with little success, so I have one of the heated roller fusers. Works pretty well, although it requires some fiddling to get the proper combination of heat and spacing.

    Add water, let the paper soften, peel it off.

    Run it through the fuser again with the green sealer film. I get better results with a layer of ordinary paper atop the green film, perhaps because that prevents the film from touching anything inside the fuser. Without the paper, the film sometimes transfers lengthwise scratches to the toner.

    Peel off the film and touch up any imperfections with an Ultra-Fine-Point Sharpie; I use orange to make the corrections easy to see against the green background. Those are the highly visible ugly marks on the bottom mask.

    Having masked one side, etch it. Then you mask the other side and etch that. Don’t try to get clever and do both sides at once; it doesn’t work. Ask me how I know.

    Next step: etching. More on that later…

    Suggestions: after you etch the first side, leave the mask in place to protect the copper. When you run the board through the fuser, add a sheet of paper on the masked side to keep the film and toner from coming off on the rollers.

    Memo to self: always pre-shrink the transfer paper.

  • Drilling Eagle Printed Circuit Boards

    I use Cadsoft’s Eagle for schematics & circuit board layouts, then build the boards in my basement laboratory using Pulsar’s laser toner transfer and ferric-chloride etching. My Sherline CNC milling machine pokes the holes in the board, which means they actually wind up in the right places. I don’t mill the outline into any fancy shapes, generally using a tin snip and maybe a little filing; glass-fiber dust is a nuisance.

    AXIS hole-drilling screenshot
    AXIS hole-drilling screenshot

    My Eagle ulp routine (in the Useful Stuff page) extracts the holes from the circuit board layout, sorts by drill size, then visits each hole in nearest-neighbor order. It starts by touching each hole with a center drill, which probably isn’t necessary, but it makes me feel good and provides a last-minute check that everything is lined up properly.

    Figuring the tool path is obviously the traveling-salesman problem in disguise, but a strict nearest-neighbor order is close enough for boards of this size. You could probably optimize it by brute-force exhaustion and that would be appropriate for production use, but I rarely make more than one version of each board.

    Eagle’s standard part libraries use a weird set of hole diameters, which my routine rounds off to the nearest mil. I don’t have a vast array of drills, so I don’t pay much attention to the differences between, say, 0.024, 0.025, and 0.027 inch drills. Tool changes are strictly manual and I don’t have to change the drill if I don’t want to!

    Got a bunch of teeny carbide drills as resharps from DrillBitCity a long time ago.

    I double-stick-tape the board (center and corners) to a flycut sacrificial plate, which makes it flat enough for these purposes.The pic below shows a 60-mil board held down with masking tape; it’s the same layout as in the screen shot above.

    Tool changes use a 2-inch block (plus a sheet of paper) as a height reference. You can tweak the ulp file for your setup.

    My board layouts have a giant via at each corner, with the lower-left corner at (0,0). Drilling doesn’t require any fussy alignment, because I etch the board after drilling: the holes serve as bright lights to line up the pads & vias. I’ll have more to say about this elsewhere.

    Speeds and feeds are on the sissy side; I crank the 10k rpm head up to a dangerous chattering whine and feed the drills at 5 inches/min (call it 125 mm/min). Both of those are far too slow, but work OK.

    Run a shop vac to suck up the dust as you drill! I doubt that a typical shopvac filter removes the fines, but it’s better than letting all the dust settle on the mill and in my lungs.

    Circuit board drilling
    Circuit board drilling

    The clamps are these, mounted on studs screwed into the tooling plate.

    Incidentally, the Sherline mill’s throat depth and Y-axis travel limits the board to about 4 inches along the Y axis; yes, with the spacer block installed. That’s just about exactly the maximum size the low-end version of Eagle can produce, so it’s a nice match.

    There are other ways of doing PCBs. I haven’t tried trace-isolation milling, but PCB-Gcode looks like the ticket if you want to generate a breathtaking amount of glass-fiber dust. My quick check shows that it inserts semicolon-delimited comments into the tool-change commands, which EMC 2.2.8 promptly chokes upon, but that’s probably a quick configuration tweak and will change with EMC 2.3 anyway.

    If you’ve got the scratch, there are commercial solutions: Chris Daniel (who was also at the Cabin Fever EMC booth) uses a T-Tech gantry router at work.

    Memo to Self: Expect a call from a patent lawyer either telling me that I’m infringing somebody’s Nearest Neighbor Algorithm claims or asking me for my design notebooks to establish me as the Prior Artist.

  • Wireless Mouse Storage

    Wireless mice have fairly good power-saving routines; if they’re not moving, they shut down. Alas, if you’re packing a mouse to bring along with your PC, it may stay awake for the whole trip… at least until its battery goes flat.

    Isolating tab for storing a mouse
    Isolating tab for storing a mouse

    You can remove the cells, but then you’re stuck with a bunch of moving parts: mouse, receiver, a couple of AA cells. Now you need a ziplock baggie. Fooey.

    Better to take a strip of thin plastic, like a small plastic Post-It flag, and isolate one cell. Make it long enough to stick out through the slot in the case and you’ll have a reminder that the mouse won’t start up automagically.

    Mouse with battery disconnected and tabbed
    Mouse with battery disconnected and tabbed

    Some mice actually have a mechanical switch, but if it’s a pushbutton then you may as well insert the plastic strip.

    This works for cell phones, too, at least if you’re the sort who can afford to turn the phone off because you’re not expecting any calls.