MustafaMulla29/usb-pd-motherboard
4-layer USB-C PD hub motherboard with 20 V USB-C input, Linux T113-S3 computer, CH338F USB hub, four individually controlled 5–20 V PD outputs, USB data/camera ports, regulated rails, and hardware watchdog/E-stop safety interlock.
- Version
- 1.0.24
- License
- unset
- Stars
- 0
Use with the tscircuit CLI
tsci is the tscircuit CLI. Install it with npm install -g tscircuit.
tsci clone MustafaMulla29/usb-pd-motherboard # download the package files into ./usb-pd-motherboard
tsci add MustafaMulla29/usb-pd-motherboard # add it to your project as @tsci/MustafaMulla29.usb-pd-motherboardIn 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.
tools/bom-value-check.py
"""Does every resistor and capacitor on the built board have a JLCPCB part of the value the design asks for?
python3 -I tools/bom-value-check.py (after a build with the parts engine: tsci build index.tsx)
Why this exists: tscircuit remembers the part it picked for a component by the component's NAME and footprint,
not by its value (.tscircuit/cache/). Change the value of an existing resistor or capacitor and the next build
on the same computer keeps the old part number. Found on 2026-12-02: RESTSRC and RESTPD still had the 1k / 10k
parts after their values became 330 ohm / 2.2k, and four hub parts that kept a name got the old hub's parts.
If this prints a wrong value: delete the cache file it names, build again, run this again.
Reads dist/index/circuit.json; asks JLCPCB's public parts data for each part number (kept in .tscircuit/jlc-parts/).
"""
import hashlib, json, os, re, subprocess, sys
cj = json.load(open("dist/index/circuit.json")); cache = ".tscircuit/jlc-parts"; os.makedirs(cache, exist_ok=True)
def detail(c):
f = os.path.join(cache, c + ".json")
if not os.path.exists(f) or os.path.getsize(f) < 50:
r = subprocess.run(["curl", "-s", "-m", "40", "-H", "User-Agent: Mozilla/5.0", f"https://cart.jlcpcb.com/shoppingCart/smtGood/getComponentDetail?componentCode={c}"], capture_output=True, text=True)
open(f, "w").write(r.stdout)
try:
j = json.load(open(f)); return j["data"] if isinstance(j.get("data"), dict) else j
except Exception: return {}
MULT = {"p": 1e-12, "n": 1e-9, "u": 1e-6, "µ": 1e-6, "μ": 1e-6, "m": 1e-3, "": 1, "k": 1e3, "K": 1e3, "M": 1e6}
def value_in(text, unit, prefixes):
m = re.search(r"(?<![\w.])(\d+(?:\.\d+)?)\s*([" + prefixes + "]?)" + unit, text)
return float(m.group(1)) * MULT[m.group(2)] if m else None
def cache_file(e, footprint):
key = json.dumps({**{k: e[k] for k in ("ftype", "name", "manufacturer_part_number", "standard", "pin_count") if e.get(k) is not None}, "footprinterString": footprint}, separators=(",", ":"), ensure_ascii=False)
return f".tscircuit/cache/{re.sub(r'[^a-zA-Z0-9]', '_', key)[-10:]}-{hashlib.md5(key.encode()).hexdigest()}.json"
placed = {e["source_component_id"] for e in cj if e["type"] == "pcb_component"}
footprint = {e["source_component_id"]: e.get("footprinter_string") for e in cj if e["type"] == "cad_component"}
wrong = []; unread = []; n = 0
for e in cj:
if e["type"] != "source_component" or e.get("ftype") not in ("simple_resistor", "simple_capacitor") or e["source_component_id"] not in placed: continue
c = ((e.get("supplier_part_numbers") or {}).get("jlcpcb") or [None])[0]
if not c: continue
text = detail(c).get("describe") or ""; n += 1
want, got = (e.get("resistance"), value_in(text, "Ω", "mkKM")) if e["ftype"] == "simple_resistor" else (e.get("capacitance"), value_in(text, "F", "pnuµμ"))
shown = e.get("display_resistance") or e.get("display_capacitance")
if got is None: unread.append(f" {e['name']} ({shown}): {c} {text[:60]!r}")
elif want is None or abs(got - want) > 0.011 * abs(want):
files = [f for f in (cache_file(e, fp) for fp in ("0402", "0603", "0805", "1206", footprint.get(e["source_component_id"]) or "")) if os.path.exists(f)]
wrong.append(f" {e['name']} should be {shown}, but {c} is: {text[:70]}\n cache file: {files[0] if files else 'none (already deleted, or the part number is set in the source)'}")
print(f"{n} resistors and capacitors checked against JLCPCB's data: {len(wrong)} with the wrong value" + (f", {len(unread)} could not be read" if unread else ""))
print("\n".join(wrong + unread))
sys.exit(1 if wrong else 0)