main
Caleb Publish 0.1.1 83c9715 1d ago
#!/usr/bin/env python3
"""Build Dinkle 2EHDRM-XXP (5.08 mm pluggable PCB header, right angle, threaded flange) for P positions, hand-built in
CadQuery by Adom (tier 3) from Dinkle's 2EHDRM-XXP catalog data sheet (dinkle.com outpagepdf.php?dpid=333, p.3 Drawings).

Printed: length 5.08*(P-1)+15.24, width 12.00, height 8.47 above the board, pins 1.00 square, 4.00 below the board,
pitch 5.08, end pin 7.62 from the housing end, pin row 1.75 from the back edge; PCB holes 1.6-1.7, flange holes 2.40 at
5.08 beyond the end pins and 4.26 from the back edge.
Measured off the drawing (a web-catalog raster, about 18.4 px/mm across and 18.8 px/mm up, calibrated on the printed
25.40 length (3-way example), 12.00, 8.47 and 4.00; +/-0.1 mm): mating cavity from 4.65 mm inside each end, 1.36 to
6.75 mm above the board; a latch notch 2.1 mm wide above each position from the cavity to the top; the front top edge
chamfered 0.75 high x 1.5 deep; flange threaded hole centred 3.84 mm above the board, 2.05 mm bore with a 3.0 mm
counterbore; pin square centred 3.93 mm above the board in the front view; pin tips taper to 0.5 mm over the last 1.0 mm.
Not shown by the drawing and chosen (stated in provenance): mating cavity depth 8.0 mm, threaded bore depth 4.0 mm,
counterbore depth 0.3 mm, pin horizontal leg ending 2.0 mm behind the front face. The drawing shows nothing under the
flanges, so no peg is modelled for the 2.40 PCB holes.
Frame (the page footprint): pin 1 at the origin, pins along +X, the mating face toward +Y (footprint -y), Z up, board top
at z = 0, pin legs below.
usage: build_2ehdrm.py out.step P [name]"""
import sys
import cadquery as cq

def build(P):
    pitch, L, W, H = 5.08, 5.08 * (P - 1) + 15.24, 12.00, 8.47
    x0, y_back = -7.62, -1.75
    y_front = y_back + W
    house = cq.Workplane('XY').box(L, W, H, centered=False).translate((x0, y_back, 0))
    # front top chamfer along the full length
    ch = (cq.Workplane('YZ').polyline([(y_front, H - 0.75), (y_front + 0.01, H + 0.01), (y_front - 1.5, H + 0.01), (y_front - 1.5, H)])
          .close().extrude(L + 0.02).translate((x0 - 0.01, 0, 0)))
    house = house.cut(ch)
    # mating cavity
    cav_x0, cav_x1 = x0 + 4.65, x0 + L - 4.65
    cav = cq.Workplane('XY').box(cav_x1 - cav_x0, 8.0 + 0.01, 6.75 - 1.36, centered=False).translate((cav_x0, y_front - 8.0, 1.36))
    house = house.cut(cav)
    # latch notches above each position
    for i in range(P):
        xc = i * pitch
        house = house.cut(cq.Workplane('XY').box(2.1, 1.5 + 0.01, H - 6.75 + 0.01, centered=False).translate((xc - 1.05, y_front - 1.5, 6.75)))
    # threaded flange holes (axis along -Y from the front face)
    for xc in (-pitch, (P - 1) * pitch + pitch):
        cb = cq.Workplane('XZ').circle(1.5).extrude(0.3).translate((xc, y_front, 3.84))
        bore = cq.Workplane('XZ').circle(1.025).extrude(4.0).translate((xc, y_front, 3.84))
        house = house.cut(cb).cut(bore)
    # pins: vertical leg from -4.00 (tip tapered to 0.5 over 1.0 mm) to the bend, horizontal leg to 2.0 mm behind the front
    zc = 3.93
    pins = None
    for i in range(P):
        xc = i * pitch
        tip = cq.Workplane('XY').rect(0.5, 0.5).workplane(offset=1.0).rect(1.0, 1.0).loft().translate((xc, 0, -4.0))
        leg = cq.Workplane('XY').box(1.0, 1.0, zc + 0.5 - (-3.0), centered=(True, True, False)).translate((xc, 0, -3.0))
        arm = cq.Workplane('XY').box(1.0, (y_front - 2.0) - (-0.5), 1.0, centered=False).translate((xc - 0.5, -0.5, zc - 0.5))
        p = tip.union(leg).union(arm)
        pins = p if pins is None else pins.union(p)
    house = house.cut(pins)
    return house, pins

if __name__ == '__main__':
    out, P = sys.argv[1], int(sys.argv[2]); name = sys.argv[3] if len(sys.argv) > 3 else f'2EHDRM-{P:02d}P'
    house, pins = build(P)
    a = cq.Assembly(name=name)
    a.add(house, name='housing', color=cq.Color(0.16, 0.52, 0.28))
    a.add(pins, name='pins', color=cq.Color(0.82, 0.82, 0.78))
    a.export(out)
    print(out)