Files
RoboMovel/ferramentas/scripts/cad/pecas/arduino_uno.py
T
mguinhosandClaude Opus 5.5 f267d0c127 Projeto: robo de teste modular impresso na Ender 3 e chapas identificadas em camadas
Robo de teste em PLA (caixa_teste_ender3.py): fundo em 6 placas com grade de furos,
paredes e bandejas separadas, presas pelo mesmo pino de encaixe; STL e G-codes para
os bicos de 0,2 e 0,4 mm (os de 0,4 mm usam G29 no inicio).

Chapas 35x35: posicao dos suportes NEMA17 em azul e DXF identificado com as camadas
CORTE, SUPORTES e TEXTO para o LightBurn.

Scripts CAD: caminhos relativos ao repositorio e guarda contra links vazios.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 12:18:16 -03:00

277 lines
13 KiB
Python

# -*- coding: utf-8 -*-
"""Arduino UNO R3 — clone azul CH340G/ATmega328P-AU (o do kit Twotrees).
Coordenadas mecânicas (contorno, furos, barras de pinos, USB-B, P4) do
footprint oficial KiCad 'Module:Arduino_UNO_R3' convertido para origem no
canto inferior esquerdo (lado do USB à esquerda, pinos digitais em cima):
placa 68,58 x 53,34 x 1,6 mm
furos Ø3,2: (13,97; 2,54) (15,24; 50,80) (66,04; 7,62) (66,04; 35,56)
digitais D0..D7 x = 63,50 .. 45,72 (y = 50,80)
D8..D13,GND,AREF,SDA,SCL x = 41,66 .. 18,80 (y = 50,80)
POWER NC,IOREF,RESET,3V3,5V,GND,GND,VIN x = 27,94 .. 45,72 (y = 2,54)
A0..A5 x = 50,80 .. 63,50 (y = 2,54)
ICSP 2x3 centro (64,77; 27,94)
USB-B: x -6,35..9,53 y 32,38..43,81 ; P4: x -1,9..11,43 y 3,18..12,07
Componentes posicionados a partir da foto do anúncio (escala 12,7 px/mm).
"""
import math, sys, os
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) # cad/ deste repositório
import importlib, lib_rm; importlib.reload(lib_rm)
from lib_rm import *
T_PCB = 1.6
P = 2.54
HOLES = [(13.97, 2.54), (15.24, 50.80), (66.04, 7.62), (66.04, 35.56)]
OUTLINE = [(0, 0), (66.04, 0), (66.04, 2.54), (68.58, 5.08), (68.58, 37.85), (66.04, 40.39),
(66.04, 51.82), (64.52, 53.34), (0, 53.34)]
# ---- pinos (nome -> (x, y)) : usados pela montagem para ligar jumpers ----
PINS = {}
for i in range(8):
PINS["D%d" % i] = (63.50 - i * P, 50.80)
for i, n in enumerate(["D8", "D9", "D10", "D11", "D12", "D13", "GND_D", "AREF", "SDA", "SCL"]):
PINS[n] = (41.66 - i * P, 50.80)
for i, n in enumerate(["NC", "IOREF", "RESET", "3V3", "5V", "GND1", "GND2", "VIN"]):
PINS[n] = (27.94 + i * P, 2.54)
for i in range(6):
PINS["A%d" % i] = (50.80 + i * P, 2.54)
ICSP = [(63.50 + c * P, 25.40 + r * P) for r in range(3) for c in range(2)]
# bloco extra do clone (3 x 4): RX TX 5V GND / SCL SDA 5V GND / 3V3 3V3 GND GND
EXTRA = {}
for r, row in enumerate([["RX", "TX", "5V", "GND"], ["SCL", "SDA", "5V", "GND"], ["3V3", "3V3", "GND", "GND"]]):
for c, n in enumerate(row):
EXTRA["X_%s_%d%d" % (n, r, c)] = (58.42 + c * P, 21.59 - r * P)
def pcb():
pts = [V(x, y, 0) for x, y in OUTLINE]
s = Part.Face(Part.makePolygon(pts + [pts[0]])).extrude(V(0, 0, T_PCB))
tools = [cyl(1.6, 4, V(x, y, -1)) for x, y in HOLES]
allp = list(PINS.values()) + ICSP + list(EXTRA.values())
# fileira extra de furos ao lado das barras (característica do clone)
allp += [(x, y - P) for (x, y) in PINS.values() if y > 40]
allp += [(x, y + P) for (x, y) in PINS.values() if y < 10]
allp += [(12.0 + k * P, 23.6) for k in range(3)] # X1 (não montado)
tools += [cyl(0.5, 4, V(x, y, -1)) for x, y in allp]
return s.cut(Part.makeCompound(tools)), allp
def pads(allp):
out = []
for x, y in allp:
for z in (T_PCB, -0.035):
out.append(cyl(0.85, 0.035, V(x, y, z)).cut(cyl(0.5, 1, V(x, y, z - 0.5))))
for x, y in HOLES:
out.append(cyl(2.6, 0.035, V(x, y, T_PCB)).cut(cyl(1.6, 1, V(x, y, T_PCB - 0.5))))
return Part.makeCompound(out)
def female_header(n, x0, y0, dx=P, dy=0.0, h=8.5):
"""Barra fêmea 2,54 (preta). Pinos a partir de (x0, y0) avançando dx/dy."""
bodies, pins = [], []
for i in range(n):
x, y = x0 + i * dx, y0 + i * dy
b = cbox(P, P, h, x, y, T_PCB)
b = b.cut(cbox(1.0, 1.0, h - 1.0, x, y, T_PCB + 1.1)) # cavidade do contato
b = b.cut(Part.makeCone(0.5, 0.9, 0.4, V(x, y, T_PCB + h - 0.4)))
bodies.append(b)
pins.append(cbox(0.64, 0.3, 3.0, x, y, -3.0 + 0.0))
return fuse(bodies), pins
def male_pins(pts, h_above=6.0, below=3.0, base=2.5, z0=T_PCB, color_base=True):
bases, pins = [], []
for x, y in pts:
bases.append(cbox(P, P, base, x, y, z0))
pins.append(cbox(0.64, 0.64, h_above + base + below, x, y, z0 - below))
return bases, pins
def smd_box(dx, dy, dz, cx, cy):
return cbox(dx, dy, dz, cx, cy, T_PCB)
def silk(txt, size, x, y, ang=0, font=FONT_REG, anchor="c"):
t = text_shape(txt, size, font, height=0.02)
if t is None:
return None
bb = t.BoundBox
ox = {"c": (bb.XMin + bb.XMax) / 2, "l": bb.XMin, "r": bb.XMax}[anchor]
t.translate(V(-ox, -(bb.YMin + bb.YMax) / 2, 0))
if ang:
t.rotate(V(0, 0, 0), V(0, 0, 1), ang)
t.translate(V(x, y, T_PCB + 0.036))
return t
def usb_b():
"""Receptáculo USB-B THT: 12,0 x 16,0 x 10,9 (x -6,35 .. 9,65)."""
x0, x1 = -6.35, 9.53
y0, y1 = 32.38, 43.81
h = 10.9
b = box(x1 - x0, y1 - y0, h, x0, y0, T_PCB)
b = b.cut(box(8.4, 8.5, 8.0, x0 - 0.1, (y0 + y1) / 2 - 4.25, T_PCB + 1.2))
tongue = box(7.0, 5.5, 1.6, x0 + 1.2, (y0 + y1) / 2 - 2.75, T_PCB + 4.4)
return b, tongue
def dc_jack():
"""Conector P4 (5,5 x 2,1) preto."""
x0, x1, y0, y1 = -1.9, 11.43, 3.18, 12.07
b = box(x1 - x0 - 3.5, y1 - y0, 11.0, x0 + 3.5, y0, T_PCB)
c = cyl(4.45, 3.5, V(x0 + 3.5, (y0 + y1) / 2, T_PCB + 6.5), V(-1, 0, 0))
s = b.fuse(c).cut(cyl(3.2, 12, V(x0 - 0.1, (y0 + y1) / 2, T_PCB + 6.5), V(1, 0, 0)))
pin = cyl(1.0, 10, V(x0 - 0.1, (y0 + y1) / 2, T_PCB + 6.5), V(1, 0, 0))
return s, pin
def qfp(n_side, body, pitch, cx, cy, h=1.2, rot=0):
b = smd_box(body, body, h, cx, cy)
leads = []
L = body / 2 + 0.75
for side in range(4):
for i in range(n_side):
o = (i - (n_side - 1) / 2) * pitch
ld = cbox(1.0, 0.3, 0.15, 0, 0, T_PCB)
ld.translate(V(L, o, 0))
ld.rotate(V(0, 0, 0), V(0, 0, 1), 90 * side)
ld.translate(V(cx, cy, 0))
leads.append(ld)
dot = cyl(0.35, 0.02, V(cx - body / 2 + 0.9, cy + body / 2 - 0.9, T_PCB + h))
return b, leads, dot
def soic(n, cx, cy, rot=0, body=(9.9, 3.9), h=1.5, pitch=1.27):
bx, by = body
b = smd_box(bx, by, h, cx, cy)
leads = []
for side in (-1, 1):
for i in range(n // 2):
x = cx + (i - (n // 2 - 1) / 2) * pitch
leads.append(cbox(0.42, 1.05, 0.9, x, cy + side * (by / 2 + 0.5), T_PCB))
return b, leads
def hc49(cx, cy, along_y=False, smd=False):
L, W, H = (11.4, 4.7, 4.2) if smd else (11.0, 4.65, 3.5)
if along_y:
b = rbox(W, L, H, W / 2 - 0.01, cx - W / 2, cy - L / 2, T_PCB)
else:
b = rbox(L, W, H, W / 2 - 0.01, cx - L / 2, cy - W / 2, T_PCB)
base = None
if smd:
base = smd_box(12.9, 5.0, 0.6, cx, cy) if not along_y else smd_box(5.0, 12.9, 0.6, cx, cy)
b.translate(V(0, 0, 0.6))
return b, base
def elco_smd(cx, cy, d=6.3, h=5.4):
base = smd_box(d + 0.3, d + 0.3, 1.0, cx, cy)
can = cyl(d / 2, h - 1.0, V(cx, cy, T_PCB + 1.0))
return base, can
def chip0805(cx, cy, rot=0, kind="R"):
b = smd_box(2.0, 1.25, 0.5, cx, cy) if rot == 0 else smd_box(1.25, 2.0, 0.5, cx, cy)
return b
def build(show=True):
doc = new_doc("ArduinoUNO_R3_CH340")
part = part_container(doc, "ArduinoUNO_R3_CH340", "Arduino UNO R3 (clone CH340G, ATmega328P-AU)")
board, allp = pcb()
add(doc, "PCB", board, "pcb_azul", "PCB 1,6 mm azul", group=part)
add(doc, "Pads", pads(allp), "aco", "Pads (HASL)", group=part)
# barras fêmeas
hdrs, hpins = [], []
for n, x0, y0, dx in [(10, 18.80, 50.80, P), (8, 45.72, 50.80, P), (8, 27.94, 2.54, P), (6, 50.80, 2.54, P)]:
b, p = female_header(n, x0, y0, dx)
hdrs.append(b)
hpins += p
add(doc, "BarrasFemeas", Part.makeCompound(hdrs), "preto", "Barras fêmea 2,54 (10+8+8+6)", group=part)
add(doc, "TerminaisBarras", Part.makeCompound(hpins), "aco", "Terminais sob a placa", group=part)
# ICSP (2x3 macho)
b, p = male_pins(ICSP)
add(doc, "ICSP_base", fuse(b), "preto", "ICSP 2x3", group=part)
add(doc, "ICSP_pinos", Part.makeCompound(p), "ouro", "Pinos ICSP", group=part)
# USB-B e P4
ub, tg = usb_b()
add(doc, "USB_B", ub, "aco", "Conector USB-B", group=part)
add(doc, "USB_B_lingueta", tg, "branco", "Lingueta USB-B", group=part)
dj, dpin = dc_jack()
add(doc, "P4", dj, "preto", "Conector P4 5,5x2,1", group=part)
add(doc, "P4_pino", dpin, "aco", "Pino P4", group=part)
# CIs
mb, ml, md = qfp(8, 7.0, 0.8, 41.9, 27.4)
add(doc, "ATmega328P_AU", mb, "preto", "ATmega328P-AU (TQFP-32)", group=part)
ch_b, ch_l = soic(16, 16.6, 31.5)
add(doc, "CH340G", ch_b, "preto", "CH340G (SOIC-16)", group=part)
op_b, op_l = soic(8, 23.5, 17.3, body=(4.9, 3.9))
add(doc, "LM358", op_b, "preto", "LMV358 (SOIC-8)", group=part)
sot = [smd_box(6.5, 3.5, 1.6, 5.0, 17.3), smd_box(1.1, 3.0, 0.3, 1.0, 17.3)]
leads = ml + ch_l + op_l
leads += [cbox(1.8, 0.7, 0.3, 8.9, 17.3 + k * 2.3, T_PCB) for k in (-1, 0, 1)]
add(doc, "AMS1117", fuse(sot), "preto", "AMS1117-5.0 (SOT-223)", group=part)
add(doc, "Terminais_CIs", Part.makeCompound(leads), "aco", "Terminais dos CIs", group=part)
add(doc, "Marca_pino1", md, "aco", "Marca pino 1", group=part)
s23 = [smd_box(2.9, 1.6, 1.1, 14.5, 16.8)]
add(doc, "LP2985_3V3", s23[0], "preto", "Regulador 3,3 V (SOT-23-5)", group=part)
dio = smd_box(4.3, 2.6, 2.1, 21.5, 2.6)
add(doc, "Diodo_M7", dio, "preto", "Diodo M7 (SMA)", group=part)
# cristais
x12, x12b = hc49(16.7, 38.4, smd=True)
add(doc, "Cristal_12MHz", x12, "aco", "Cristal 12 MHz (CH340G)", group=part)
add(doc, "Cristal_12MHz_base", x12b, "preto", "Base cristal", group=part)
x16, _ = hc49(53.5, 28.0, along_y=True)
add(doc, "Cristal_16MHz", x16, "aco", "Cristal 16 MHz HC-49S", group=part)
# eletrolíticos 47 µF/25 V
for k, (cx, cy) in enumerate([(14.1, 8.7), (21.2, 8.7)]):
base, can = elco_smd(cx, cy)
add(doc, "Elco47u_%d_base" % k, base, "preto", "Base eletrolítico", group=part)
add(doc, "Elco47u_%d" % k, can, "aco", "Eletrolítico 47 µF 25 V", group=part)
# botão reset (6x6 SMD, capa vermelha)
add(doc, "Reset_corpo", smd_box(6.0, 6.0, 1.8, 5.3, 49.4), "aco", "Botão reset 6x6", group=part)
add(doc, "Reset_capa", cyl(1.75, 1.7, V(5.3, 49.4, T_PCB + 1.8)), "vermelho", "Capa do botão", group=part)
add(doc, "Reset_pernas", Part.makeCompound([cbox(1.2, 0.7, 0.4, 5.3 + sx * 3.4, 49.4 + sy * 2.25, T_PCB) for sx in (-1, 1) for sy in (-1, 1)]), "aco", "Pernas do botão", group=part)
# LEDs 0805 (ON, RX, TX, L) + resistores/capacitores
leds = [(26.3, 42.1), (26.3, 35.4), (26.3, 29.1), (26.3, 22.8)]
add(doc, "LEDs", Part.makeCompound([smd_box(2.0, 1.25, 0.8, x, y) for x, y in leds]), "creme", "LEDs 0805 ON/RX/TX/L", group=part)
passives = [(26.3, y) for y in (40.0, 37.8, 33.2, 31.0, 26.9, 24.9, 20.7)]
passives += [(12.5, 45.1), (16.4, 45.1), (20.4, 45.1), (22.5, 30.5), (8.4, 29.0), (8.4, 26.4), (5.0, 26.4),
(5.0, 23.2), (12.1, 16.7), (15.4, 19.9), (20.2, 19.9), (57.6, 34.9), (57.6, 31.6), (57.6, 27.2),
(57.6, 24.5), (4.5, 12.0 + 12.5)]
add(doc, "Passivos0805", Part.makeCompound([smd_box(2.0, 1.25, 0.55, x, y) for x, y in passives]), "bege", "R/C 0805", group=part)
# serigrafia
s = []
lbl_top = ["SCL", "SDA", "AREF", "GND", "13", "12", "~11", "~10", "~9", "8"]
for i, t in enumerate(lbl_top):
s.append(silk(t, 1.15, 18.80 + i * P, 45.2, 90))
for i, t in enumerate(["7", "~6", "~5", "4", "~3", "2", "TX→1", "RX←0"]):
s.append(silk(t, 1.15, 45.72 + i * P, 45.2, 90))
s.append(silk("DIGITAL PWM(~)", 1.4, 45.8, 42.3))
for i, t in enumerate(["", "IOREF", "RES", "3.3V", "5V", "GND", "GND", "VIN"]):
if t:
s.append(silk(t, 1.1, 27.94 + i * P, 7.9, 90))
for i in range(6):
s.append(silk("A%d" % i, 1.1, 50.8 + i * P, 7.9, 90))
s.append(silk("POWER", 1.5, 36.8, 12.6))
s.append(silk("ANALOG IN", 1.5, 57.2, 12.6))
s.append(silk("ICSP", 1.2, 64.8, 32.4))
for r, row in enumerate([["RX", "TX", "5V", "GND"], ["SCL", "SDA", "5V", "GND"], ["3.3V", "3.3V", "GND", "GND"]]):
for c, t in enumerate(row):
s.append(silk(t, 0.95, 45.0 + c * 3.4, 21.59 - r * P))
for t, x, y in [("ON", 29.0, 42.1), ("RX", 29.0, 35.4), ("TX", 29.0, 29.1), ("L", 28.6, 22.8), ("X1", 22.6, 23.6),
("U5", 14.5, 14.3), ("PT", 1.8, 29.4), ("C21", 12.5, 46.8), ("C20", 16.4, 46.8), ("C16", 20.4, 46.8),
("R13", 58.0, 30.0), ("C13", 11.0, 20.4), ("C15", 18.6, 22.0)]:
s.append(silk(t, 0.9, x, y))
# contornos das barras
s.append(box(29.8, 0.15, 0.02, 30.5, 40.9, T_PCB + 0.036))
s.append(box(15.0, 0.15, 0.02, 29.5, 11.2, T_PCB + 0.036))
s.append(box(15.5, 0.15, 0.02, 49.5, 11.2, T_PCB + 0.036))
add(doc, "Serigrafia", Part.makeCompound([x for x in s if x is not None]), "branco", "Serigrafia", group=part)
doc.recompute()
save(doc)
if show:
fit()
return doc