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.

Tag: M2

Using and tweaking a Makergear M2 3D printer

  • Juki TL-2010Q Needle LEDs: Simple Cable Clip

    A straightforward cable clip:

    TL-2010Q Needled COB LED - cable clip
    TL-2010Q Needled COB LED – cable clip

    It looks better than the previous hack bent from a snippet of PET clamshell:

    Juki TL-2010Q Needle LEDs - cable clip
    Juki TL-2010Q Needle LEDs – cable clip

    Ream out the holes with suitable drills, clean out the slot using Tiny Bandsaw™, and it’s all good.

    In retrospect, the slot isn’t worth the effort, because it doesn’t open wide enough to admit the cable and doesn’t provide any clamping force; a simple block with two holes would do as well. If the heatsink didn’t already have a 3 mm screw in play, I’d use an adhesive-backed clip from the early Kenmore LEDs.

    The OpenSCAD source code isn’t much to look at:

    //-----
    // Cable clip
    // Reoriented into build position, because we only need one
    
    ClipWall = 3*ThreadWidth;
    Clip = [15.0,10.0,CableOD + 2*ClipWall];
    
    module CableClip(CableOD = 2.0) {
    
    ClipSides = 4*3;
    ClipRadius = Clip.y/2;
    ScrewOD = 3.0;
    ClipOC = Clip.x - ClipRadius - CableOD/2 - ClipWall;
    
      translate([0,0,Clip.y/2])
        rotate([90,0,90])
          translate([0,0,0*Clip.z/2])
            difference() {
              union() {
                rotate(180/ClipSides)
                  cylinder(d=Clip.y/cos(180/ClipSides),h=Clip.z,$fn=ClipSides,center=true);
                translate([ClipRadius,0,0])
                  cube([Clip.x - ClipRadius,Clip.y,Clip.z],center=true);
              }
              translate([0,0,-(Clip.z/2 + Protrusion)])
                rotate(180/8)
                  PolyCyl(ScrewOD,Clip.z + 2*Protrusion,8);
              rotate([90,0,0])
                translate([ClipOC,0,-Clip.y])
                  rotate(180/8)
                  PolyCyl(CableOD,2*Clip.y,8);
              translate([ClipOC - Clip.x/2,0,0])
                cube([Clip.x,2*Clip.y,2*ThreadWidth],center=true);
            }
    }
    

  • SJCAM M20 Camera: Tour Easy Seat Mount

    The general idea is to replace this:

    M20 in waterproof case - Tour Easy seat
    M20 in waterproof case – Tour Easy seat

    With this:

    SJCAM M20 Mount - Tour Easy side view
    SJCAM M20 Mount – Tour Easy side view

    Thereby solving two problems:

    • Pitifully small battery capacity
    • Wobbly camera support

    The battery is an Anker PowerCore 13000 Power Bank plugged into the M20’s USB port. Given that SJCAM’s 1 A·h batteries barely lasted for a typical hour of riding, the 13 A·h PowerCore will definitely outlast my legs. The four blue dots just ahead of the strap around the battery show it’s fully charged and the blue light glowing through the case around the M20 indicates it’s turned on.

    The solid model has four parts:

    SJCAM M20 Mount - Fit layout
    SJCAM M20 Mount – Fit layout

    Which, as always, incorporates improvements based on the actual hardware on the bike.

    A strap-and-buckle belt harvested from a defunct water pack holds the battery into the cradle and the cradle onto the rack, with a fuzzy velcro strip stuck to the bottom to prevent sliding:

    SJCAM M20 Mount - Tour Easy rear view
    SJCAM M20 Mount – Tour Easy rear view

    The shell around the camera is basically a box minus the camera:

    SJCAM M20 Mount - Show - shell
    SJCAM M20 Mount – Show – shell

    The shell builds as three separate slabs, with the center section having cutouts ahead of the camera’s projections to let it slide into place:

    SJCAM M20 Mount - Show - shell sections
    SJCAM M20 Mount – Show – shell sections

    The new shell version is 30.5 mm thick, so a 40 mm screw will stick out maybe 5 mm beyond the nylon locknut. I trust the screws will get lost in the visual noise of the bike.

    A peg sticking out behind the USB jack anchors the cable in place:

    SJCAM M20 Mount - Show - shell sections - USB side
    SJCAM M20 Mount – Show – shell sections – USB side

    The front slab and center top have curves matching the M20 case:

    SJCAM M20 Mount - Show - shell sections - button side
    SJCAM M20 Mount – Show – shell sections – button side

    The camera model has a tidy presentation option:

    SJCAM M20 Mount - Show - M20 body
    SJCAM M20 Mount – Show – M20 body

    And an ugly option to knock the protruberances out of the shell:

    SJCAM M20 Mount - Show - M20 body - knockouts
    SJCAM M20 Mount – Show – M20 body – knockouts

    The square-ish post on the base fits into an angled socket in the clamp around the seat rail:

    SJCAM M20 Mount - Show - clamp
    SJCAM M20 Mount – Show – clamp

    The numbers correspond to the “Look Angle” of the socket pointing the camera toward overtaking traffic. The -20° in the first clamp shows a bit too much rack:

    SJCAM M20 Mount - first ride - traffic - 2019-02-06
    SJCAM M20 Mount – first ride – traffic – 2019-02-06

    It may not matter, though, as sometimes you want to remember what’s on the right:

    SJCAM M20 Mount - first ride - 2019-02-06
    SJCAM M20 Mount – first ride – 2019-02-06

    FWIW, the track veering off onto the grass came from a fat-tire bike a few days earlier. Most of the rail trail had cleared by the time we tried it, with some ice and snow in rock cuts and shaded areas.

    Contrary to the first picture, I later remounted the camera under the seat rail with its top side downward. The M20 has a “rotate video” mode for exactly that situation, which I forgot to turn off in the fancy new mount, so I rotated the pix afterward.

    A 3 mm screw extends upward through the hole in the socket to meet a threaded brass insert epoxied into the shell base, as shown in the uglified M20 model. Despite appearances, the hole is perpendicular to both the socket and the shell, so you can tweak the Look Angle without reprinting the shell.

    All in all, the mount works well. We await better riding weather …

    The OpenSCAD source code as a GitHub Gist:

    // SJCAM M20 Camera Mount for Tour Easy seat back rail
    // Ed Nisley – KE4ZNU
    // 2019-02
    /* [Layout Options] */
    Layout = "Fit"; // [Show,Fit,Build]
    Part = "Shell"; // [Cradle,Shell,Clamp,ShellSections,M20,Interposer,Battery,Buttons]
    LookAngle = [0,5,-25]; // camera angle, looking backwards
    /* [Extrusion Parameters] */
    ThreadWidth = 0.40;
    ThreadThick = 0.25;
    HoleWindage = 0.2;
    Protrusion = 0.1;
    //—–
    // Dimensions
    /* [Hidden] */
    ID = 0;
    OD = 1;
    LENGTH = 2;
    ClampScrew = [5.0,10.0,50.0]; // ID=thread OD=washer LENGTH=total
    ClampInsert = [5.0,7.5,10.5]; // brass insert
    MountScrew = [3.0,7.0,23]; // ID=thread OD=washer LENGTH=tune to fit clamp arch
    MountInsert = [3.0,4.95,8.0]; // ID=screw OD, OD=knurl dia
    EmbossDepth = 2*ThreadThick + Protrusion; // recess depth + Protrusion beyond surface
    DebossHeight = EmbossDepth; // text height + Protrusion into part
    Projection = 10; // stick-out to punch through shell sides & suchlike
    SupportColor = "Yellow";
    FadeColor = "Green";
    FadeAlpha = 0.25;
    //—–
    // Useful routines
    function IntegerMultiple(Size,Unit) = Unit * ceil(Size / Unit);
    module PolyCyl(Dia,Height,ForceSides=0) { // based on nophead's polyholes
    Sides = (ForceSides != 0) ? ForceSides : (ceil(Dia) + 2);
    FixDia = Dia / cos(180/Sides);
    cylinder(r=(FixDia + HoleWindage)/2,
    h=Height,
    $fn=Sides);
    }
    //—–
    // M20 Camera
    // Looks backwards from seat = usual right-hand coordinates work fine
    // X parallel to bike frame, Y parallel to seat strut, Z true vertical
    M20 = [24.5,40.5,54.0];
    M20tm = 4.0; // chord height at top of case
    M20tr = (pow(M20tm,2) + pow(M20.y,2)/4) / (2*M20tm); // … radius
    echo(str("Top radius: ",M20tr));
    M20TopSides = 3*3*4;
    echo(str(" … sides: ",M20TopSides));
    M20fm = 1.0; // chord height at front of case
    M20fr = (pow(M20fm,2) + pow(M20.y,2)/4) / (2*M20fm); // … radius
    echo(str("Front radius: ",M20fr));
    M20FrontSides = ceil(M20fr / M20tr * M20TopSides); // make arc sides match up
    echo(str(" … sides: ",M20FrontSides));
    Lens = [19.0,22.5,5.5]; // ID=optical element, OD=tube
    LensBezel = [23.0,24.5,2.5]; // ID=lens tube, OD=bezel
    LensOffset = [-M20fm,0,41.5]; // bottom of case to lens centerline
    LensCap = [Lens[OD],24.5,4.5]; // silicone lens cap
    Spkr = [0.75,M20.y,14.3]; // speaker recess below LCD
    Switch = [8.0,1.0,38.0]; // selection switches
    SwitchOffset = [9.0,0,0]; // from rear to center of switches
    Jack = [10.0,0.1,36.0]; // jack and MicroSD card access, slightly enlarged
    JackOffset = [10.0,0,30.0]; // rear, bottom to center of jack block
    USB = [JackOffset.x – Jack.x/2,20.0,10.0]; // strut under USB plug
    USBOffset = [0,0,33.5]; // bottom to center of jack
    SDCard = [2.0,0.1,12.0]; // SD Card slot
    SDOffset = [9.0,0,20.0]; // bottom, rear to center of slot
    Button = [8.5,10.5,M20tm]; // ID = button, OD = bezel
    ButtonOC = 18.0; // on-center Y separation, assume X centered
    Screen = [0.1,31,24]; // LCD on rear face
    ScreenOffset = [0,0,33];
    BarLEDs = [0.1 + M20fm,12.0,5.0]; // Bar LEDs on front face
    BarLEDsOffset = [-M20fm,0,12.5];
    PwrLED = [3.5,3.5,0.1 + M20tm]; // power LED on top
    PwrLEDOffset = [2.5,0,0];
    RearLEDs = [1.0,2.0,0.1]; // charge and power LED openings above LCD
    RearLEDsOffset = [0,13.0/2,M20tm + 3.0]; // .. from top center of case
    module Buttons(KO) {
    for (j = [-1,1])
    translate([0,j*ButtonOC/2,0]) {
    cylinder(d=Button[OD],h=Button[LENGTH],$fn=12);
    if (KO)
    translate([0,0,M20tm])
    cylinder(d1=Button[OD],d2=1.5*Button[OD],h=Button.z,$fn=12);
    }
    }
    module M20Shape(Knockout = false) {
    difference() {
    intersection() {
    translate([0,0,M20.z/2 – M20tr]) // top curve
    rotate([0,90,0]) rotate(180/M20TopSides)
    cylinder(r=M20tr,h=2*(M20.x + Protrusion),$fn=M20TopSides,center=true);
    translate([M20.x/2 – M20fr,0,0])
    rotate(180/M20FrontSides)
    cylinder(r=M20fr,h=2*M20.z,$fn=M20FrontSides,center=true);
    cube(M20,center=true);
    }
    translate([Spkr.x/2 – M20.x/2 – Protrusion,0,Spkr.z/2 – Protrusion/2 – M20.z/2])
    cube(Spkr + [Protrusion,2*Protrusion,Protrusion],center=true);
    }
    translate([M20.x/2,0,-M20.z/2] + LensOffset)
    rotate([0,90,0])
    cylinder(d=Lens[OD] + HoleWindage,h=(Knockout ? Projection : Lens[LENGTH]),$fn=4*4*3,center=false);
    translate([M20.x/2 + M20fm/2,0,-M20.z/2] + LensOffset) // lens bezel
    rotate([0,90,0])
    cylinder(d1=LensBezel[OD],d2=Lens[OD],h=LensBezel[LENGTH],$fn=4*4*3,center=false);
    translate([-M20.x/2 + SwitchOffset.x, // side switches
    -(Switch.y + M20.y – Protrusion)/2,
    0])
    cube(Switch + [0,Protrusion,0] + (Knockout ? [0,Projection,0] : [0,0,0]),center=true);
    if (Knockout)
    translate([(M20.x/2 – M20fm)/2,-M20.y/2,0]) // side switch slide-in clearance
    cube([M20.x/2 – M20fm,2*Switch.y,Switch.z],center=true);
    translate([-M20.x/2 + JackOffset.x,
    (Jack.y + M20.y – Protrusion)/2,
    JackOffset.z – M20.z/2])
    cube(Jack + [0,Protrusion,0] + (Knockout ? [0,Projection,0] : [0,0,0]),center=true);
    translate([0,0,M20.z/2 – M20tm]) // top control buttons
    Buttons(Knockout);
    if (Knockout)
    translate([(M20.x – M20fm)/4,0,M20.z/2 – M20tm + Button[LENGTH]/2]) // slide-in button clearance
    cube([(M20.x – M20fm)/2,ButtonOC + Button[OD],Button[LENGTH]],center=true);
    translate([-(M20.x + Screen.x – Protrusion)/2,0,-M20.z/2] + ScreenOffset)
    cube(Screen + [Protrusion,0,0] + (Knockout ? [Projection,0,0] : [0,0,0]),center=true);
    for (j = [-1,1])
    translate([-M20.x/2 + Protrusion,j*RearLEDsOffset.y,M20.z/2 – RearLEDsOffset.z])
    rotate([0,-90,0]) rotate(180/6)
    PolyCyl(RearLEDs[OD],Knockout ? Projection : RearLEDs[LENGTH],6);
    translate([M20.x/2 + BarLEDs.x/2,0,-M20.z/2] + BarLEDsOffset)
    cube(BarLEDs + (Knockout ? [Projection,0,0] : [0,0,0]),center=true);
    translate([0,0,M20.z/2 – M20tm] + PwrLEDOffset)
    rotate(180/8)
    PolyCyl(PwrLED[OD],(Knockout ? Projection : PwrLED[LENGTH]),8);
    if (Knockout) {
    translate([0,0,-M20.z/2])
    rotate([180,0,0]) { // mounting screw
    PolyCyl(MountScrew[ID],MountScrew[LENGTH],6);
    translate([0,0,MountScrew[LENGTH] – Protrusion])
    PolyCyl(MountScrew[OD],MountScrew[ID] + 4*ThreadThick,6); // SHCS head is about 1 ID long
    }
    translate([0,0,-(M20.z/2 + MountInsert[LENGTH] + 4*ThreadWidth – Protrusion)])
    PolyCyl(MountInsert[OD],MountInsert[LENGTH] + 4*ThreadWidth,6); // insert inside Interposer
    }
    }
    //—–
    // Shell
    // Wraps around camera
    NomWall = 3.0;
    ShellWall = [IntegerMultiple(NomWall,ThreadThick),
    IntegerMultiple(NomWall,ThreadWidth),
    IntegerMultiple(NomWall,ThreadWidth)];
    ShellRadius = ShellWall.x;
    ShellSides = 8;
    ShellOA = M20 + 2*ShellWall;
    echo(str("Shell OA: ",ShellOA));
    Interposer = [M20.x – M20fm,M20.x – M20fm,10.0]; // if you can't be smart, be square
    module Shell() {
    Screw = [3.0,6.75,30]; // ID=thread OD=washer LENGTH
    ScrewClear = 1.0; // additional washer clearance
    ScrewSides = 8;
    ScrewOC = M20 + [0,Screw[ID]/cos(180/ScrewSides),Screw[ID]/cos(180/ScrewSides)]; // use PolyCyl hole dia, ignore .x value
    difference() {
    union() {
    hull()
    for (i=[-1,1], j=[-1,1], k=[-1,1])
    translate([i*(ShellOA.x – 2*ShellRadius)/2,
    j*(ShellOA.y – 2*ShellRadius)/2,
    k*(ShellOA.z – 2*ShellRadius)/2])
    sphere(r=ShellRadius/cos(180/ShellSides),$fn=ShellSides); // fix low-poly approx radius
    for (j=[-1,1], k=[-1,1]) // screw bosses, full length
    translate([0,j*ScrewOC.y/2,k*ScrewOC.z/2])
    rotate([0,90,0]) rotate(180/ScrewSides)
    cylinder(d=Screw[OD] + ScrewClear,h=ShellOA.x,center=true,$fn=ScrewSides);
    translate([-(ShellOA.x – USB.x – ShellWall.x)/2, // USB plug support strut
    (M20.y + USB.y)/2 – ShellRadius,
    -M20.z/2] + USBOffset)
    hull()
    for (i=[-1,1], j=[-1,1], k=[-1,1])
    translate([i*(USB.x + ShellWall.x – 2*ShellRadius)/2,
    j*(USB.y – 2*ShellRadius)/2,
    k*(USB.z – 2*ShellRadius)/2])
    rotate(0*180/ShellSides) rotate([90,0,90])
    sphere(r=ShellRadius/cos(180/ShellSides),$fn=ShellSides);
    translate([-M20fm/2,0,-ShellOA.z/2 – Interposer.z + Protrusion/2])
    InterposerShape(Embiggen = false);
    }
    render(convexity=4) // remove camera shape from interior
    M20Shape(Knockout = true);
    for (j=[-1,1], k=[-1,1]) // screw bores
    translate([-ShellOA.x,j*ScrewOC.y/2,k*ScrewOC.z/2])
    rotate([0,90,0]) rotate(180/ScrewSides)
    PolyCyl(Screw[ID],2*ShellOA.x,ScrewSides);
    translate([ShellOA.x/2 – ThreadThick + Protrusion/2,0,-5]) // recess for legend
    cube([EmbossDepth,ShellOA.y – 12,7],center=true);
    translate([0,(M20.y + 1.5*SDCard.z)/2 + ThreadWidth,-M20.z/2 + SDOffset.z])
    resize([M20.x,0,0])
    sphere(d=1.5*SDCard.z,$fn=24);
    }
    translate([ShellOA.x/2 – DebossHeight,0,-5])
    rotate([90,0,90])
    linear_extrude(height=DebossHeight,convexity=20)
    text(text="KE4ZNU",size=5,spacing=1.20,font="Arial:style:Bold",halign="center",valign="center");
    // Totally ad-hoc support structures
    if (false)
    color(SupportColor) {
    for (j=[-1,1], k=[0,1])
    translate([-ShellOA.x/2 + Screw[LENGTH],j*ShellOA.y/2,k*ShellOA.z])
    rotate([0,90,0])
    SupportScrew(Dia=Screw[OD] + ScrewClear,Length=ShellOA.x – Screw[LENGTH],Num=ScrewSides);
    }
    }
    // Generate support structure for screw boss
    module SupportScrew(Dia,Length,Num = 6) {
    for (a=[0 : 360/Num : 360/2])
    rotate(a)
    translate([0,0,(Length + ThreadThick)/2])
    cube([Dia – 2*ThreadWidth,2*ThreadWidth,Length – ThreadThick],center=true);
    }
    // Generate interposer block
    // Origin at center bottom surface for E-Z rotation
    module InterposerShape(Embiggen = false) {
    translate([0,0,Interposer.z/2])
    if (Embiggen) {
    minkowski() {
    cube(Interposer,center=true);
    cube(HoleWindage,center=true);
    }
    }
    else
    cube(Interposer + [-Protrusion,0,Protrusion],center=true); // avoid slivers, merge with shell
    }
    // Cut shell sections for printing
    // "Front" = lens end, toward +X direction
    // origin centered on M20.xyz and ShellOA.xyz
    module ShellSection(Section="Front") {
    if (Section == "Front") // include front curve
    intersection() {
    Shell();
    translate([ShellOA.x – (M20fm + ShellWall.x),0,0])
    cube([ShellOA.x,2*ShellOA.y,2*ShellOA.z],center=true);
    }
    else if (Section == "Center") // exclude front curve for E-Z printing
    intersection() {
    Shell();
    translate([-M20fm/2,0,0])
    cube([M20.x – M20fm,2*ShellOA.y,2*ShellOA.z],center=true);
    }
    else if (Section == "Back") // flush with LCD on rear face
    intersection() {
    Shell();
    translate([-ShellOA.x + (ShellWall.x),0,0])
    cube([ShellOA.x,2*ShellOA.y,2*ShellOA.z],center=true);
    }
    }
    //—–
    // Clamp
    // Grips seat frame rail
    // Uses shell rounding values for tidiness
    // Adjust MountScrew[LENGTH] to put head more-or-less flush with clamp arch
    RailOD = 20.0; // slightly elliptical in bent section
    RailSides = 2*3*4;
    ClampOA = [60.0,40.0,ClampScrew[LENGTH]]; // set clamp size to avoid weird screw spacing
    echo(str("Clamp OA: ",ClampOA));
    ClampOffset = 0.0; // raise clamp to allow more room for mount
    ClampTop = ClampOA.z/2 + ClampOffset;
    InsertCap = 6*ThreadThick; // fill layers atop inserts
    Kerf = 2.0;
    module Clamp(Support = false) {
    RibThick = 2*ThreadWidth;
    NumRibs = IntegerMultiple(ceil(ClampOA.y / 4.0),2); // space ribs roughly 4 mm apart
    RibSpace = ClampOA.y / NumRibs;
    echo(str("Ribs: ",NumRibs," spaced: ",RibSpace));
    ClampScrewOC = IntegerMultiple(ClampOA.x – ClampScrew[OD] – 10*ThreadWidth,1.0);
    echo(str("ClampScrew OC: ",ClampScrewOC));
    difference() {
    hull()
    for (i=[-1,1], j=[-1,1], k=[-1,1])
    translate([i*(ClampOA.x – 2*ShellRadius)/2,
    j*(ClampOA.y – 2*ShellRadius)/2,
    k*(ClampOA.z – 2*ShellRadius)/2 + ClampOffset])
    sphere(r=ShellRadius/cos(180/ShellSides),$fn=ShellSides);
    cube([2*ClampOA.x,2*ClampOA.y,Kerf],center=true); // split across middle
    rotate([90,0,0]) // seat rail
    cylinder(d=RailOD,h=2*ClampOA.y,$fn=RailSides,center=true);
    for (i=[-1,1]) // clamp inserts
    translate([i*ClampScrewOC/2,0,0])
    rotate(180/6)
    PolyCyl(ClampInsert[OD],ClampTop – InsertCap,6);
    for (i=[-1,1]) // clamp screw clearance
    translate([i*ClampScrewOC/2,0,-(ClampOA.z/2 – ClampOffset) – InsertCap])
    rotate(180/6)
    PolyCyl(ClampScrew[ID],ClampOA.z,6);
    translate([0,0,ClampTop + 0.7*Interposer.z]) // mounting bolt hole
    rotate(LookAngle)
    translate([0,0,ShellOA.z/2]) {
    M20Shape(Knockout = true);
    translate([0,0,-ShellOA.z/2 – Interposer.z])
    InterposerShape(Embiggen = true);
    }
    translate([ClampOA.x/2 – (EmbossDepth – Protrusion)/2, // recess for LookAngle.z
    0,
    ClampOA.z/4 + ClampOffset])
    cube([EmbossDepth,17,8],center=true);
    translate([0.3*ClampOA.x, // recess for LookAngle.z
    -(ClampOA.y/2 – (EmbossDepth – Protrusion)/2),
    ClampOA.z/4 + ClampOffset])
    cube([10,EmbossDepth,8],center=true);
    translate([0,0,-ClampOA.z/2 + (EmbossDepth – Protrusion)/2]) // recess bottom legend
    cube([35,10,EmbossDepth],center=true);
    }
    translate([ClampOA.x/2 – DebossHeight,0,ClampOA.z/4 + ClampOffset]) // LookAngle.z legend
    rotate([90,0,90])
    linear_extrude(height=DebossHeight,convexity=20)
    text(text=str(LookAngle.z),size=6,spacing=1.20,
    font="Arial:style:Bold",halign="center",valign="center");
    translate([0.3*ClampOA.x,-ClampOA.y/2 + DebossHeight + Protrusion/2,ClampOA.z/4 + ClampOffset]) // LookAngle.y legend
    rotate([90,0,00])
    linear_extrude(height=DebossHeight,convexity=20)
    text(text=str(LookAngle.y),size=6,spacing=1.20,
    font="Arial:style:Bold",halign="center",valign="center");
    translate([0,0,-ClampOA.z/2])
    linear_extrude(height=DebossHeight,convexity=20)
    mirror([0,1,0])
    text(text="KE4ZNU",size=5,spacing=1.20,
    font="Arial:style:Bold",halign="center",valign="center");
    if (Support) {
    difference() {
    color(SupportColor)
    union() {
    for (j=[-NumRibs/2:NumRibs/2])
    translate([0,j*RibSpace,0])
    rotate([90,0,0])
    cylinder(d=RailOD – 2*ThreadThick,h=RibThick,$fn=2*3*4,center=true);
    cube([RailOD – 4*ThreadWidth,NumRibs*RibSpace,Kerf + 2*ThreadThick],center=true);
    }
    cube([2*ClampOA.x,2*ClampOA.y,Kerf],center=true); // split across middle
    }
    }
    }
    //—–
    // Battery
    // Based on Anker PowerCore, simplified shapes
    // Includes port & button punchouts
    Battery = [97.5,80.0,22.5]; // X=length, Y includes rounded edges, Z = Y dia
    module BatteryShape() {
    USB = [Projection,38,10]; // clearance around USB output ports
    USBOffset = [0,25.5,0]; // from -Y edge to center of USB block
    ChargeBtn = [11.0 + 5.0,10,5.0 + 5.0]; // charge level check button, enlarged
    Btnc = ChargeBtn.z; // figure button recess into battery curve
    Btnr = Battery.z/2;
    Btnm = Btnr – sqrt(pow(Btnr,2) – pow(Btnc,2)/4);
    ChargeBtnOffset = [17.0,0,0]; // from +X edge to center, centered on Z
    BatterySides = 2*3*4;
    hull()
    for (j=[-1,1])
    translate([0,j*(Battery.y – Battery.z)/2,0])
    rotate([0,90,0])
    cylinder(d=Battery.z,h=Battery.x,$fn=BatterySides,center=true);
    translate([(Battery.x + USB.x)/2 – Protrusion,-Battery.y/2 + USBOffset.y,0])
    cube(USB,center=true);
    translate([Battery.x/2 – ChargeBtnOffset.x,Battery.y/2 + ChargeBtn.y/2 – 2*Btnm,0])
    cube(ChargeBtn,center=true);
    }
    //—–
    // Battery cradle
    RackWidth = 89.0; // flat width between rack rails
    CradleWall = [4.0,4.0,3.0]; // wall thickness
    CradleRadius = 2.0; // corner rounding
    CradlePad = 0.5; // cushion around battery
    BatteryBase = CradleWall.z + CradlePad; // actual bottom surface of battery
    CradleOA = [Battery.x + 2*CradleWall.x,
    min((Battery.y + 2*CradleWall.y),RackWidth),
    BatteryBase + Battery.z/3];
    echo(str("Cradle OA: ",CradleOA));
    module Cradle() {
    difference() {
    hull()
    for (i=[-1,1], j=[-1,1]) { // box with tidy rounded corners
    translate([i*(CradleOA.x/2 – CradleRadius),
    j*(CradleOA.y/2 – CradleRadius),
    1*(CradleOA.z – CradleRadius)])
    sphere(r=CradleRadius,$fn=6);
    translate([i*(CradleOA.x/2 – CradleRadius),
    j*(CradleOA.y/2 – CradleRadius),
    0*(CradleOA.z/2 – CradleRadius)])
    cylinder(r=CradleRadius,h=CradleOA.z/2,$fn=6);
    }
    translate([0,0,Battery.z/2 + BatteryBase]) // minus the battery
    minkowski(convexity=3) { // … slightly embiggened
    BatteryShape();
    cube(2*CradlePad,center=true);
    }
    if (false) // reveal insets for debug
    translate([0,0,-Protrusion])
    cube(CradleOA + [0,0,CradleOA.z],center=false);
    translate([0,0,CradleWall.z – ThreadThick + Protrusion/2]) // recess top legend
    cube([55,20,EmbossDepth],center=true);
    translate([0,0,(EmbossDepth – Protrusion)/2]) // recess bottom legend
    cube([70,15,EmbossDepth],center=true);
    }
    translate([0,4.0,CradleWall.z – DebossHeight – Protrusion])
    linear_extrude(height=DebossHeight,convexity=20)
    text(text="PowerCore",size=6,spacing=1.20,
    font="Arial:style:Bold",halign="center",valign="center");
    translate([0,-4.0,CradleWall.z – DebossHeight – Protrusion])
    linear_extrude(height=DebossHeight,convexity=20)
    text(text="13000",size=6,spacing=1.20,
    font="Arial:style:Bold",halign="center",valign="center");
    linear_extrude(height=DebossHeight,convexity=20)
    mirror([0,1,0])
    text(text="KE4ZNU",size=10,spacing=1.20,
    font="Arial:style:Bold",halign="center",valign="center");
    }
    //—–
    // Build things
    // Layouts for design & tweaking
    if (Layout == "Show")
    if (Part == "Battery")
    BatteryShape();
    else if (Part == "Buttons")
    Buttons();
    else if (Part == "Interposer")
    InterposerShape(Embiggen = false);
    else if (Part == "Shell")
    Shell();
    else if (Part == "M20")
    M20Shape(Knockout = false);
    else if (Part == "ShellSections") {
    translate([ShellOA.x,0,0])
    ShellSection(Section="Front");
    translate([0,0,0])
    ShellSection(Section="Center");
    translate([-ShellOA.x,0,0])
    ShellSection(Section="Back");
    }
    else if (Part == "Clamp") {
    Clamp(Support = false);
    color(FadeColor,FadeAlpha)
    rotate([90,0,0])
    cylinder(d=RailOD,h=2*ClampOA.y,$fn=RailSides,center=true);
    }
    else if (Part == "Cradle") {
    Cradle();
    translate([0,0,Battery.z/2 + CradleWall.z])
    color(FadeColor,FadeAlpha)
    BatteryShape();
    }
    // Build layouts for top-level parts
    if (Layout == "Build")
    if (Part == "Cradle")
    Cradle();
    else if (Part == "Clamp") {
    translate([0,0.7*ClampOA.y,0])
    difference() {
    translate([0,0,-Kerf/2])
    Clamp(Support = true);
    translate([0,0,-ClampOA.z])
    cube(2*ClampOA,center=true);
    }
    translate([0,-0.7*ClampOA.y,-0])
    difference() {
    translate([0,0,-Kerf/2])
    rotate([0,180,0])
    Clamp(Support = true);
    translate([0,0,-ClampOA.z])
    cube(2*ClampOA,center=true);
    }
    }
    else if (Part == "Shell") {
    translate([0,-1.2*ShellOA.y,ShellOA.x/2])
    rotate([0,90,180])
    ShellSection(Section="Front");
    translate([0,0,M20.x/2])
    rotate([0,-90,0])
    ShellSection(Section="Center");
    translate([0,1.4*ShellOA.y,ShellOA.x/2])
    rotate([0,-90,180])
    ShellSection(Section="Back");
    }
    // Ad-hoc arrangement to see how it all goes together
    if (Layout == "Fit") {
    rotate(180) {
    Cradle();
    translate([0,0,Battery.z/2 + CradleWall.z])
    color(FadeColor,FadeAlpha)
    BatteryShape();
    }
    translate([0,-100,0]) {
    Clamp();
    color(FadeColor,FadeAlpha)
    rotate([90,0,0])
    cylinder(d=RailOD,h=2*ClampOA.y,$fn=RailSides,center=true);
    }
    translate([0,-100,(ClampOA.z + ShellOA.z)/2 + Interposer.z])
    translate([0,0,-ShellOA.z/2 + Interposer.z])
    rotate(LookAngle)
    translate([0,0,ShellOA.z/2]) {
    Shell();
    color(FadeColor,FadeAlpha)
    M20Shape(Knockout = false);
    }
    }

  • Makergear M2: Z-Axis Platform Sensor Switch, Replacement Thereof

    After nearly four years of dangling a bare millimeter above the nozzle, the lever on the relocated Z-Axis switch finally snagged a stray thread and got bent out of shape. I un-bent it, but finally decided it was time to get more air between the nozzle and the switch actuator.

    The small shim reduces the actuation distance:

    file:///mnt/bulkdata/Cameras/2019/Shop Projects/Makergear M2/Z-Axis Switch/IMG_20190204_185300 - M2 Z-Axis - microswitch exterior
    file:///mnt/bulkdata/Cameras/2019/Shop Projects/Makergear M2/Z-Axis Switch/IMG_20190204_185300 – M2 Z-Axis – microswitch exterior

    Prying the ends outward with a thumbnail releases a pair of snaps and the cover pops off to reveal the innards:

    M2 Z-Axis - microswitch interior
    M2 Z-Axis – microswitch interior

    The spring-loaded innards will launch themselves into the far corners of your shop, so be gentle as you slide the lever out and reinstall the side plate with a pair of clicks.

    I filed the screw holes in my homebrew brass angle plate into slots, so as to get some adjustability, remounted the switch on the X-axis gantry, and tuned for best clearance:

    M2 Z-Axis - bare microswitch vs nozzle
    M2 Z-Axis – bare microswitch vs nozzle

    It looks a bit more canted than it really is.

    There’s about 1.6 mm of Z-axis distance between the nozzle and the switch, which should suffice for another few years.

    The view from the front shows a slight angle, too:

    M2 Z-Axis - activated
    M2 Z-Axis – activated

    There’s a millimeter or so below the nuts holding the X-axis linear slide in place, because the original 18 mm M3 SHCS are now 16 mm long (having shotgunned the metric SHCS and BHCS situation some time ago) and the washers are gone.

    They’re all nylon lock nuts except for the one just to the left of the switch, providing barely enough clearance for the Powerpole connectors on the hotrod platform:

    M2 Z-Axis - platform connector clearance
    M2 Z-Axis – platform connector clearance

    With the nozzle off the platform to the far right side, Z-axis homing proceeded normally. Manually jogging to Z=+5.0 mm left 2.6 mm of air under the nozzle, so I reset the offset in EEPROM to -2.4 = (2.6 – 5.0) mm:

    M206 Z-2.4
    M500

    The first calibration square came out at 2.91 mm, so I changed the offset to -2.3 mm, got a 2.80 mm square with a firmly squished first layer, changed it to -2.5 mm, and got a 3.00 mm square for my efforts.

    An array of five squares showed the platform remains level to within +0.05 / -0.07 mm:

    M2 Platform Alignment Check - 2019-02-06
    M2 Platform Alignment Check – 2019-02-06

    I defined it to be Good Enough™ and quit while I was ahead.

    The bottom two squares in the left pile have squished first layers. The rest look just fine:

    M2 Z-Axis - switch offset calibration squares
    M2 Z-Axis – switch offset calibration squares

    The whole set-and-test process required about 45 minutes, most of which was spent waiting for the platform to reach 90 °C in the 14 °C Basement Laboratory.

    Done!

  • Vacuum Tube LEDs: Better Radome

    A two-legged spider radome base definitely looks better than the four-legged version:

    Arduino Pro Mini - NP-BX1 - radome
    Arduino Pro Mini – NP-BX1 – radome

    The radome base now has a hole punched in its bottom for the data lead, with the two power wires going out the sides as before:

    Arduino Pro Mini Battery Holder - SK6812 radome base
    Arduino Pro Mini Battery Holder – SK6812 radome base

    The alert reader will notice the vertical strut on the far side doesn’t go directly into the center of its base fitting. I attempted a bit of cosmetic repair on the horizontal wire below the Pro Mini and discovered, not at all to my surprise, (re)soldering a connection to a 14 AWG copper wire an inch away from a 3D printed base doesn’t work well at all.

    Doesn’t affect the function and, as nobody will ever notice, I’ll leave it be.

  • Juki TL-2010Q: COB LED Light Bar

    Mary needed more light under the arm of her Juki TL-2010Q sewing machine, so I proposed a 12 V 6 W COB LED module instead of the high-density LED strips I used on her Kenmore 158s:

    Kenmore 158 Sewing Machine - Cool white LEDs - rear no flash
    Kenmore 158 Sewing Machine – Cool white LEDs – rear no flash

    Because the COB LEDs dissipate 6W, far more power than I’m comfortable dumping into a 3D printed structure, I redefined a length of aluminum shelf bracket extrusion to be a heatsink and epoxied the module’s aluminum back plate thereto:

    Juki TL-2010Q COB LED - test lighting
    Juki TL-2010Q COB LED – test lighting

    Unlike the flexible LED strips, the COB LED modules have no internal ballast resistors and expect to run from a constant-current supply. Some preliminary testing showed we’d want less than the maximum possible light output, so a constant-voltage supply and a few ohms of ballast would suffice:

    Juki TL-2010Q COB LED - ballast resistor test
    Juki TL-2010Q COB LED – ballast resistor test

    With all that in hand, the heatsink extrusion cried out for smooth endcaps to control the wires and prevent snagging:

    TL-2010Q COB LED Light Bars - end caps - Show layout
    TL-2010Q COB LED Light Bars – end caps – Show layout

    The central hole in the left cap passes 24 AWG silicone wires from the power supply, with 28 AWG silicone wires snaking down through the L-shaped rectangular cutouts along the extrusion to the LED module’s solder pads.

    The model includes built-in support:

    TL-2010Q COB LED Light Bars - end caps - Build layout
    TL-2010Q COB LED Light Bars – end caps – Build layout

    Assuming the curved ends didn’t need support / anchors holding them down turned out to be completely incorrect:

    Juki TL-2010Q COB LED - curled endcaps
    Juki TL-2010Q COB LED – curled endcaps

    Fortunately, those delicate potato chips lived to tell the tale and, after a few design iterations, everything came out right:

    Juki TL-2010Q COB LED - heatsink endcap - internal connections
    Juki TL-2010Q COB LED – heatsink endcap – internal connections

    The “connector”, such as it is, serves to make the light bar testable / removable and the ballast resistor tweakable, without going nuts over the details. The left side is an ordinary pin header strip held in place with hot melt glue atop the obligatory Kapton tape, because the heatsink doesn’t get hot enough to bother the glue. The right side is a pair of two-pin header sockets, also intended for PCB use. The incoming power connects to one set and the ballast resistor to the other, thusly:

    Juki TL-2010Q COB LED - light bar connector diagram
    Juki TL-2010Q COB LED – light bar connector diagram

    The diagram is flipped top-to-bottom from the picture, but you get the idea. Quick, easy, durable, and butt-ugly, I’d say.

    The next step was to mount it on the sewing machine and steal some power, but that’s a story for another day.

    The relevant dimensions for the aluminum extrusion:

    Aluminum shelf bracket extrusion - dimensions
    Aluminum shelf bracket extrusion – dimensions

    The OpenSCAD source code as a GitHub Gist:

    // Juki TL-2010Q Sewing Machine – COB LED Light Bars
    // Ed Nisley – KE4ZNU
    // 2019-01
    /* [Layout Options] */
    Layout = "Build"; // [Bracket,Endcap,Show,Build]
    Wiring = [1,0]; // left and right wire holes
    BuildSupport = true;
    /* [Extrusion Parameters] */
    ThreadWidth = 0.40;
    ThreadThick = 0.20;
    HoleWindage = 0.2;
    Protrusion = 0.1;
    //—–
    // Shelf bracket used as LED heatsink
    /* [Hidden] */
    LEDPlate = [15.0,2.4]; // 2D coords from end of LED
    BktOuter = [15.9,12.6 + LEDPlate.y]; // 2D coords as seen from end of extrusion
    BktWalls = [1.3,2.2 + LEDPlate.y]; // … extend base to cover LED
    BktCap = [2.5,3.0];
    BracketPoints = [
    [0,0],
    [BktOuter.x,0],
    [BktOuter.x,BktOuter.y],
    [(BktOuter.x – BktCap.x),BktOuter.y],
    [(BktOuter.x – BktCap.x),(BktOuter.y – BktCap.y)],
    [(BktOuter.x – BktWalls.x),(BktOuter.y – BktCap.y)],
    [(BktOuter.x – BktWalls.x),BktWalls.y],
    [BktWalls.x,BktWalls.y],
    [BktWalls.x,(BktOuter.y – BktCap.y)],
    [BktCap.x,(BktOuter.y – BktCap.y)],
    [BktCap.x,BktOuter.y],
    [0,BktOuter.y],
    [0,0]
    ];
    BracketPlugInsert = 10.0; // distance into bracket end
    WireOD = 1.6; // COB LED jumpers – 24 AWG silicone
    WireOC = BktOuter.x – 2*BktWalls.x – WireOD;
    echo(str("Wire OC: ",WireOC));
    CableOD = 4.0; // power entry cable
    CapSides = 2*3*4;
    //—–
    // Useful routines
    module PolyCyl(Dia,Height,ForceSides=0) { // based on nophead's polyholes
    Sides = (ForceSides != 0) ? ForceSides : (ceil(Dia) + 2);
    FixDia = Dia / cos(180/Sides);
    cylinder(r=(FixDia + HoleWindage)/2,
    h=Height,
    $fn=Sides);
    }
    //—–
    // Endcap with smooth rounding
    // Wires = true to punch holes for LED wires
    module Endcap(Wires = true) {
    // arc length to flatten inside of cap
    // not needed to build in normal orientation
    m = BktOuter.x/2 – sqrt(pow(BktOuter.x/2,2) – pow(BktOuter.x – 2*BktCap.x,2)/4);
    difference() {
    translate([0,0,BktOuter.y/2]) // basic endcap shape
    intersection() {
    cylinder(d=BktOuter.x,h=BktOuter.y,$fn=CapSides,center=true);
    rotate([90,0,0])
    rotate(180/CapSides)
    cylinder(d=BktOuter.y,h=BktOuter.x,$fn=CapSides,center=true);
    }
    translate([-BracketPlugInsert,0,0]) // extrusion + LED plate
    Bracket(BracketPlugInsert);
    if (false) // flatten inner end
    translate([-BktOuter.y + m,0,BktOuter.y/2])
    cube([BktOuter.y,BktOuter.x,BktOuter.y],center=true);
    if (Wires) {
    for (j=[-1,1]) // COB LED connections
    translate([WireOD – BktOuter.x/2,j*WireOC/2,(BktWalls.y + WireOD – Protrusion)/2])
    rotate([0,00,0])
    cube([BktOuter.x,WireOD + Protrusion,BktWalls.y + WireOD + Protrusion],center=true);
    translate([0,0,BktOuter.y/2]) // power entry / exit
    rotate([0,90,0])
    translate([0,0,-BktOuter.x])
    rotate(180/6)
    PolyCyl(CableOD,2*BktOuter.x,6);
    }
    }
    }
    // Totally ad-hoc support structures
    module Support(Wiring = false) {
    Spacing = 4*ThreadWidth;
    NumBars = floor((BktOuter.y/2) / Spacing);
    echo(str("Support bars: ",NumBars));
    color("Yellow") {
    render() difference() {
    union() {
    for (i=[1:NumBars]) // inside extrusion
    translate([-i*Spacing,0,(BktWalls.y + WireOD)/2])
    cube([2*ThreadWidth,BktOuter.x – 0*BktWalls.x,BktWalls.y + WireOD],center=true);
    if (true)
    for (j=[-1:1]) // reduce outside curve uplift
    translate([0.3*BktOuter.y,j*BktOuter.x/3,BktOuter.y/10])
    cube([BktOuter.y/3,2*ThreadWidth,BktOuter.y/5],center=true);
    }
    minkowski() { // all-around clearance
    Endcap(Wiring);
    cube(2.0*ThreadThick,center=true);
    }
    if (Wiring) {
    translate([0,0,BktOuter.y/2]) // remove rubble from wire bore
    rotate([0,90,0])
    translate([0,0,-BktOuter.x])
    rotate(180/6)
    PolyCyl(CableOD,2*BktOuter.x,6);
    }
    }
    if (false)
    translate([-(BktOuter.x/4 + ThreadWidth),0,ThreadThick/2]) // adhesion pad
    cube([BktOuter.x/2,BktOuter.x – BktWalls.x,ThreadThick],center=true);
    // translate([BktOuter.x/3,0,ThreadThick/2]) // adhesion pad
    // cube([0.3*BktOuter.x,0.7*BktOuter.x,ThreadThick],center=true);
    if (false)
    for (j = [-1:1]) // tie pad to bottom of cap
    translate([-(4*ThreadWidth)/2,j*(BktOuter.x – 2*ThreadWidth)/2,ThreadThick/2])
    cube([4*ThreadWidth,2*ThreadWidth,ThreadThick],center=true);
    }
    }
    //—–
    // Heatsink extrusion + LED plate
    // Centered on Y with Length extending in +X
    module Bracket(Length = 10)
    translate([0,-BktOuter.x/2,0])
    rotate([90,0,90])
    linear_extrude(height = Length,convexity=3)
    polygon(points=BracketPoints);
    //—–
    // Build things
    if (Layout == "Bracket")
    Bracket();
    if (Layout == "Endcap")
    Endcap();
    if (Layout == "Show") {
    translate([BktOuter.x,0,0])
    Endcap(Wiring[1]);
    translate([-BktOuter.x,0,0])
    rotate(180)
    Endcap(Wiring[0]);
    color("Yellow",0.35)
    translate([-BktOuter.x/2,0,0])
    Bracket(BktOuter.x);
    }
    if (Layout == "Build") {
    translate([BktOuter.y,0,0]) {
    Endcap(Wiring[0]);
    if (BuildSupport)
    Support(Wiring[0]);
    }
    translate([-BktOuter.y,0,0]) {
    Endcap(Wiring[1]);
    if (BuildSupport)
    Support(Wiring[1]);
    }
    }

  • Vacuum Tube LEDs: Radome Prototype

    Definitely not a vacuum tube:

    Arduino Pro Mini - NP-BX1 cell - SK6812 - blue phase
    Arduino Pro Mini – NP-BX1 cell – SK6812 – blue phase

    It’s running the same firmware, though, with the Arduino Pro Mini and the LEDs drawing power from the (mostly) defunct lithium battery.

    The LED holder is identical to the Pirhana holder, with a 10 mm diameter recess punched into it for the SK6812 PCB:

    Astable Multivibrator Battery Holder - Neopixel PCB - Slic3r
    Astable Multivibrator Battery Holder – Neopixel PCB – Slic3r

    Those embossed legends sit in debossed rectangles for improved legibility. If I repeat it often enough, I’m sure I’ll remember which is which.

    The 3.6 V (and declining) power supply may not produce as much light from the SK6812 LEDs, but it’s entirely adequate for anything other than a well-lit room. The 28 AWG silicone wires require a bit of careful dressing to emerge from the holes in the radome holder:

    SK6812 LED PCB - Pirhana holder wiring
    SK6812 LED PCB – Pirhana holder wiring

    The firmware cycles through all the usual colors:

    Arduino Pro Mini - NP-BX1 cell - SK6812 - orange phase
    Arduino Pro Mini – NP-BX1 cell – SK6812 – orange phase

    A pair of tensilized 22 AWG copper wires support the Pro Mini between the rear struts. The whole affair looks a bit heavier than I expected, though, so I should reduce the spider to a single pair of legs with a third hole in the bottom of the LED recess for the data wire.

    The OpenSCAD source code needs some refactoring and tweaking, but the Pirhana LED solid model version of the battery holder should give you the general idea.

  • Astable Multivibrator: Monochrome Pirhana LED

    The LED parts box disgorged some single-color Pirhana-style LEDs:

    Astable - 2N7000 - Mono Pirhana LED
    Astable – 2N7000 – Mono Pirhana LED

    Didn’t quite catch the blink, but the Ping-Pong ball radome lights up just as you’d expect.

    The radome sits on a stripped-down RGB LED spider:

    Astable Multivibrator Battery Holder - mono LED Spider - fit view
    Astable Multivibrator Battery Holder – mono LED Spider – fit view

    The circuitry is the same as the First Light version, with a 1 MΩ resistor stabilizing the LED ballast resistor:

    Astable - 2N7000 - Mono Pirhana LED - detail
    Astable – 2N7000 – Mono Pirhana LED – detail

    Those are 1 µF ceramic caps in the astable section, so I’m no longer abusing electrolytics, and a stylin’ 100 nF film cap metering out the LED pulse up above.

    Just for pretty, I’ve been using yellow / black wires for the battery connections and matching the LED color with its cathode lead.

    The OpenSCAD source code as a GitHub Gist:

    // Holder for Li-Ion battery packs
    // Ed Nisley KE4ZNU January 2013
    // 2018-11-15 Adapted for 1.5 mm pogo pins, battery data table
    // 2018-12 RGB LED spider, general cleanups
    /* [Layout options] */
    BatteryName = "NP-BX1"; // [NP-BX1,NB-5L,NB-6L]
    RGBCircuit = false; // false = 1 strut pair, true = 2 pairs
    Layout = "Spider"; // [Build,Show,Fit,Case,Lid,Pins,RGBSpider,Spider]
    /* [Extrusion parameters] – must match reality! */
    // Print with +2 shells and 3 solid layers
    ThreadThick = 0.25;
    ThreadWidth = 0.40;
    HoleWindage = 0.2;
    function IntegerMultiple(Size,Unit) = Unit * ceil(Size / Unit);
    function IntegerLessMultiple(Size,Unit) = Unit * floor(Size / Unit);
    Protrusion = 0.1; // make holes end cleanly
    /* [Hidden] */
    inch = 25.4;
    BuildOffset = 3.0; // clearance for build layout
    Gap = 2.0; // separation for Fit parts
    //- Basic dimensions
    WallThick = 4*ThreadWidth; // holder sidewalls
    BaseThick = 6*ThreadThick; // bottom of holder to bottom of battery
    TopThick = 6*ThreadThick; // top of battery to top of holder
    //- Battery dimensions – rationalized from several samples
    // Coordinate origin at battery corner with contacts, key openings downward
    T_NAME = 0; // Name must fit recess, so don't get loquacious
    T_SIZE = 1;
    T_CONTACTS = 2;
    T_KEYS = 3;
    BatteryData = [
    ["NP-BX1",[43.0,30.0,9.5],[[-0.75,6.0,6.2,"+"],[-0.75,16.0,6.2,"-"]],[[1.70,3.70,2.90],[1.70,3.60,2.90]]],
    ["NB-5L", [45.0,32.0,8.0],[[-0.82,4.5,3.5,"-"],[-0.82,11.0,3.5,"+"]],[[2.2,0.75,2.0],[2.2,2.8,2.0]]],
    ["NB-6L",[42.5,35.5,7.0],[[-0.85,5.50,3.05,"-"],[-0.85,11.90,3.05,"+"]],[[2.0,0.70,2.8],[2.0,2.00,2.8]]],
    ];
    echo(str("Battery: ",BatteryName));
    BatteryIndex = search([BatteryName],BatteryData,1,0)[0];
    echo(str(" Index: ",BatteryIndex));
    BatterySize = BatteryData[BatteryIndex][T_SIZE]; // X = length, Y = width, Z = thickness
    echo(str(" Size: ",BatterySize));
    Contacts = BatteryData[BatteryIndex][T_CONTACTS]; // relative to battery edge, front, and bottom
    echo(str(" Contacts: ",Contacts));
    ContactOC = Contacts[1].y – Contacts[0].y; // + and – terminals for pogo pin contacts
    ContactCenter = Contacts[0].y + ContactOC/2;
    KeyBlocks = BatteryData[BatteryIndex][T_KEYS]; // recesses in battery face set X position
    echo(str(" Keys: ",KeyBlocks));
    //- Pin dimensions
    ID = 0;
    OD = 1;
    LENGTH = 2;
    PinShank = [1.5,2.0,6.5]; // shank, flange, compressed length
    PinFlange = [1.5,2.0,0.5]; // flange, length included in PinShank
    PinTip = [0.9,0.9,2.5]; // extended spring-loaded tip
    WireOD = 1.7; // wiring from pins to circuitry
    PinChannel = WireOD; // cut behind flange for solder overflow
    PinRecess = 3.0; // recess behind pin flange end for epoxy fill
    echo(str("Contact tip dia: ",PinTip[OD]));
    echo(str(" .. shank dia: ",PinShank[ID]));
    OverTravel = 0.5; // space beyond battery face at X origin
    //- Holder dimensions
    GuideRadius = ThreadWidth; // friction fit ridges
    GuideOffset = 7; // from compartment corners
    LidOverhang = 2.0; // atop of battery for retention
    LidClearance = LidOverhang * (BatterySize.z/BatterySize.x); // … clearance above battery for tilting
    echo(str("Lid clearance: ",LidClearance));
    CaseSize = [BatterySize.x + PinShank[LENGTH] + OverTravel + PinRecess + GuideRadius + WallThick,
    BatterySize.y + 2*WallThick + 2*GuideRadius,
    BatterySize.z + BaseThick + TopThick + LidClearance];
    echo(str("Case size: ",CaseSize));
    CaseOffset = [-(PinShank[LENGTH] + OverTravel + PinRecess),-(WallThick + GuideRadius),0]; // position around battery
    ThumbRadius = 10.0; // thumb opening at end of battery
    CornerRadius = 3*ThreadThick; // nice corner rounding
    LidSize = [-CaseOffset.x + LidOverhang,CaseSize.y,TopThick];
    LidOffset = [0.0,CaseOffset.y,0];
    //- Wire struts
    StrutDia = 1.6; // AWG 14 = 1.6 mm
    StrutSides = 3*4;
    StrutBase = [StrutDia,StrutDia + 4*WallThick,CaseSize.z – TopThick]; // ID = wire, OD = buildable
    //StrutOC = [IntegerLessMultiple(BatterySize.x – StrutBase[OD],5.0), // set easy OC wire spacing
    // IntegerMultiple(CaseSize.y + StrutBase[OD],5.0)];
    StrutOC = [IntegerLessMultiple(CaseSize.x – 2*CornerRadius -2*StrutBase[OD],5.0),
    IntegerMultiple(CaseSize.y + StrutBase[OD],5.0)];
    StrutOffset = [CaseSize.x/2 + CaseOffset.x,BatterySize.y/2]; // from case centerlines
    StrutAngle = atan(StrutOC.y/StrutOC.x);
    echo(str("Strut OC: ",StrutOC));
    //- RGB / Pirhana / Neopixel-ish LEDs
    RGBBody = [8.0,8.0,5.0]; // Z = body height
    PixelPCB = [4.0,10.0,3.0]; // Neopixel-ish PCBs, ID = chip window
    RGBPin = 5.0; // pin length
    RGBPinsOC = [5.0,5.0]; // pin layout
    RGBRecess = RGBBody.z + RGBPin/2; // maximum LED recess depth
    BallOD = 40.0; // radome sphere
    BallSides = 4*StrutSides; // nice number of sides
    BallPillar = [norm([RGBBody.x,RGBBody.y]),
    norm([RGBBody.x,RGBBody.y]) + 4*WallThick,
    StrutBase[OD] + RGBBody.z];
    BallChordM = BallOD/2 – sqrt(pow(BallOD/2,2) – (pow(BallPillar[OD],2))/4);
    echo(str("Ball chord depth: ",BallChordM));
    //———————-
    // Useful routines
    module PolyCyl(Dia,Height,ForceSides=0) { // based on nophead's polyholes
    Sides = (ForceSides != 0) ? ForceSides : (ceil(Dia) + 2);
    FixDia = Dia / cos(180/Sides);
    cylinder(r=(FixDia + HoleWindage)/2,h=Height,$fn=Sides);
    }
    //——————-
    //– Guides for tighter friction fit
    module Guides() {
    translate([GuideOffset,-GuideRadius,0])
    PolyCyl(2*GuideRadius,(BatterySize.z – Protrusion),4);
    translate([GuideOffset,(BatterySize.y + GuideRadius),0])
    PolyCyl(2*GuideRadius,(BatterySize.z – Protrusion),4);
    translate([(BatterySize.x – GuideOffset),-GuideRadius,0])
    PolyCyl(2*GuideRadius,(BatterySize.z – Protrusion),4);
    translate([(BatterySize.x – GuideOffset),(BatterySize.y + GuideRadius),0])
    PolyCyl(2*GuideRadius,(BatterySize.z – Protrusion),4);
    translate([(BatterySize.x + GuideRadius),GuideOffset/2,0])
    PolyCyl(2*GuideRadius,(BatterySize.z – Protrusion),4);
    translate([(BatterySize.x + GuideRadius),(BatterySize.y – GuideOffset/2),0])
    PolyCyl(2*GuideRadius,(BatterySize.z – Protrusion),4);
    }
    //– Contact pins
    // Rotated to put them in their natural oriention
    // Aligned to put tip base / end of shank at Overtravel limit
    module PinShape() {
    translate([-(PinShank[LENGTH] + OverTravel),0,0])
    rotate([0,90,0])
    rotate(180/6)
    union() {
    PolyCyl(PinTip[OD],PinShank[LENGTH] + PinTip[LENGTH],6);
    PolyCyl(PinShank[ID],PinShank[LENGTH] + Protrusion,6); // slight extension for clean cuts
    PolyCyl(PinFlange[OD],PinFlange[LENGTH],6);
    }
    }
    // Position pins to put end of shank at battery face
    // Does not include recess access into case
    module PinAssembly() {
    union() {
    for (p = Contacts)
    translate([0,p.y,p.z])
    PinShape();
    translate([-(PinShank[LENGTH] + OverTravel) + PinChannel/2, // solder space
    ContactCenter,
    Contacts[0].z])
    cube([PinChannel,
    (Contacts[1].y – Contacts[0].y + PinFlange[OD]),
    PinFlange[OD]],center=true);
    for (j=[-1,1]) // wire channels
    translate([-(PinShank[LENGTH] + OverTravel – PinChannel/2),
    j*ContactOC/4 + ContactCenter,
    Contacts[0].z – PinFlange[OD]/2])
    rotate(180/6)
    PolyCyl(WireOD,CaseSize.z,6);
    }
    }
    //– Case with origin at battery corner
    module Case() {
    difference() {
    union() {
    difference() {
    union() {
    translate([(CaseSize.x/2 + CaseOffset.x), // basic case shape
    (CaseSize.y/2 + CaseOffset.y),
    (CaseSize.z/2 – BaseThick)])
    hull()
    for (i=[-1,1], j=[-1,1], k=[-1,1])
    translate([i*(CaseSize.x/2 – CornerRadius),
    j*(CaseSize.y/2 – CornerRadius),
    k*(CaseSize.z/2 – CornerRadius)])
    sphere(r=CornerRadius/cos(180/8),$fn=8); // cos() fixes undersize spheres!
    for (i= RGBCircuit ? [-1,1] : -1) { // strut bases
    hull()
    for (j=[-1,1])
    translate([i*StrutOC.x/2 + StrutOffset.x,j*StrutOC.y/2 + StrutOffset.y,-BaseThick])
    rotate(180/StrutSides)
    cylinder(d=StrutBase[OD],h=StrutBase[LENGTH],$fn=StrutSides);
    translate([i*StrutOC.x/2 + StrutOffset.x,StrutOffset.y,StrutBase[LENGTH]/2 – BaseThick])
    cube([2*StrutBase[OD],StrutOC.y,StrutBase[LENGTH]],center=true); // blocks for fairing
    for (j=[-1,1]) // hemisphere caps
    translate([i*StrutOC.x/2 + StrutOffset.x,
    j*StrutOC.y/2 + StrutOffset.y,
    StrutBase[LENGTH] – BaseThick])
    rotate(180/StrutSides)
    sphere(d=StrutBase[OD]/cos(180/StrutSides),$fn=StrutSides);
    }
    }
    translate([-OverTravel,-GuideRadius,0])
    cube([(BatterySize.x + GuideRadius + OverTravel),
    (BatterySize.y + 2*GuideRadius),
    (BatterySize.z + LidClearance + Protrusion)]); // battery space
    translate([BatterySize.x/2,BatterySize.y/2,0]) // recess around battery name
    cube([0.8*BatterySize.x,8,2*ThreadThick],center=true);
    translate([CaseOffset.x + CaseSize.x/2,BatterySize.y/2,-BaseThick + ThreadThick – Protrusion]) // recess around battery name
    cube([0.75*CaseSize.x,8,2*ThreadThick],center=true);
    }
    Guides(); // improve friction fit
    translate([-OverTravel,-GuideRadius,0]) // battery keying blocks
    cube(KeyBlocks[0] + [OverTravel,GuideRadius,0],center=false);
    translate([-OverTravel,(BatterySize.y – KeyBlocks[1].y),0])
    cube(KeyBlocks[1] + [OverTravel,GuideRadius,0],center=false);
    translate([BatterySize.x/2,BatterySize.y/2,-ThreadThick])
    linear_extrude(height=2*ThreadThick,convexity=10)
    text(text=BatteryName,size=5,spacing=1.20,font="Arial:style:Bold",halign="center",valign="center");
    translate([CaseOffset.x + CaseSize.x/2,BatterySize.y/2,-BaseThick])
    linear_extrude(height=2*ThreadThick + Protrusion,convexity=10)
    mirror([0,1,0])
    text(text="KE4ZNU",size=6,spacing=1.20,font="Arial:style:Bold",halign="center",valign="center");
    }
    translate([2*CaseOffset.x, // battery top access
    (CaseOffset.y – Protrusion),
    BatterySize.z + LidClearance])
    cube([2*CaseSize.x,(CaseSize.y + 2*Protrusion),2*TopThick]);
    for (i2 = RGBCircuit ? [-1,1] : -1) { // strut wire holes and fairing
    for (j=[-1,1])
    translate([i2*StrutOC.x/2 + StrutOffset.x,j*StrutOC.y/2 + StrutOffset.y,0])
    rotate(180/StrutSides)
    PolyCyl(StrutBase[ID],2*StrutBase[LENGTH],StrutSides);
    for (i=[-1,1], j=[-1,1])
    translate([i*StrutBase[OD] + (i2*StrutOC.x/2 + StrutOffset.x),
    j*StrutOC.y/2 + StrutOffset.y,
    -(BaseThick + Protrusion)])
    rotate(180/StrutSides)
    PolyCyl(StrutBase[OD],StrutBase[LENGTH] + 2*Protrusion,StrutSides);
    }
    translate([(BatterySize.x – Protrusion), // remove thumb notch
    (CaseSize.y/2 + CaseOffset.y),
    (ThumbRadius)])
    rotate([90,0,0])
    rotate([0,90,0])
    cylinder(r=ThumbRadius,
    h=(WallThick + GuideRadius + 2*Protrusion),
    $fn=22);
    PinAssembly(); // pins and wiring
    translate([CaseOffset.x + PinRecess + Protrusion,(Contacts[1].y + Contacts[0].y)/2,Contacts[0].z])
    translate([-PinRecess,0,0])
    cube([2*PinRecess,
    (Contacts[1].y – Contacts[0].y + PinFlange[OD]/cos(180/6) + 2*HoleWindage),
    2*PinFlange[OD]],center=true); // pin insertion hole
    }
    }
    // Lid position offset to match case
    // The polarity indicator recesses are pure bodges
    module Lid() {
    union() {
    difference() {
    translate([-LidSize.x/2 + LidOffset.x + LidOverhang,LidSize.y/2 + LidOffset.y,0])
    difference() {
    hull()
    for (i=[-1,1], j=[-1,1], k=[-1,1])
    translate([i*(LidSize.x/2 – CornerRadius),
    j*(LidSize.y/2 – CornerRadius),
    k*(LidSize.z – CornerRadius)]) // double thickness for flat bottom
    sphere(r=CornerRadius,$fn=8);
    translate([0,0,-LidSize.z/2]) // remove bottom
    cube([(LidSize.x + 2*Protrusion),(LidSize.y + 2*Protrusion),LidSize.z],center=true);
    translate([LidSize.x/8,0,0])
    cube([LidSize.x/4,0.75*LidSize.y,4*ThreadThick],center=true); // epoxy recess
    }
    translate([0,0,-(Contacts[0].z + PinFlange[OD])]) // punch wire holes
    PinAssembly();
    for (n=[0,1]) // polarity recesses
    translate([-LidOverhang/2 – 0.40,Contacts[n].y,LidSize.z – ThreadThick/2])
    cube([4,4.5,ThreadThick + Protrusion],center=true);
    }
    for (n=[0,1]) // polarity indicators
    translate([-LidOverhang/2,Contacts[n].y,LidSize.z – 1*ThreadThick]) // … proud of surface
    rotate(90)
    linear_extrude(height=2*ThreadThick,convexity=10)
    text(text=Contacts[n][3],size=5,font="Arial:style:Bold",halign="center",valign="center");
    }
    }
    // Spider for RGB LED + radome atop vertical struts
    module RGBSpider() {
    difference() {
    union() {
    for (i=[-1,1], j=[-1,1]) {
    translate([i*StrutOC.x/2,j*StrutOC.y/2,StrutBase[OD]/2])
    rotate(180/StrutSides) // doesn't quite match crosspieces; close enough
    sphere(d=StrutBase[OD]/cos(180/StrutSides),$fn=StrutSides);
    translate([i*StrutOC.x/2,j*StrutOC.y/2,0])
    rotate(180/StrutSides)
    cylinder(d=StrutBase[OD],h=StrutBase[OD]/2,$fn=StrutSides);
    }
    for (m=[-1,1]) // connecting bars
    rotate(m*StrutAngle)
    translate([0,0,StrutBase[OD]/4])
    cube([norm(StrutOC),StrutBase[OD],StrutBase[OD]/2],center=true);
    translate([0,0,0]) // pillar for RGB LED and ball
    cylinder(d=BallPillar[OD],h=BallPillar[LENGTH],$fn=BallSides);
    }
    for (i=[-1,1], j=[-1,1]) // strut wires
    translate([i*StrutOC.x/2,j*StrutOC.y/2,-Protrusion])
    rotate(0)
    PolyCyl(StrutBase[ID],StrutBase[OD]/2,6);
    for (m=[-1,1], n=[0,1]) // RGBA wires through bars
    rotate(m*StrutAngle + n*180)
    translate([StrutOC.x/3,0,-Protrusion])
    PolyCyl(StrutBase[ID],StrutBase[OD],6);
    translate([0,0,BallOD/2 + BallPillar[LENGTH] – BallChordM]) // ball inset
    sphere(d=BallOD);
    translate([0,0,2*RGBBody.z + (BallPillar[LENGTH] – BallChordM) – RGBRecess]) // LED inset
    cube(RGBBody + [HoleWindage,HoleWindage,3*RGBBody.z],center=true); // XY clearance + huge height for E-Z cut
    translate([0,0,StrutBase[OD]/2]) // Neopixel recess
    PolyCyl(PixelPCB[OD],3*RGBBody.z,BallSides/2);
    for (m=[-1,1]) // RGBA wires through pillar
    rotate(m*StrutAngle)
    translate([0,0,StrutBase[OD]/2 + WireOD/2 + 0*Protrusion])
    cube([norm(StrutOC)/2,WireOD,WireOD],center=true);
    }
    }
    // Spider for single LED atop struts, with the ball
    // Aligned to struts at terminal end of battery on Y axis
    module Spider() {
    difference() {
    union() {
    for (j=[-1,1]) {
    translate([-StrutOC.x/2,j*StrutOC.y/2,StrutBase[OD]/2])
    rotate(180/StrutSides)
    sphere(d=StrutBase[OD]/cos(180/StrutSides),$fn=StrutSides);
    translate([-StrutOC.x/2,j*StrutOC.y/2,0])
    rotate(180/StrutSides)
    cylinder(d=StrutBase[OD],h=StrutBase[OD]/2,$fn=StrutSides);
    }
    translate([-StrutOC.x/2,0,StrutBase[OD]/4]) // connecting bars
    cube([StrutBase[OD]*cos(180/StrutSides),StrutOC.y,StrutBase[OD]/2],center=true);
    translate([-StrutOC.x/2,0,0]) // pillar for RGB LED and ball
    cylinder(d=BallPillar[OD],h=BallPillar[LENGTH],$fn=BallSides);
    }
    for (j=[-1,1]) // strut wires
    translate([-StrutOC.x/2,j*StrutOC.y/2,-Protrusion])
    rotate(0)
    PolyCyl(StrutBase[ID],StrutBase[OD]/2,6);
    translate([-StrutOC.x/2,0,0]) // wires through bars
    for (n=[-1,1])
    rotate(n*90)
    translate([StrutOC.x/3,0,-Protrusion])
    PolyCyl(StrutBase[ID],StrutBase[OD],6);
    translate([-StrutOC.x/2,0,-Protrusion]) // center hole for Neopixel
    rotate(180/6)
    PolyCyl(StrutBase[ID],StrutBase[OD],6);
    translate([-StrutOC.x/2,0,BallOD/2 + BallPillar[LENGTH] – BallChordM]) // ball inset
    sphere(d=BallOD);
    translate([-StrutOC.x/2,0,2*RGBBody.z + (BallPillar[LENGTH] – BallChordM) – RGBRecess]) // LED inset
    cube(RGBBody + [HoleWindage,HoleWindage,3*RGBBody.z],center=true); // XY clearance + huge height for E-Z cut
    translate([-StrutOC.x/2,0,StrutBase[OD]/2]) // Neopixel recess
    PolyCyl(PixelPCB[OD],3*RGBBody.z,BallSides/2);
    translate([-StrutOC.x/2,0,StrutBase[OD]/2 + WireOD/2 + 0*Protrusion]) // wire channels
    cube([WireOD,StrutOC.y/2,WireOD],center=true);
    }
    }
    //——————-
    // Build it!
    if (Layout == "Case")
    Case();
    if (Layout == "Lid")
    Lid();
    if (Layout == "RGBSpider") {
    RGBSpider();
    }
    if (Layout == "Spider") {
    Spider();
    }
    if (Layout == "Pins") {
    color("Silver",0.5)
    PinShape();
    PinAssembly();
    }
    if (Layout == "Fit") { // reveal pin assembly
    difference() {
    Case();
    translate([(CaseOffset.x – Protrusion),
    Contacts[1].y,
    Contacts[1].z])
    cube([(-CaseOffset.x + Protrusion),CaseSize.y,CaseSize.z]);
    translate([(CaseOffset.x – Protrusion),
    (CaseOffset.y – Protrusion),
    0])
    cube([(-CaseOffset.x + Protrusion),
    Contacts[0].y + Protrusion – CaseOffset.y,
    CaseSize.z]);
    }
    translate([0,0,BatterySize.z + Gap])
    Lid();
    color("Silver",0.15)
    PinAssembly();
    if (RGBCircuit) {
    translate([StrutOC.x/2,BatterySize.y/2,2*BatterySize.z])
    difference() {
    RGBSpider();
    rotate(180-StrutAngle)
    translate([0,0,-Protrusion])
    cube([norm(StrutOC),StrutBase[OD],2*BallPillar.z],center=false);
    }
    color("Green",0.35)
    translate([StrutOC.x/2,BatterySize.y/2,2*BatterySize.z + BallOD/2 + BallPillar[LENGTH] – BallChordM])
    sphere(d=BallOD);
    }
    else {
    difference() {
    translate([StrutOC.x/2,BatterySize.y/2,2*BatterySize.z])
    Spider();
    translate([-BallPillar[OD],BatterySize.y/2,2*BatterySize.z – Protrusion])
    cube([BallPillar[OD],StrutOC.y,2*BallPillar.z],center=false);
    }
    color("Green",0.35)
    translate([0,BatterySize.y/2,2*BatterySize.z + BallOD/2 + BallPillar[LENGTH] – BallChordM])
    sphere(d=BallOD);
    }
    }
    if (Layout == "Build") {
    rotate(90) {
    translate([-BatterySize.x/2,-BatterySize.y/2,BaseThick])
    Case();
    translate([-CaseSize.x + LidSize.x,-(LidSize.y/2 + LidOffset.y),0])
    Lid();
    if (RGBCircuit)
    translate([StrutOC.x + BatterySize.x/2,0,0])
    RGBSpider();
    else
    translate([StrutOC.x + BatterySize.x/2,0,0])
    Spider();
    }
    }
    if (Layout == "Show") {
    Case();
    translate([0,0,(BatterySize.z + Gap)])
    Lid();
    color("Silver",0.25)
    PinAssembly();
    if (RGBCircuit) {
    translate([StrutOC.x/2,BatterySize.y/2,2*BatterySize.z])
    RGBSpider();
    color("Green",0.35)
    translate([StrutOC.x/2,BatterySize.y/2,2*BatterySize.z + BallOD/2 + BallPillar[LENGTH] – BallChordM])
    sphere(d=BallOD);
    }
    else {
    translate([StrutOC.x/2,BatterySize.y/2,2*BatterySize.z])
    Spider();
    color("Green",0.35)
    translate([0,BatterySize.y/2,2*BatterySize.z + BallOD/2 + BallPillar[LENGTH] – BallChordM])
    sphere(d=BallOD);
    }
    }