MustafaMulla29/bluetooth-connected-pedometer
It defines a PCB footprint and schematic symbol for a row of solder pads used as wire connection points, featuring customizable spacing and label annotations.
- Version
- 0.3.0
- License
- unset
- Stars
- 0
Use with the tscircuit CLI
tsci is the tscircuit CLI. Install it with npm install -g tscircuit.
tsci clone MustafaMulla29/bluetooth-connected-pedometer # download the package files into ./bluetooth-connected-pedometer
tsci add MustafaMulla29/bluetooth-connected-pedometer # add it to your project as @tsci/MustafaMulla29.bluetooth-connected-pedometerIn 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.
scripts/prepare_fabrication.py
#!/usr/bin/env python3
"""Package the verified tscircuit export for JLCPCB; never changes copper."""
import csv, io, json, re, zipfile, hashlib
from collections import defaultdict
from pathlib import Path
root=Path(__file__).resolve().parents[1]
fab=root/'fabrication'
items=json.loads((root/'dist/index/circuit.json').read_text())
for report in ['build-diagnostics.json','fabrication-check.json']:
data=json.loads((root/'docs'/report).read_text())
assert data['circuit_sha256']==hashlib.sha256((root/'dist/index/circuit.json').read_bytes()).hexdigest(), 'Stale check report'
assert not data.get('errors') and not data.get('violations'), 'Unresolved fabrication errors'
source={o['name']:o for o in items if o['type']=='source_component'}
land_names={'J1','J2','J3','J5'}
source={k:v for k,v in source.items() if k not in land_names}
packages={'U1':'RF-BM-2340B1-SMD30-P1.27','U2':'WSON-10-EP-2.2x2','U3':'DSBGA-9-P0.5','U4':'SOT-23-5','U5':'LGA-12-2x2','U6':'SOT-23-6',
'Y1':'Crystal-2016-4P','Y2':'Crystal-3215-2P','L1':'0805','L2':'0402','J4':'U.FL-R-SMT-1','SW1':'TS-1088','SW2':'TS-1088'}
cap_sizes={'C19702':'0603','C15850':'0805','C15849':'0603','C1779':'0805','C1705':'0603','C1607':'0603'}
groups=defaultdict(list)
for name,o in source.items():
mpn=o.get('manufacturer_part_number');parts=o.get('supplier_part_numbers',{}).get('jlcpcb',[])
assert mpn and len(parts)==1,(name,mpn,parts)
lcsc=parts[0];footprint=packages.get(name,cap_sizes.get(lcsc,'0402'))
groups[(mpn,lcsc,footprint)].append(name)
with (fab/'BOM.csv').open('w',newline='') as f:
w=csv.writer(f);w.writerow(['Comment','Designator','Footprint','LCSC Part #'])
for (mpn,lcsc,footprint),names in groups.items():w.writerow([mpn,','.join(names),footprint,lcsc])
# Pin coordinates make package-specific rotation review independent of library zero.
by_id={o['source_component_id']:o['name'] for o in items if o['type']=='source_component'}
sp={o['source_port_id']:o for o in items if o['type']=='source_port' and o['source_component_id'] in by_id}
with (fab/'pin-coordinates.csv').open('w',newline='') as f:
w=csv.writer(f);w.writerow(['Reference','Pin','Signal_and_ball_aliases','X_mm','Y_mm','Side'])
for o in items:
if o['type']!='pcb_port' or o['source_port_id'] not in sp:continue
p=sp[o['source_port_id']]
w.writerow([by_id[p['source_component_id']],p.get('pin_number',''),';'.join(p.get('port_hints',[p['name']])),
f"{o['x']:.6f}",f"{o['y']:.6f}",'/'.join(o['layers'])])
z=zipfile.ZipFile(fab/'gerbers.zip')
rows=list(csv.DictReader(io.StringIO(z.read('pick_and_place.csv').decode())))
rows=[r for r in rows if r['Designator'] in source]
assert {r['Designator'] for r in rows}==set(source) and len(rows)==len(source)
with (fab/'CPL.csv').open('w',newline='') as f:
w=csv.DictWriter(f,fieldnames=['Designator','Mid X','Mid Y','Layer','Rotation']);w.writeheader();w.writerows(rows)
layer_count=next(o['num_layers'] for o in items if o['type']=='pcb_board')
through_drill=f'drill-L1-L{layer_count}.drl'
assert [n for n in z.namelist() if n.endswith('.drl') and 'npth' not in n]==[through_drill], 'Unexpected blind/buried drill span'
# Coincident same-size holes arise when routes reuse a via. Emit one drill hit.
removed=0;drill_count=0
with zipfile.ZipFile(fab/'stride-reve-gerbers.zip','w',zipfile.ZIP_DEFLATED) as out:
for n in z.namelist():
if not n.endswith(('.gbr','.drl')):continue
s=z.read(n).decode()
if n.endswith('.drl'):
seen=set();tool=None;lines=[]
for line in s.splitlines():
if re.fullmatch(r'T\d+',line):tool=line
if line.startswith('X'):
key=(tool,line)
if key in seen:removed+=1;continue
seen.add(key)
if n==through_drill:drill_count+=1
lines.append(line)
s='\n'.join(lines)+'\n'
out.writestr(n,s)
report={'circuit_sha256':hashlib.sha256((root/'dist/index/circuit.json').read_bytes()).hexdigest(),
'purchased_components':len(source),'unique_part_numbers':len(groups),'through_drill_hits':drill_count,
'duplicate_same_tool_drill_hits_removed':removed,'coordinate_origin':'Board center, mm; same as Gerbers',
'copper_processing':'None; Gerbers are unchanged from the tscircuit exporter'}
(fab/'export-manifest.json').write_text(json.dumps(report,indent=2)+'\n')
print(json.dumps(report,indent=2))