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: PC Tweakage

Remembering which tweaks worked

  • LinuxCNC Electronics Case Mods

    I’m planning to put all the stepper driver bricks, solid state relays, power suppliers, miscellaneous doodads, and suchlike that will interface LinuxCNC with the M2 printer into a repurposed Dell desktop PC case.

    The front of the case had some tabs sticking out that anchored / aligned / captured various bits of hardware; grabbing them with a Vise-Grip, wiggling until the steel failed, and then filing the raw edge solved that problem:

    Dell PC case - removing small tabs
    Dell PC case – removing small tabs

    The PC had room for a diskette drive, with a lip protruding below the opening:

    Dell PC case - diskette drive slot tab
    Dell PC case – diskette drive slot tab

    A welding pliers wiggled nearly the entire tab at once:

    PC case - removing diskette drive tab
    PC case – removing diskette drive tab

    The bulky Dell front panel had four locating pins that mated with four round holes, one of which appears in the first picture. I wanted a somewhat less butt-ugly front than the bare metal grill, but still with some air flow into the case, so I found some 1/4 inch diameter standoffs tapped 4-40 that fit snugly in the holes and cut them to length:

    Dell PC case - trimming panel mounts
    Dell PC case – trimming panel mounts

    Another defunct Dell case contributed a side panel with roughly the right color. Four match-drilled clearance holes later:

    Dell PC case - vent panel
    Dell PC case – vent panel

    Just for effect, I squared up a slab of nice smoke-brown polycarb to cover the upper opening and perhaps hold das Blinkenlights. The slab was, as almost always happens, slightly too large for the Sherline, so I had to reclamp it to clean up all the sides. It came out about half a millimeter out of square and, being that type of guy, I clamped a block to the back of the table with a suitable spacer against the wide side, removed the spacer, loosened the step clamp on that end, rotated the slab against the block, made another pass, and it came out perfectly square:

    Dell PC case - squaring polycarb panel
    Dell PC case – squaring polycarb panel

    Four match-drilled holes and some epoxy later:

    Dell PC case - polycarb panel mounts
    Dell PC case – polycarb panel mounts

    I’ll probably put the main AC switch on that top panel, but it looks pretty good even with the protective paper on the back:

    Dell PC case - front panels
    Dell PC case – front panels

    I must mill a recess under the vent panel and counterbore the screw heads so everything fits flush and lines up neatly.

    Another chunk of aluminum will hold the stepper driver bricks along the front of the case:

    Dell PC case - stepper drive panel
    Dell PC case – stepper drive panel

    I laid out the holes with a square, eyeballed the spacing on a machinist’s scale, manually punched / drilled / tapped the holes, and it’s all good. The standoffs provide a bit of airflow around the edges; I don’t expect the drivers to get more than slightly warm, because they’re running near the bottom of their current rating. Incidentally, that sheet is a different and much nicer alloy than the pure aluminum I jeweled for the main base plate and will probably not use.

    The 24 VDC power supply will mount on the top of the case, up where the Dell PC supply used to reside. The supply has M4 tapped holes and, of course, I don’t have any such standoffs, but I did find some hex standoffs with 6-32 tapped holes on both ends. Bandsaw ’em in half and clean up the raw end to the proper length:

    Dell PC case - power supply standoffs - trimming
    Dell PC case – power supply standoffs – trimming

    Center drill in the lathe / drill / tap an M4 thread in each one, saw off some M4 screws, slather with red Loctite, insert studs into standoffs, and that should hold the power supply in place with 6-32 screws through the case top:

    Dell PC case - power supply standoffs
    Dell PC case – power supply standoffs

    More Quality Shop Time lies ahead, but it’s coming together…

  • HP ScanJet 3970 Lid Hinge Re-Repair

    As expected, that repair didn’t last very long at all; one hinge fractured along the same line as before. This time, however, we had a visit already in-plan, so I brought along my solvents and clamps.

    Perhaps you wondered how I could have been so remiss as to not brace those thin white flanges. One picture of the unbroken hinge in the “lid down” position is worth a thousand words:

    HP 3970 Scanjet - intact hinge
    HP 3970 Scanjet – intact hinge

    Need more? Here’s another thousand words from the other side:

    HP 3970 Scanjet - intact hinge pivot
    HP 3970 Scanjet – intact hinge pivot

    As the lid opens, the gray tab pivots toward the edge of the lid until it’s nearly parallel, at which point all of the force tries to yank those two flanges apart and then crack the tiny solid part at the pivot pin.

    Eventually, it succeeds. This is a view of the scanner base with the gray tab inserted in its slot, with the broken hinge in the “lid up” position:

    HP 3970 Scanjet - broken hinge pivot
    HP 3970 Scanjet – broken hinge pivot

    Clever design, no?

    I was unable to extract the broken fragment from the gray tab (actually, unwilling to apply more force, as I cracked part of the gray ring around the hinge pin), so this became an in situ repair. Once again, I applied solvent glue and squished the pieces together:

    HP 3970 Scanjet - glued hinge
    HP 3970 Scanjet – glued hinge

    And clamped it while we ate lunch:

    HP 3970 Scanjet - hinge clamping
    HP 3970 Scanjet – hinge clamping

    The brass rod applies the clamping force to the fractured part of the hinge through the pivot point. This isn’t the most stable clamp arrangement you’ve ever seen, but it worked well enough.

    I pushed the scanner back half a foot, so the lid now clunks against the wall just before the hinges reach their limit. Maybe they’ll survive until the next visit…

  • LinuxCNC: Optiplex 760 Setup

    I planned to use an old Dell Inspiron 531S AMD desktop for the LinuxCNC installation, but it turned out to have terrible interrupt latency, despite fiddling with all the available BIOS settings and video drivers. Mostly, it ran fine, but would occasionally burp up a millisecond-long latency spike for no apparent reason. So it’s now on the harvest / recycle heap.

    A new-to-me off-lease Dell Optiplex 760 Core 2 Duo in the SDT (Small Desktop Tower) configuration has similar latency numbers:

    Optiplex 760 latency - isolcpu 1
    Optiplex 760 latency – isolcpu 1

    What’s important here is that the latency remains rock-solid stable at those numbers. Contrary to my experience with the D520 and D525 Atoms, isolating one CPU for the real-time tasks didn’t make any noticeable difference, but it’s running that way because the overall performance isn’t a problem.

    Latency around 20 μs is near the upper limit for successful software step generation at any reasonable pace; the LinuxCNC description has more details. In round numbers, running the M2 at 500 mm/s needs a 40 kHz step rate in 1/16 microstep mode = a 25 μs period, which means 20 μs of jitter wouldn’t work well at all. Which is why I’m using Mesa FPGA card to get hardware step generation: it makes such problems Go Away.

    The Optiplex arrived with Windows Vista Business preinstalled; it dates back to mid-2009. I used System Rescue CD to shrink the Windows partition, added a few more, then installed LinuxCNC direct from the CD image (based on Ubuntu 10.04 LTS) and Xubuntu 13.04. The latter serves as a general-purpose installation for times when I don’t need LinuxCNC, because 10.04 is pretty much obsolete for anything other than real-time control.

    Digression 1: Yes, 10.04 LTS. TheRTAI project hasn’t released the patches that will slip the real-time kernel under the stock 3.x Linux kernel: LinuxCNC remains stuck at 10.04 LTS. Those changes have been coming Real Soon Now for quite a while; as with most Open Source projects, they could use more manpower and money. This isn’t a problem, as LinuxCNC is used for motion control, not a general-purpose operating system.

    The SDT case has room for two PCI cards and one PCI-E video card, so I installed the dual-head video card that couldn’t handle the U2711 monitor’s dual-DVI connection (although I’m using only DVI Output 1) and a Mesa 5i25. The middle “card” is actually a tiny PCB connected to a ribbon cable that brings out a second serial port (remember serial ports?) and what could be either or both of a PS2 keyboard or mouse connection (remember PS/2?).

    Optiplex 760 SDT - dual DVI - serial - 5i25
    Optiplex 760 SDT – dual DVI – serial – 5i25

    The back panel has a parallel printer port (which may come in handy for something) and a serial port, although you’re expected to have USB mice and keyboards these days. The front panel even has a floppy drive…

    Digression 2: LinuxCNC does not require a parallel printer port; this seems to be a common misconception among folks who don’t actually know how it works. The Mesa 5i25 FPGA card with a 7i76 step-direction daughter board provides high-resolution timing for five axes, rotary encoder inputs, a bunch of buffered digital I/O bits, a watchdog timer, plus various other useful odds and ends, all behind handy screw terminals.

    The Optiplex 760 has on-board VGA-class video that would also work fine, but the monitor I’m using has its VGA input connected to the box driving the Sherline mill and an unused DVI input. Having that dual-DVI monitor card lying around, I figured I could attach the same monitor to both systems and just poke the monitor’s input section button; I’ve found KVM switches unreliable in this application.

    The usual setup preps the system for public-key SSH on a nonstandard port, sets up the NFS mounts, and tweaks this-and-that: it’s running just fine.

    Digression 3: SSH kvetches when you swap server boxes at the same IP address, as well it should. If you’re foolish enough to have two separate Linux installs on the same box with the same IP, SSH reminds you every time you boot the other distro…

  • Automated Scan-and-Enhance: ImageMagick to the Rescue

    Mary’s folks enjoy the daily crossword, but they wanted a slightly larger edition… and, after a bit of procrastination, I conjured up an automated way to make it happen, so her father need not do this manually with The GIMP and Xsane.

    The scanner, an old HP Scanjet 3970, dropped off the Windows driver list after Vista, so it now runs only with Linux.

    Doing the scan is straightforward, as it’s the default scanner:

    scanimage --mode Gray --opt_emulategray=yes --resolution 300 -x 115 -y 210 --format=pnm & scan.pnm
    

    The X and Y coordinates set the scan dimensions in millimeters, which should be as small as possible consistent with scanning the whole crossword.

    The driver produces output image files in PNM format, which isn’t particularly common these days, or TIFFImageMagick knows what to do with both of them; I picked PNM.

    Unfortunately, for some unknown reason, the SANE driver produces a severely low-contrast image:

    HP3900 Grayscale Scan
    HP3900 Grayscale Scan

    ImageMagick can produce a histogram:

    convert scan.pnm histogram:hist.png
    

    Which shows the problem:

    HP3900 Grayscale Histogram
    HP3900 Grayscale Histogram

    That’s using the grayscale emulation mode: the driver does a Color scan and converts to Gray mode for the output image. It seems having the driver do the conversion produces better results than scanning directly in Color and then applying ImageMagick, but it’s not my scanner and I don’t have a lot of experience with it.

    Given the PNM image:

    • Blow out the contrast
    • Resize the scan to fill the page
    • Crisp up the edges a bit
    convert scan.pnm -level 45%,60% -resize 2400x3000 +repage -unsharp 0 trim.png
    

    Which looks like this:

    Crossword - contrasty resize
    Crossword – contrasty resize

    This being Linux, the best way to print something is with either Postscript or PDF. I used PDF, because then we can look at the results with Reader, a more familiar program than, say, Evince:

    convert -density 300 -size 2550x3300 canvas:white trim.png -gravity center -composite page.pdf
    

    Which centers the crossword on the page over a white background with enough margin to keep the printer happy:

    Crossword - full page
    Crossword – full page

    That PDF goes to the default printer queue, where it’s turned into Postscript and comes out exactly like it should:

    lp page.pdf
    

    I gimmicked the default printer instance to use only black ink by creating a separate CUPS printer with the appropriate defaults. Other programs pay no attention to that setting and the printer uses colored inks. There is no explanation I can find for any of this; Linux / CUPS printing is basically a black box operation.

    In theory, you could print the composited image file as a PNG or some such, but I cannot make it come out the right size in the right place.

    You could do all of that in one line, with one huge ImageMagick invocation kicking off the scan and firing the result to the printer, but leaving some intermediate results lying along the trail isn’t necessarily a Bad Thing. I should probably use random temporary file names, though, in the interest of not polluting the namespace.

    All this happened remotely, with me signed on through SSH: hooray for the command line. Had to use SCP a few times to fetch those intermediate files to puzzle over the results, too.

    The complete Bash script:

    #!/bin/bash
    scanimage --mode Gray --opt_emulategray=yes --resolution 300 -x 115 -y 210 --format=pnm > /tmp/scan.pnm
    convert /tmp/scan.pnm -level 45%,60% -resize 2400x3000 +repage -unsharp 0 /tmp/trim.png
    convert -density 300 -size 2550x3300 canvas:white /tmp/trim.png -gravity center -composite /tmp/page.pdf
    lp /tmp/page.pdf
    

    A slightly closer scan crop with left and top margins may also work, at the cost of more precise positioning on the scanner:

    #!/bin/bash
    scanimage --mode Gray --opt_emulategray=yes --resolution 300 -l 5 -t 6 -x 105 -y 190 --format=pnm > /tmp/scan.pnm
    
    
  • UDEV Rules for M2’s HAL Devices

    Rather than have a bunch of separate rule files for each USB HID device I’ll be using with LinuxCNC on the M2, here they are in one lump:

    cat /etc/udev/rules.d/hal-input.rules
    # Rules to configure input device permissions for hal_input
    
    ATTRS{product}=="Nostromo SpeedPad2",GROUP="plugdev",MODE="0660"
    ATTRS{product}=="Arduino Leonardo",GROUP="plugdev",MODE="0660"
    ATTRS{product}=="Logitech Dual Action",GROUP="plugdev",MODE="0660"
    

    The strings are case-sensitive and must match exactly. That post (among others) describes the whole dance required to get all the information.

    Remember to add yourself to the plugdev group, too.

  • Logitech Dual Action Gamepads: Mac vs. PC

    Turns out that there’s no difference between the Mac and PC versions of the Logitech Dual Action Gamepad:

    Logitech Dual Action Gamepads - Mac vs PC
    Logitech Dual Action Gamepads – Mac vs PC

    I picked up a Mac version cheap from the usual eBay seller and discovered that LinuxCNC / HAL was perfectly happy. That wasn’t too surprising; they have the same model and part numbers. Most likely, the only difference was the CD and maybe the Quick Start Guide that I didn’t get in the opened retail box…

    So now I have either a hot backup for the Joggy Thing or one for a different box.

    Most likely, it was cheap because nobody wants a blue-and-black peripheral next to their shiny white Mac…

  • Dual Monitors: devilspie2 FTW!

    Because it seems there’s no good support for separate X sessions with dual monitors these days, the landscape and portrait monitors on my desk represent viewports into a larger pixel array within a single X session. As a consequence, it’s entirely possible to slide windows across the gutter between the two displays (generally producing an essentially unusable result), but one cannot flip through workspaces on only one monitor.

    Worse, some programs seem to have trouble remembering that they were last seen on the portrait monitor, so I must rearrange the windows at the start of every session. First world problem, yeah, but still annoying.

    I’d previously used devilspie to force windows to their proper places across monitors, sessions, and workspaces, but its s-expression syntax was impenetrable and I eventually gave up using it.

    A fork (or continuation or something) called devilspie2 uses lua scripts that I can both read and write. It’s an Ubuntu package and easy to set up.

    A typical script in ~/.config/devilspie2 looks like this:

    if (get_application_name()=="Firefox") then
       set_window_geometry(0,0,1300,1200);
       maximize_vertically();
    end
    

    Putting Adobe Reader on the portrait monitor looks about the same:

    if (get_application_name()=="acroread") then
       unmaximize();
       set_window_geometry(2561,0,1000,100);
       maximize();
    end
    

    Set /usr/bin/devilspie2 as an auto-started program and it Just Works…