MustafaMulla29/rp2040-bldc-motor-controller
Hardware assembly metadata and PCB geometry for a controller board with a snap-off rotary-encoder section, plus four parallel 150 µF/50 V bulk electrolytic capacitors filtering the motor supply.
- Version
- 2.0.40
- License
- unset
- Stars
- 0
Use with the tscircuit CLI
tsci is the tscircuit CLI. Install it with npm install -g tscircuit.
tsci clone MustafaMulla29/rp2040-bldc-motor-controller # download the package files into ./rp2040-bldc-motor-controller
tsci add MustafaMulla29/rp2040-bldc-motor-controller # add it to your project as @tsci/MustafaMulla29.rp2040-bldc-motor-controllerIn a cloned or new (tsci init) project: tsci dev starts a local preview, tsci build outputs Circuit JSON, and tsci push publishes to tscircuit.com.
encoder-mount/mount.py
"""Encoder holder and magnet cap for the 2212 motor (parametric fit study).
Frame: origin on the motor axis at the motor's base plane, Z up into the motor.
X follows the 16 mm screw pitch, Y the 19 mm pitch. The encoder cable leaves sideways, toward -X,
so it does not run under the three motor leads, which leave the motor toward +Y.
Motor data comes from the seller's dimension drawing for the Readytosky RS2212 920KV (Amazon
B075DD16LK, read on 1 December 2026): 28 mm body (drawn as 27.8), 24 mm tall without the M6
propeller shaft, 38 mm overall, four M3 holes on 19 mm and 16 mm pitches. The drawing shows a
flat base with no shaft standing proud of it, so `shaft.stickOut` is 0 and the magnet cap is
glued onto the shaft end instead of gripping the shaft.
NOT VERIFIED on a motor: whether the shaft end is exactly flush or slightly recessed, what
retains it (clip or screw), the size of the opening around it, and where the three leads leave
the base relative to the screw pattern. Set `shaft.stickOut` (negative if recessed) and rerun:
cap length, board height, post length and stand height all follow from it.
Run: enclosure/.venv/bin/python encoder-mount/mount.py (needs manifold3d, trimesh, numpy)
"""
from pathlib import Path
import json, math
import manifold3d as mf
import numpy as np
import trimesh
ROOT = Path(__file__).resolve().parent.parent
OUT = ROOT / "assets" / "encoder-mount"
P = {
# Body 28 mm and the 16 x 19 mm M3 pattern are consistent across seller listings.
"motor": {"bodyDiameter": 28.0, "bodyHeight": 24.0, "screwX": 8.0, "screwY": 9.5,
"screwClearance": 3.4, "headDiameter": 5.5, "headHeight": 2.5},
"shaft": {"stickOut": 0.0, "source": "seller drawing: flat base, nothing proud", "measured": False},
"magnet": {"diameter": 6.0, "height": 2.5}, # 6 x 2.5 mm, diametric
"sensor": {"gap": 1.5, "chipHeight": 1.1}, # AS5047P: magnet 0.5-3 mm from the package
# encoder-board.circuit.tsx, turned a quarter turn: its long axis lies along X, plug end at -X.
# `near`/`far` are distances from the chip centre along that axis.
"board": {"width": 24.0, "length": 38.0, "originToPadEnd": 12.5, "thickness": 1.6,
"holes": [(-8.5, -8.5), (8.5, -8.5), (-8.5, 8.5), (8.5, 8.5)], "holeDiameter": 2.7,
"plug": {"near": 14.96, "far": 25.04, "halfWidth": 7.5, "height": 5.5},
"chip": {"along": 6.4, "across": 5.0}},
"holder": {"plate": 2.5, "wall": 3.0, "sideClearance": 2.0, "post": 6.0, "pilot": 2.2,
"pilotDepth": 4.0, "shaftHole": 10.0, "plugSideX": -14.5, "farSideX": 17.0, "underBoard": 4.3},
# `neck` is the small glue face on the shaft end; the wide part stays `topClearance` below the base.
"cap": {"diameter": 8.0, "topClearance": 0.6, "neck": 3.0, "pocketClearance": 0.1, "floor": 1.0},
}
def derive(p):
s, m, g, c = p["shaft"], p["magnet"], p["sensor"], p["cap"]
z = {}
z["shaftEnd"] = -s["stickOut"]
z["capTop"] = min(-c["topClearance"], z["shaftEnd"]) # wide part of the cap never rubs the motor base
z["magnetTop"] = z["capTop"] - c["floor"] # plastic floor keeps the magnet off the steel shaft
z["magnetFace"] = z["magnetTop"] - m["height"]
z["chipTop"] = z["magnetFace"] - g["gap"]
z["boardTop"] = z["chipTop"] - g["chipHeight"]
z["boardBottom"] = z["boardTop"] - p["board"]["thickness"]
z["standBottom"] = z["boardBottom"] - p["holder"]["underBoard"]
z["plateBottom"] = -p["holder"]["plate"]
return z
def box(x0, x1, y0, y1, z0, z1):
return mf.Manifold.cube([x1 - x0, y1 - y0, z1 - z0], center=True).translate([(x0 + x1) / 2, (y0 + y1) / 2, (z0 + z1) / 2])
def cyl(x, y, z0, z1, radius, segments=96):
return mf.Manifold.cylinder(z1 - z0, radius, circular_segments=segments, center=True).translate([x, y, (z0 + z1) / 2])
def union(parts):
return mf.Manifold.batch_boolean(parts, mf.OpType.Add)
def build(p=P):
z = derive(p); h, b, mo, c = p["holder"], p["board"], p["motor"], p["cap"]
inner = b["width"] / 2 + h["sideClearance"]; outer = inner + h["wall"]
screws = [(mo["screwX"], 0), (-mo["screwX"], 0), (0, mo["screwY"]), (0, -mo["screwY"])]
solid = union([
box(h["plugSideX"], h["farSideX"], -outer, outer, z["plateBottom"], 0),
box(h["plugSideX"], h["farSideX"], inner, outer, z["standBottom"], 0),
box(h["plugSideX"], h["farSideX"], -outer, -inner, z["standBottom"], 0),
*[cyl(x, y, z["boardTop"], z["plateBottom"] + 0.01, h["post"] / 2) for x, y in b["holes"]],
])
holder = solid - union([
cyl(0, 0, z["plateBottom"] - 1, 1, h["shaftHole"] / 2),
*[cyl(x, y, z["plateBottom"] - 1, 1, mo["screwClearance"] / 2) for x, y in screws],
*[cyl(x, y, z["boardTop"] - 0.01, z["boardTop"] + h["pilotDepth"], h["pilot"] / 2) for x, y in b["holes"]],
])
cap = cyl(0, 0, z["magnetFace"], z["capTop"], c["diameter"] / 2) \
- cyl(0, 0, z["magnetFace"] - 1, z["magnetTop"], (p["magnet"]["diameter"] + c["pocketClearance"]) / 2)
if z["shaftEnd"] > z["capTop"]: # neck up to the shaft end, glued to it
cap = cap + cyl(0, 0, z["capTop"] - 0.01, z["shaftEnd"], c["neck"] / 2)
# neighbours, for clearance checks and the assembly picture
env = {
"motor": cyl(0, 0, 0, mo["bodyHeight"], mo["bodyDiameter"] / 2),
"magnet": cyl(0, 0, z["magnetFace"], z["magnetTop"], p["magnet"]["diameter"] / 2),
"board": box(-(b["length"] - b["originToPadEnd"]), b["originToPadEnd"], -b["width"] / 2, b["width"] / 2, z["boardBottom"], z["boardTop"])
- union([cyl(x, y, z["boardBottom"] - 1, z["boardTop"] + 1, b["holeDiameter"] / 2) for x, y in b["holes"]]),
"chip": box(-b["chip"]["along"] / 2, b["chip"]["along"] / 2, -b["chip"]["across"] / 2, b["chip"]["across"] / 2, z["boardTop"], z["chipTop"]),
"plug": box(-b["plug"]["far"], -b["plug"]["near"], -b["plug"]["halfWidth"], b["plug"]["halfWidth"], z["boardTop"], z["boardTop"] + b["plug"]["height"]),
"motorScrewHeads": union([cyl(x, y, z["plateBottom"] - mo["headHeight"], z["plateBottom"], mo["headDiameter"] / 2) for x, y in screws]),
"boardScrews": union([cyl(x, y, z["boardBottom"] - 2.0, z["boardBottom"], 2.3) for x, y in b["holes"]]),
}
return holder, cap, env, z
def mesh(solid):
m = solid.to_mesh()
return trimesh.Trimesh(vertices=m.vert_properties[:, :3], faces=m.tri_verts, process=True)
def main():
holder, cap, env, z = build()
checks = []
def check(name, ok, detail=""):
checks.append({"check": name, "pass": bool(ok), "detail": detail})
vol = lambda a, b: float((a ^ b).volume())
for name, solid in (("holder", holder), ("magnet cap", cap)):
m = mesh(solid)
check(f"{name} is one watertight solid", m.is_watertight and m.is_winding_consistent and len(solid.decompose()) == 1, f"{m.volume:.0f} mm3")
for other in ("motor", "magnet", "board", "chip", "plug", "motorScrewHeads", "boardScrews"):
check(f"holder does not cut into {other}", vol(holder, env[other]) < 1e-3, f"{vol(holder, env[other]):.4f} mm3")
check("magnet cap does not touch the holder", vol(cap, holder) < 1e-6, f"radial gap {(P['holder']['shaftHole'] - P['cap']['diameter']) / 2:.2f} mm")
for other in ("motor", "chip", "board", "motorScrewHeads"):
check(f"magnet cap does not touch {other}", vol(cap, env[other]) < 1e-6)
check("magnet fits its pocket", vol(cap, env["magnet"]) < 1e-6)
gap = z["magnetFace"] - z["chipTop"]
check("magnet face to chip is 0.5-3 mm", 0.5 <= gap <= 3.0, f"{gap:.2f} mm")
check("motor screw heads clear the board parts", z["plateBottom"] - P["motor"]["headHeight"] - z["chipTop"] >= 0.5, f"{z['plateBottom'] - P['motor']['headHeight'] - z['chipTop']:.2f} mm above the chip")
plan_gap = P["board"]["plug"]["near"] + P["holder"]["plugSideX"] # plug starts beyond the plate edge
check("plug clears the holder plate in plan", plan_gap >= 0.3, f"{plan_gap:.2f} mm")
leads_side = P["board"]["width"] / 2 + P["holder"]["sideClearance"] + P["holder"]["wall"]
check("cable leaves on a different side from the motor leads", P["board"]["plug"]["far"] > leads_side, "cable toward -X, motor leads toward +Y")
check("stand lifts the board screws off the table", (z["boardBottom"] - 2.0) - z["standBottom"] >= 1.5, f"{(z['boardBottom'] - 2.0) - z['standBottom']:.2f} mm")
check("posts reach the holder plate", z["plateBottom"] - z["boardTop"] >= P["holder"]["pilotDepth"], f"post {z['plateBottom'] - z['boardTop']:.2f} mm")
check("cap reaches the shaft end with a glue face", z["shaftEnd"] >= z["capTop"], f"{P['cap']['neck']:.1f} mm neck, {z['shaftEnd'] - z['capTop']:.2f} mm tall")
check("magnet is kept off the steel shaft", z["shaftEnd"] - z["magnetTop"] >= 1.0, f"{z['shaftEnd'] - z['magnetTop']:.2f} mm of plastic")
OUT.mkdir(parents=True, exist_ok=True)
flip = trimesh.transformations.rotation_matrix(math.pi, [1, 0, 0])
for name, solid in (("encoder-holder", holder), ("magnet-cap", cap)):
m = mesh(solid); m.apply_transform(flip); m.apply_translation([0, 0, -m.bounds[0][2]]) # print side down
m.export(OUT / f"{name}.stl")
report = {
"status": "FIT STUDY: flat base taken from the seller's drawing; shaft end, its retainer and lead exit not checked on a motor",
"parameters": P, "heights": {k: round(v, 3) for k, v in z.items()},
"holderBounds": [[round(v, 3) for v in row] for row in mesh(holder).bounds.tolist()],
"capBounds": [[round(v, 3) for v in row] for row in mesh(cap).bounds.tolist()],
"checks": checks, "allChecksPass": all(c["pass"] for c in checks),
"hardware": ["4 x M3 screws into the motor base (length to suit the motor's thread depth plus 2.5 mm plate)",
"4 x M2.5 x 5 plastic or brass screws into the posts", "1 x 6 x 2.5 mm diametric magnet, glued into the cap",
"glue for the cap's neck on the shaft end"],
}
(OUT / "report.json").write_text(json.dumps(report, indent=2) + "\n")
for c in checks: print(("PASS " if c["pass"] else "FAIL ") + c["check"] + (f" | {c['detail']}" if c["detail"] else ""))
print(f"{sum(c['pass'] for c in checks)}/{len(checks)} checks pass; heights: " + ", ".join(f"{k} {v:.2f}" for k, v in z.items()))
raise SystemExit(0 if report["allChecksPass"] else 1)
if __name__ == "__main__":
main()