Electronics (PCBs, boards, enclosures)
Put printed-circuit boards in your model without drawing a single resistor:
pick parts from the catalog, place them on a board in one line each, use a
ready Arduino / Raspberry Pi / ESP32 / Feather, mount it on standoffs, and
generate a 3D-printable tray with cutouts where the connectors are. This is
the cadbuildr-electronics library, built on Foundation.
Prerequisites: pip install cadbuildr-electronics (it installs
cadbuildr-foundation and cadbuildr-stdlib).
It models the mechanical board (outline, holes, component bodies, connector positions), not the circuit: there are no nets or traces.
Populate a board
from cadbuildr.foundation import show
from cadbuildr.electronics import PCB, PinHeader, Resistor, LED, SOTPackage, USBTypeC
pcb = PCB(50, 30, color="blue")
pcb.place(PinHeader(positions=6), ref="J1", x=-18, y=10)
pcb.place(Resistor("220"), ref="R1", x=0, y=0, rotation=90)
pcb.place(LED("red"), ref="D1", x=12, y=0)
pcb.place(SOTPackage("SOT-223"), ref="U1", x=-8, y=-8)
pcb.place(USBTypeC(), ref="J2", x=0, y=15 - 3.65)
pcb.mounting_holes_rect(3, 3)
show(pcb)Each place call does two things from one pose: it drills and paints the
part’s land pattern into the board, and it seats the 3D body on top. Holes
and bodies cannot drift apart. Coordinates are millimetres from the board
centre; rotation is in degrees, counter-clockwise seen from the top;
side="bottom" puts the part underneath (its land pattern is mirrored for
you).
pcb.bom() lists every placement with its value and package;
pcb.bom_table() groups them with quantities.
Use a ready board
from cadbuildr.electronics.boards import ArduinoUno, RaspberryPiZero, Feather, OledModule
board = Feather(mcu="RP2040")Available: ArduinoUno, ArduinoNano, ArduinoMega, RaspberryPi,
RaspberryPiZero, RaspberryPiPico, ESP32DevKit, Feather, and the
display modules OledModule and CharacterLCD. Outlines, mounting holes
and connector positions follow the real boards; the smaller parts are
stylised.
Mount a board on standoffs
Every board exposes its mounting holes as screw holes: mount_1, mount_2…
on the top face and mount_1_under… on the underside. Standoffs and screws
connect to them, so you never type their coordinates.
from cadbuildr.foundation import Assembly
from cadbuildr.stdlib.fasteners.screws_and_bolts.din912_part import DIN912Screw
from cadbuildr.electronics import Standoff
from cadbuildr.electronics.boards import RaspberryPi
pi = RaspberryPi()
asm = Assembly()
asm.ground(pi)
asm.connect_all(lambda: Standoff("M2.5", 11, "male-female"), pi.group("mount_under"), own="top")
asm.connect_all(lambda: DIN912Screw("M2.5", 6, with_thread=False), pi.group("mount"))
print(asm.check()) # [] when every part is connected and every loop closesThe screw size comes from the hole (a 2.75 mm hole takes M2.5, 3.2 mm takes M3).
Put a board in a case
from cadbuildr.electronics import BoardInEnclosure
box = BoardInEnclosure(board="ArduinoUno")The tray is generated from the board: a boss under each mounting hole, and
a rectangular opening in the wall in front of each sideways connector (USB,
barrel jack, RJ45, HDMI, microSD…). The board, tray and screws are joined
with connect, and each boss and cutout is checked against the board, so a
connector that moves away from its opening raises an error instead of
producing a case that does not fit.
For your own board, build the tray directly:
from cadbuildr.electronics import PCBEnclosure
tray = PCBEnclosure(pcb, wall=2, standoff=5, headroom=15)Upward-facing parts (headers, JST connectors, buttons, displays) need a lid, which is not generated yet.
Parts and packages
| Group | Items |
|---|---|
| Passives | Resistor, ResistorSMD, CeramicCapacitor, ElectrolyticCapacitor, ChipPackage |
| Semiconductors | LED, Diode, SOTPackage, TOPackage |
| ICs | DIP, SOIC, QFP, DualInlinePackage, SmallOutlinePackage, QuadFlatPackage, QFNPackage |
| Connectors | PinHeader, FemaleHeader, ScrewTerminal, USBTypeA, USBMicroB, USBTypeC, HDMIConnector, MicroSDSocket, JSTConnector, RJ45, BarrelJack |
| Other | Crystal, TactileButton, SlideSwitch, Buzzer, DisplayPanel, Standoff |
The *Package items take a package code ("SOIC-8", "QFN-32_5x5",
"SOT-23-5", "TO-220-3"…) and generate the body and an IPC-7351B land
pattern from catalog data. CatalogPart("AMS1117-3.3") picks the package
from a manufacturer part number.
In the CADbuildr app every item is in the Electronics tab of the library toolbar, and its inputs (package, value, size, board…) are editable in the Configuration bar.
When something is wrong
Errors are named and say what to change: a reference designator used twice
or a part placed twice raises PlacementError, an unknown package
UnknownPackage, an odd pin count for a dual-row package FootprintError.
All of them are ElectronicsError, a ValueError.