我需要表示一个包含 Arduino 的电路。我对 circuitikz 和 latex 还不熟悉,所以我无法编写复杂的电路元件。
答案1
我认为没有这样的包,但你可以创建自己的 Arduino Uno 组件。我建议你阅读 CircuiTikZ 手册:https://texdoc.org/serve/circuitikzmanual.pdf/0,并阅读有关 LaTeX 的资料(网上有很多相关资源,只需在谷歌中搜索即可)。
之后,为了创建您自己的组件,我建议您查看 John Kormylo 在此处的回答:CircuiTikZ — 创建新组件按照他的多极教程,我能够创建这个 Arduino Uno 图来使 LED 闪烁:
这是代码:
\documentclass[margin=3mm]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[american, siunitx]{circuitikz}
\pgfdeclareshape{arduno}{
\anchor{center}{\pgfpointorigin} % within the node, (0,0) is the center
\anchor{text} % this is used to center the text in the node
{\pgfpoint{-.5\wd\pgfnodeparttextbox}{-.5\ht\pgfnodeparttextbox}}
% Pin Assignments
\savedanchor\ardunoa{\pgfpoint{-2.4cm}{-3.5cm}} % Pin A5
\anchor{A5}{\ardunoa}
\savedanchor\ardunob{\pgfpoint{-2.4cm}{-3cm}} % Pin A4
\anchor{A4}{\ardunob}
\savedanchor\ardunoc{\pgfpoint{-2.4cm}{-2.5cm}} % Pin A3
\anchor{A3}{\ardunoc}
\savedanchor\ardunod{\pgfpoint{-2.4cm}{-2cm}} % Pin A2
\anchor{A2}{\ardunod}
\savedanchor\ardunoe{\pgfpoint{-2.4cm}{-1.5cm}} % Pin A1
\anchor{A1}{\ardunoe}
\savedanchor\ardunof{\pgfpoint{-2.4cm}{-1cm}} % Pin A0
\anchor{A0}{\ardunof}
\savedanchor\ardunog{\pgfpoint{2.4cm}{-3.5cm}} % Pin D0
\anchor{D0}{\ardunog}
\savedanchor\ardunoh{\pgfpoint{2.4cm}{-3cm}} % Pin D1
\anchor{D1}{\ardunoh}
\savedanchor\ardunoi{\pgfpoint{2.4cm}{-2.5cm}} % Pin D2
\anchor{D2}{\ardunoi}
\savedanchor\ardunoj{\pgfpoint{2.4cm}{-2cm}} % Pin D3
\anchor{D3}{\ardunoj}
\savedanchor\ardunok{\pgfpoint{2.4cm}{-1.5cm}} % Pin D4
\anchor{D4}{\ardunok}
\savedanchor\ardunol{\pgfpoint{2.4cm}{-1cm}} % Pin D5
\anchor{D5}{\ardunol}
\savedanchor\ardunom{\pgfpoint{2.4cm}{-0.5cm}} % Pin D6
\anchor{D6}{\ardunom}
\savedanchor\ardunon{\pgfpoint{2.4cm}{0cm}} % Pin D7
\anchor{D7}{\ardunon}
\savedanchor\ardunoo{\pgfpoint{2.4cm}{0.5cm}} % Pin D8
\anchor{D8}{\ardunoo}
\savedanchor\ardunop{\pgfpoint{2.4cm}{1cm}} % Pin D9
\anchor{D9}{\ardunop}
\savedanchor\ardunoq{\pgfpoint{2.4cm}{1.5cm}} % Pin D10
\anchor{D10}{\ardunoq}
\savedanchor\ardunor{\pgfpoint{2.4cm}{2cm}} % Pin D11
\anchor{D11}{\ardunor}
\savedanchor\ardunos{\pgfpoint{2.4cm}{2.5cm}} % Pin D12
\anchor{D12}{\ardunos}
\savedanchor\ardunot{\pgfpoint{2.4cm}{3cm}} % Pin D13
\anchor{D13}{\ardunot}
\savedanchor\ardunou{\pgfpoint{-2.4cm}{2.5cm}} % Pin AREF
\anchor{AREF}{\ardunou}
\savedanchor\ardunov{\pgfpoint{-2.4cm}{3cm}} % Pin RST
\anchor{RST}{\ardunov}
\savedanchor\ardunow{\pgfpoint{0.1cm}{-4.4cm}} % Pin GND
\anchor{GND}{\ardunow}
\savedanchor\ardunox{\pgfpoint{-1cm}{4.4cm}} % Pin 3V
\anchor{3V}{\ardunox}
\savedanchor\ardunoy{\pgfpoint{-0.5cm}{4.4cm}} % Pin 5V
\anchor{5V}{\ardunoy}
\savedanchor\ardunoz{\pgfpoint{1cm}{4.4cm}} % Pin Vin
\anchor{VIN}{\ardunoz}
\foregroundpath{ % Border and Pin Names are drawn here
% Container
\pgfsetlinewidth{0.5pt}
\pgfpathrectanglecorners{\pgfpoint{2cm}{4cm}}{\pgfpoint{-2cm}{-4cm}}
\pgfusepath{draw}
% Analog Input Pins
\pgfsetlinewidth{0.9pt}
\pgfpathmoveto{\pgfpoint{-2cm}{-3.5cm}}
\pgfpathlineto{\pgfpoint{-2.4cm}{-3.5cm}}
\pgfpathmoveto{\pgfpoint{-2cm}{-3cm}}
\pgfpathlineto{\pgfpoint{-2.4cm}{-3cm}}
\pgfpathmoveto{\pgfpoint{-2cm}{-2.5cm}}
\pgfpathlineto{\pgfpoint{-2.4cm}{-2.5cm}}
\pgfpathmoveto{\pgfpoint{-2cm}{-2cm}}
\pgfpathlineto{\pgfpoint{-2.4cm}{-2cm}}
\pgfpathmoveto{\pgfpoint{-2cm}{-1.5cm}}
\pgfpathlineto{\pgfpoint{-2.4cm}{-1.5cm}}
\pgfpathmoveto{\pgfpoint{-2cm}{-1cm}}
\pgfpathlineto{\pgfpoint{-2.4cm}{-1cm}}
\pgfusepath{draw}
% Digital Input/Output Pins
\pgfpathmoveto{\pgfpoint{2cm}{-3.5cm}}
\pgfpathlineto{\pgfpoint{2.4cm}{-3.5cm}}
\pgfpathmoveto{\pgfpoint{2cm}{-3cm}}
\pgfpathlineto{\pgfpoint{2.4cm}{-3cm}}
\pgfpathmoveto{\pgfpoint{2cm}{-2.5cm}}
\pgfpathlineto{\pgfpoint{2.4cm}{-2.5cm}}
\pgfpathmoveto{\pgfpoint{2cm}{-2cm}}
\pgfpathlineto{\pgfpoint{2.4cm}{-2cm}}
\pgfpathmoveto{\pgfpoint{2cm}{-1.5cm}}
\pgfpathlineto{\pgfpoint{2.4cm}{-1.5cm}}
\pgfpathmoveto{\pgfpoint{2cm}{-1cm}}
\pgfpathlineto{\pgfpoint{2.4cm}{-1cm}}
\pgfpathmoveto{\pgfpoint{2cm}{-0.5cm}}
\pgfpathlineto{\pgfpoint{2.4cm}{-0.5cm}}
\pgfpathmoveto{\pgfpoint{2cm}{0cm}}
\pgfpathlineto{\pgfpoint{2.4cm}{0cm}}
\pgfpathmoveto{\pgfpoint{2cm}{0.5cm}}
\pgfpathlineto{\pgfpoint{2.4cm}{0.5cm}}
\pgfpathmoveto{\pgfpoint{2cm}{1cm}}
\pgfpathlineto{\pgfpoint{2.4cm}{1cm}}
\pgfpathmoveto{\pgfpoint{2cm}{1.5cm}}
\pgfpathlineto{\pgfpoint{2.4cm}{1.5cm}}
\pgfpathmoveto{\pgfpoint{2cm}{2cm}}
\pgfpathlineto{\pgfpoint{2.4cm}{2cm}}
\pgfpathmoveto{\pgfpoint{2cm}{2.5cm}}
\pgfpathlineto{\pgfpoint{2.4cm}{2.5cm}}
\pgfpathmoveto{\pgfpoint{2cm}{3cm}}
\pgfpathlineto{\pgfpoint{2.4cm}{3cm}}
\pgfusepath{draw}
% AREF, RST Pins
\pgfpathmoveto{\pgfpoint{-2cm}{2.5cm}}
\pgfpathlineto{\pgfpoint{-2.4cm}{2.5cm}}
\pgfpathmoveto{\pgfpoint{-2cm}{3cm}}
\pgfpathlineto{\pgfpoint{-2.4cm}{3cm}}
\pgfusepath{draw}
% GND Pin
\pgfpathmoveto{\pgfpoint{0.1cm}{-4cm}}
\pgfpathlineto{\pgfpoint{0.1cm}{-4.4cm}}
\pgfusepath{draw}
% Power Pins
\pgfpathmoveto{\pgfpoint{-1cm}{4cm}}
\pgfpathlineto{\pgfpoint{-1cm}{4.4cm}}
\pgfpathmoveto{\pgfpoint{-0.5cm}{4cm}}
\pgfpathlineto{\pgfpoint{-0.5cm}{4.4cm}}
\pgfpathmoveto{\pgfpoint{1cm}{4cm}}
\pgfpathlineto{\pgfpoint{1cm}{4.4cm}}
\pgfusepath{draw}
% Arduino UNO Board Name
\pgftext[bottom,at={\pgfpoint{0cm}{1.6cm}}]{\normalsize Arduino}
\pgftext[bottom,at={\pgfpoint{-0.25cm}{1.15cm}}]{\normalsize UNO}
% Analog Input Pin Names
\pgftext[bottom,rotate=-90,at={\pgfpoint{2.3cm}{-1.3cm}}]{\footnotesize Analog Input}
\pgftext[center,at={\pgfpoint{-1.6cm}{-3.5cm}}]{\footnotesize A5}
\pgftext[center,at={\pgfpoint{-1.6cm}{-3cm}}]{\footnotesize A4}
\pgftext[center,at={\pgfpoint{-1.6cm}{-2.5cm}}]{\footnotesize A3}
\pgftext[center,at={\pgfpoint{-1.6cm}{-2cm}}]{\footnotesize A2}
\pgftext[center,at={\pgfpoint{-1.6cm}{-1.5cm}}]{\footnotesize A1}
\pgftext[center,at={\pgfpoint{-1.6cm}{-1cm}}]{\footnotesize A0}
% Digital Input/Output Pin Names
\pgftext[bottom,rotate=90,at={\pgfpoint{-0.3cm}{-1.3cm}}]{\footnotesize Digital Input/Output}
\pgftext[center,at={\pgfpoint{1.6cm}{-3.5cm}}]{\footnotesize D0}
\pgftext[center,at={\pgfpoint{1.6cm}{-3cm}}]{\footnotesize D1}
\pgftext[center,at={\pgfpoint{1.6cm}{-2.5cm}}]{\footnotesize D2}
\pgftext[center,at={\pgfpoint{1.6cm}{-2cm}}]{\footnotesize D3}
\pgftext[center,at={\pgfpoint{1.6cm}{-1.5cm}}]{\footnotesize D4}
\pgftext[center,at={\pgfpoint{1.6cm}{-1cm}}]{\footnotesize D5}
\pgftext[center,at={\pgfpoint{1.6cm}{-0.5cm}}]{\footnotesize D6}
\pgftext[center,at={\pgfpoint{1.6cm}{0cm}}]{\footnotesize D7}
\pgftext[center,at={\pgfpoint{1.6cm}{0.5cm}}]{\footnotesize D8}
\pgftext[center,at={\pgfpoint{1.6cm}{1cm}}]{\footnotesize D9}
\pgftext[center,at={\pgfpoint{1.6cm}{1.5cm}}]{\footnotesize D10}
\pgftext[center,at={\pgfpoint{1.6cm}{2cm}}]{\footnotesize D11}
\pgftext[center,at={\pgfpoint{1.6cm}{2.5cm}}]{\footnotesize D12}
\pgftext[center,at={\pgfpoint{1.6cm}{3cm}}]{\footnotesize D13}
% RST, AREF Pin Names
\pgftext[center,at={\pgfpoint{-1.5cm}{2.5cm}}]{\footnotesize AREF}
\pgftext[center,at={\pgfpoint{-1.6cm}{3cm}}]{\footnotesize RST}
% GND Pin Name
\pgftext[top,at={\pgfpoint{0.1cm}{-3.6cm}}]{\footnotesize GND}
% Power Pin Names
\pgftext[top,at={\pgfpoint{0.1cm}{3.5cm}}]{\small Power}
\pgftext[top,at={\pgfpoint{-1cm}{3.8cm}}]{\footnotesize 3V}
\pgftext[top,at={\pgfpoint{-0.5cm}{3.8cm}}]{\footnotesize 5V}
\pgftext[top,at={\pgfpoint{1cm}{3.8cm}}]{\footnotesize Vin}
}
}
\begin{document}
\begin{tikzpicture}
\draw
(2,4) node[arduno] (arduno1) {}
(arduno1.D13) to(6,7) to [R](6,3) to [leDo](6,-0.9)
(arduno1.GND) to(2.1,-0.9) to (6,-0.9)
;
\node[align=left] at (7,5) {220 $\Omega$ \\ Resistor};
\node[align=left] at (7.2,1) {LED};
\end{tikzpicture}
\end{document}
如果您不想,您不必创建 Arduino Uno 的精确物理表示,只要您以可理解的方式表示其引脚就足够了。无论哪种方式,欢迎提出任何有关如何改善我的图表(或我的代码)美观的建议
答案2
作为起点,您可以使用以下代码(它不是 Arduino Uno 的完整代码,并且某些组件未缩放)。
\documentclass[margin=5mm]{standalone}
\usepackage{xcolor,circuitikz,tikz}
\usetikzlibrary{calc,intersections,positioning}
\definecolor{darkcerulean}{rgb}{0.03, 0.27, 0.49}
\tikzset{%
myarduino/.pic={
\coordinate (A) at (0,0);
\filldraw[very thick, darkcerulean] (A)--(66.1,0)-|(66.1,2.5)--++(45:2.5)--++(90:30)--++(135:2.5)--++(90:16)--++(180:66.1)--cycle;
\filldraw[very thick,gray!40](-2.5,3) rectangle (10,10);
\filldraw[very thick,gray!40](-6,40) rectangle (10,50);
\filldraw[very thick,gray](25,13) rectangle (63,20);
\foreach \x/\t in {26/RESET,29/3V3,32/5V,35/GND1,38/GND2,41/VIN}{
\node (\t) at (\x,3mm) [fill,draw,minimum width=3mm,minimum height=3mm]{};
\node at (\x,5mm) [xshift=2.5mm,above=8mm,rotate=90]{$\mathbf{\t}$};}
\foreach \x/\n in {46/0,49/1,52/2,55/3,58/4,61/5}{
\node (\n) at (\x,3mm) [fill,draw,minimum width=3mm,minimum height=3mm]{};
\node at (\x,3mm) [above=3mm]{$\mathbf{\n}$};}
}
}
\begin{document}
\begin{tikzpicture}[x=2mm,y=2mm]
\pic at (0,0) {myarduino};
\draw[very thick] (GND1)--++(-90:10);
\draw[very thick] (RESET)--++(-90:10);
\draw[very thick] (1)--++(-90:10);
\draw[very thick] (4)--++(-90:10);
\end{tikzpicture}
\end{document}