diff --git a/docs/tutorials/arduino-uno-schematic.mdx b/docs/tutorials/arduino-uno-schematic.mdx new file mode 100644 index 00000000..77a22aa5 --- /dev/null +++ b/docs/tutorials/arduino-uno-schematic.mdx @@ -0,0 +1,388 @@ +--- +title: 'Arduino Uno Schematic' +description: 'Design the schematic layout for an Arduino Uno development board' +icon: 'code' +--- + +## Overview + +In this tutorial, we will build the schematic for the **Arduino Uno** development board. This tutorial focuses on the schematic only, utilizing the `routingDisabled` property to bypass PCB trace routing. + +We will include the core microcontroller (**ATmega328P**), the USB-to-serial communication microcontroller (**ATmega16U2**), a USB Type-B port, crystal oscillators, power decoupling, and pin headers. + +--- + +## 📋 Components Checklist + +Our schematic will consist of: +1. **ATmega328P-PU MCU (U1)** — The main processor. +2. **ATmega16U2 MCU (U2)** — The USB-to-Serial converter. +3. **USB Type-B Female Connector (J1)** — For programming and power. +4. **16MHz Crystal Oscillator (Y1)** — Clock source for the main MCU. +5. **Decoupling Capacitors & Pull-up Resistors** — To stabilize power and reset lines. +6. **Arduino Header Connectors (J2, J3, J4, J5)** — Standard pinout headers. + +--- + +## 🛠️ Step-by-Step Implementation + +Create a new tutorial snippet in your editor or local project workspace and implement the circuit using the code below. + +### 1. Main Schematic Design + +We wrap our components inside a `` block to ensure we focus purely on the logical connections and schematic symbols. + +```tsx title="ArduinoUno.tsx" +import React from "react" +import { useResistor, useCapacitor } from "@tscircuit/core" + +export const ArduinoUno = () => { + // Main MCU: ATmega328P (28-pin DIP) + const atmega328p = ( + + ) + + // USB-to-Serial MCU: ATmega16U2 (32-pin TQFP) + const atmega16u2 = ( + + ) + + // USB Port (Type B) + const usbPort = ( + + ) + + // 16MHz Crystal for U1 + const crystal = ( + + ) + + // Arduino Headers + const powerHeader = ( + + ) + + const analogHeader = ( + + ) + + const digitalHeader1 = ( + 1", + pin3: "D2", + pin4: "D3", + pin5: "D4", + pin6: "D5", + pin7: "D6", + pin8: "D7", + }} + schWidth={1.2} + schHeight={3} + schX={8} + schY={-3} + /> + ) + + const digitalHeader2 = ( + + ) + + // Passives + const R1 = useResistor("R1", { resistance: "10k" }) // Pull-up for RESET + const C1 = useCapacitor("C1", { capacitance: "100nF" }) // Decoupling capacitor + + return ( + + {/* Active Components */} + {atmega328p} + {atmega16u2} + {usbPort} + {crystal} + + {/* Headers */} + {powerHeader} + {analogHeader} + {digitalHeader1} + {digitalHeader2} + + {/* Passives */} + + + + {/* Basic Traces */} + + + + + + {/* Crystal Osc Connection */} + + + + {/* USB-to-Serial Traces */} + + + + + + {/* RX -> TX */} + {/* TX -> RX */} + + {/* Main MCU Analog Header Traces */} + + + + + + + + {/* Main MCU Digital Header Traces */} + + + + + + + + + + + + + + + + + {/* Ground headers */} + + + + + ) +} +``` + +--- + +## Conclusion + +This completes the schematic setup for the Arduino Uno. Since `routingDisabled` is set to `true`, the layout compiler skips the routing phases, keeping compilation fast and visual rendering focused purely on schematic symbols. diff --git a/docs/tutorials/draw-any-letter-leds.mdx b/docs/tutorials/draw-any-letter-leds.mdx new file mode 100644 index 00000000..e0f03917 --- /dev/null +++ b/docs/tutorials/draw-any-letter-leds.mdx @@ -0,0 +1,160 @@ +--- +title: 'Draw Any Letter with LEDs' +description: 'Create a math-driven custom component that renders A-Z alphabet letters using LED matrix math' +icon: 'code' +--- + +## Overview + +In this tutorial, we will build a custom, reusable `` component. This component dynamically renders any capital letter from A to Z on both the schematic and PCB using an array of 0603 SMD LEDs and current-limiting resistors. + +Rather than hard-coding absolute coordinates, we define a relative coordinate matrix for each letter and use basic math scaling to position the components on both views. + +--- + +## 📐 Math-Driven Layout Strategy + +To build the letters, we use a $5 \times 7$ grid system. Each letter is represented by a set of coordinates `[x, y]` where `x` is in range `[0..4]` and `y` is in range `[0..6]`. + +When rendering: +* **PCB Positioning:** We convert grid coordinates `(gx, gy)` to millimeter coordinates: + * `pcbX = (gx - 2) * spacing` + * `pcbY = (gy - 3) * spacing` + This centers the letter around `(0,0)` on the board. +* **Schematic Positioning:** We scale grid coordinates by a factor of 3 to lay out the symbols cleanly in columns and rows. + +--- + +## 🛠️ Step-by-Step Component Setup + +Create a new file `docs/tutorials/draw-any-letter-leds.mdx` or add the component definition directly to your local library. + +### 1. Reusable component definition + +```tsx title="LedLetter.tsx" +import React from "react" +import { useResistor } from "@tscircuit/core" + +// Define a 5x7 grid mapping for capital A-Z letters +const LETTER_GRIDS: Record = { + A: [[0,0], [0,1], [0,2], [0,3], [0,4], [0,5], [1,6], [2,6], [3,6], [4,5], [4,4], [4,3], [4,2], [4,1], [4,0], [1,3], [2,3], [3,3]], + B: [[0,0], [0,1], [0,2], [0,3], [0,4], [0,5], [0,6], [1,6], [2,6], [3,6], [4,5], [4,4], [1,3], [2,3], [3,3], [4,2], [4,1], [1,0], [2,0], [3,0]], + C: [[0,1], [0,2], [0,3], [0,4], [0,5], [1,6], [2,6], [3,6], [4,6], [1,0], [2,0], [3,0], [4,0]], + D: [[0,0], [0,1], [0,2], [0,3], [0,4], [0,5], [0,6], [1,6], [2,6], [3,5], [4,4], [4,3], [4,2], [3,1], [2,0], [1,0]], + E: [[0,0], [0,1], [0,2], [0,3], [0,4], [0,5], [0,6], [1,6], [2,6], [3,6], [4,6], [1,3], [2,3], [3,3], [1,0], [2,0], [3,0], [4,0]], + F: [[0,0], [0,1], [0,2], [0,3], [0,4], [0,5], [0,6], [1,6], [2,6], [3,6], [4,6], [1,3], [2,3], [3,3]], + G: [[0,1], [0,2], [0,3], [0,4], [0,5], [1,6], [2,6], [3,6], [4,6], [1,0], [2,0], [3,0], [4,0], [4,1], [4,2], [3,2], [2,2]], + H: [[0,0], [0,1], [0,2], [0,3], [0,4], [0,5], [0,6], [4,0], [4,1], [4,2], [4,3], [4,4], [4,5], [4,6], [1,3], [2,3], [3,3]], + I: [[0,6], [1,6], [2,6], [3,6], [4,6], [2,5], [2,4], [2,3], [2,2], [2,1], [0,0], [1,0], [2,0], [3,0], [4,0]], + J: [[0,1], [1,0], [2,0], [3,0], [4,1], [4,2], [4,3], [4,4], [4,5], [4,6], [3,6], [2,6], [1,6]], + K: [[0,0], [0,1], [0,2], [0,3], [0,4], [0,5], [0,6], [1,3], [2,4], [3,5], [4,6], [2,2], [3,1], [4,0]], + L: [[0,0], [0,1], [0,2], [0,3], [0,4], [0,5], [0,6], [1,0], [2,0], [3,0], [4,0]], + M: [[0,0], [0,1], [0,2], [0,3], [0,4], [0,5], [0,6], [1,5], [2,4], [3,5], [4,6], [4,5], [4,4], [4,3], [4,2], [4,1], [4,0]], + N: [[0,0], [0,1], [0,2], [0,3], [0,4], [0,5], [0,6], [1,5], [2,4], [3,3], [4,6], [4,5], [4,4], [4,3], [4,2], [4,1], [4,0]], + O: [[0,1], [0,2], [0,3], [0,4], [0,5], [1,6], [2,6], [3,6], [4,5], [4,4], [4,3], [4,2], [4,1], [3,0], [2,0], [1,0]], + P: [[0,0], [0,1], [0,2], [0,3], [0,4], [0,5], [0,6], [1,6], [2,6], [3,6], [4,5], [4,4], [3,3], [2,3], [1,3]], + Q: [[0,1], [0,2], [0,3], [0,4], [0,5], [1,6], [2,6], [3,6], [4,5], [4,4], [4,3], [4,2], [4,1], [3,0], [2,0], [1,0], [2,2], [3,1], [4,0]], + R: [[0,0], [0,1], [0,2], [0,3], [0,4], [0,5], [0,6], [1,6], [2,6], [3,6], [4,5], [4,4], [3,3], [2,3], [1,3], [2,2], [3,1], [4,0]], + S: [[0,1], [1,0], [2,0], [3,0], [4,1], [3,2], [2,3], [1,4], [0,5], [1,6], [2,6], [3,6], [4,5]], + T: [[0,6], [1,6], [2,6], [3,6], [4,6], [2,5], [2,4], [2,3], [2,2], [2,1], [2,0]], + U: [[0,6], [0,5], [0,4], [0,3], [0,2], [0,1], [1,0], [2,0], [3,0], [4,1], [4,2], [4,3], [4,4], [4,5], [4,6]], + V: [[0,6], [0,5], [0,4], [0,3], [1,2], [1,1], [2,0], [3,1], [3,2], [4,3], [4,4], [4,5], [4,6]], + W: [[0,6], [0,5], [0,4], [0,3], [0,2], [0,1], [1,0], [2,1], [2,2], [2,3], [3,0], [4,1], [4,2], [4,3], [4,4], [4,5], [4,6]], + X: [[0,6], [1,5], [2,4], [3,3], [4,2], [4,6], [3,5], [1,3], [0,2], [0,1], [0,0], [4,0], [4,1], [2,2]], + Y: [[0,6], [1,5], [2,4], [3,5], [4,6], [2,3], [2,2], [2,1], [2,0]], + Z: [[0,6], [1,6], [2,6], [3,6], [4,6], [3,5], [2,4], [1,3], [0,2], [0,1], [0,0], [1,0], [2,0], [3,0], [4,0]], +} + +interface LedLetterProps { + letter: string + power: string + gnd: string + spacing?: number // Distance between LEDs on the PCB (in mm) + pcbX?: number + pcbY?: number +} + +export const LedLetter = ({ + letter, + power, + gnd, + spacing = 3.5, + pcbX = 0, + pcbY = 0, +}: LedLetterProps) => { + const points = LETTER_GRIDS[letter.toUpperCase()] || [] + + return ( + + {points.map(([gx, gy], index) => { + const ledName = `D_${index}` + const resName = `R_${index}` + + // Mathematically project the grid to physical mm units + const ledX = (gx - 2) * spacing + const ledY = (gy - 3) * spacing + + // Offset resistor slightly above the LED + const resX = ledX + const resY = ledY + 1.5 + + return ( + + {/* SMD LED */} + + {/* Series current limiting resistor */} + + {/* Connections */} + .pin1`} /> + .pin2`} to={`.${ledName} > .anode`} /> + .cathode`} to={`${gnd}`} /> + + ) + })} + + ) +} +``` + +### 2. Using the component + +To render the letter **"A"** on a PCB, import the component and pass the net references: + +```tsx title="examples/LetterDisplay.tsx" +import { LedLetter } from "lib/LedLetter" + +export default () => ( + + {/* Draw letter A with 3.5mm LED spacing */} + + +) +``` + +--- + +## Conclusion + +This custom component enables rendering any alphabet letter dynamically using standard surface-mount (SMD) LEDs and resistors. By leveraging grid matrix logic, the component scales cleanly, and connections are correctly routed in series for each cell. diff --git a/docs/tutorials/esp32-pcb-routing.mdx b/docs/tutorials/esp32-pcb-routing.mdx new file mode 100644 index 00000000..adc79d75 --- /dev/null +++ b/docs/tutorials/esp32-pcb-routing.mdx @@ -0,0 +1,132 @@ +--- +title: 'ESP32 PCB Layout and Routing' +description: 'Laying out and routing a custom ESP32-D0WD board on a 2-layer PCB' +icon: 'code' +--- + +## Overview + +In this tutorial, we will take the reference schematic from the ESP32 development circuit and lay out its components on a physical **2-layer PCB**. + +Laying out a high-frequency RF microcontroller like the ESP32 requires careful component placement to ensure signal integrity, low noise, and good wireless performance. + +--- + +## 📐 PCB Layout Best Practices + +When laying out the ESP32 board, follow these key hardware design rules: +1. **Decoupling Capacitors:** Place decoupling capacitors (like `C4`, `C9`, `C19`) as close as physically possible to their respective VDD pins on the ESP32. +2. **Crystal Oscillator:** Keep the crystal (`U1`) and its load capacitors (`C1`, `C2`) very close to the ESP32 `XTAL_P`/`XTAL_N` pins. Keep trace lengths short and symmetrical. +3. **Antenna Placement:** Place the antenna (`ANT1`) at the outer edge of the PCB. Ensure there is a keepout area (no copper ground plane) underneath and around the antenna to prevent signal attenuation. + +--- + +## 🛠️ Step-by-Step PCB Layout + +We will wrap our circuit in a `` component with a specified size (`50mm` by `40mm`) and position each component using `pcbX`, `pcbY`, and `pcbRotation`. + +```tsx title="ESP32PcbLayout.tsx" +import React from "react" +import { useESP32_D0WD } from "@tsci/AnasSarkiz.ESP32_D0WD" +import { useResistor, useCapacitor } from "@tscircuit/core" + +export const ESP32PcbLayout = () => { + const ESP32 = useESP32_D0WD("U2") + + // Capacitors with footprints and PCB placement + const C1 = useCapacitor("C1", { capacitance: "10pF", footprint: "0402", pcbX: -6, pcbY: 12 }) + const C2 = useCapacitor("C2", { capacitance: "10pF", footprint: "0402", pcbX: -10, pcbY: 12 }) + const C3 = useCapacitor("C3", { capacitance: "100pF", footprint: "0402", pcbX: -8, pcbY: 8 }) + const C4 = useCapacitor("C4", { capacitance: "0.1uF", footprint: "0402", pcbX: 5, pcbY: 5 }) + const C5 = useCapacitor("C5", { capacitance: "10nF", footprint: "0402", pcbX: -2, pcbY: 5 }) + const C6 = useCapacitor("C6", { capacitance: "3.3nF", footprint: "0402", pcbX: -2, pcbY: 3 }) + const C9 = useCapacitor("C9", { capacitance: "1nF", footprint: "0402", pcbX: -5, pcbY: -5 }) + const C10 = useCapacitor("C10", { capacitance: "0.1uF", footprint: "0402", pcbX: -10, pcbY: -5 }) + const C11 = useCapacitor("C11", { capacitance: "1uF", footprint: "0402", pcbX: -12, pcbY: -5 }) + const C13 = useCapacitor("C13", { capacitance: "10uF", footprint: "0603", pcbX: -14, pcbY: -5 }) + + // Resistors with footprints and PCB placement + const R1 = useResistor("R1", { resistance: "20k", footprint: "0402", pcbX: -2, pcbY: 1 }) + const R2 = useResistor("R2", { resistance: "0Ω", footprint: "0402", pcbX: -4, pcbY: 10 }) + const R3 = useResistor("R3", { resistance: "499Ω", footprint: "0402", pcbX: 8, pcbY: 8 }) + const R4 = useResistor("R4", { resistance: "2k", footprint: "0402", pcbX: 8, pcbY: -5 }) + + return ( + + {/* Main ESP32 Microcontroller positioned at the center */} + + + {/* Crystal Oscillator close to XTAL pins */} + + + {/* Flash Memory */} + + + {/* PSRAM Memory */} + + + {/* Antenna at the board edge with ground clearance */} + + + {/* Schematic placements and connections */} + {/* ... (Traces and connections mapped from the schematic tutorial) */} + + + + + + {/* Decoupling cap routes */} + + + + {/* RF Trace from ESP32 to Antenna matching network */} + + + ) +} +``` + +--- + +## 📡 Routing RF Traces + +Traces carrying high-frequency RF signals (like the path from `LNA_IN` to `ANT1`) require specialized design parameters: +* **Impedance Matching:** The trace width must be designed to have a characteristic impedance of **50 $\Omega$**. In TSCircuit, you can configure targeted width rules: + ```tsx + + ``` +* **Minimize Vias:** Avoid placing vias on the RF trace to prevent impedance mismatches and signal reflections. Keep the path as straight as possible. + +--- + +## Conclusion + +With the component placement coordinated and board constraints defined, the TSCircuit autorouter automatically routes the signals using a 2-layer stackup. Make sure to compile the design and verify that the copper clearance around `ANT1` is completely empty. diff --git a/static/img/tutorials/arduino_uno_tutorial.png b/static/img/tutorials/arduino_uno_tutorial.png new file mode 100644 index 00000000..f5b0723f Binary files /dev/null and b/static/img/tutorials/arduino_uno_tutorial.png differ diff --git a/static/img/tutorials/esp32_pcb_tutorial.png b/static/img/tutorials/esp32_pcb_tutorial.png new file mode 100644 index 00000000..6beecd38 Binary files /dev/null and b/static/img/tutorials/esp32_pcb_tutorial.png differ diff --git a/static/img/tutorials/led_letter_tutorial.png b/static/img/tutorials/led_letter_tutorial.png new file mode 100644 index 00000000..e57e9d01 Binary files /dev/null and b/static/img/tutorials/led_letter_tutorial.png differ