diff --git a/docs/tutorials/class-d-audio-amplifier-hat.mdx b/docs/tutorials/class-d-audio-amplifier-hat.mdx new file mode 100644 index 00000000..77beee55 --- /dev/null +++ b/docs/tutorials/class-d-audio-amplifier-hat.mdx @@ -0,0 +1,185 @@ +--- +title: Class D Audio Amplifier HAT +description: Learn how to build a 3W stereo Class D audio amplifier HAT using the PAM8403 amplifier chip, speaker terminals, and volume control with tscircuit. +--- + +## Overview + +In this tutorial, we will build a **Class D Audio Amplifier HAT**. This board takes stereo line-level audio input and amplifies it to drive two 3W speakers (Left and Right channels) with excellent efficiency and minimal heat output. + +Unlike traditional analog amplifiers (such as Class A or AB) which dissipate excess power as heat, **Class D amplifiers** work by converting the analog input into a high-frequency PWM (Pulse Width Modulation) signal. The output MOSFETs switch fully ON or fully OFF rapidly, leading to efficiencies up to 90%, making them perfect for battery-powered or compact projects like Raspberry Pi audio HATs. + +We will use the **PAM8403** Class D amplifier chip, which is a filterless 3W stereo amplifier requiring minimal external components. + +--- + +## ๐Ÿ“‹ Components Checklist + +Our amplifier HAT will consist of: +1. **PAM8403 Class D Amplifier (U1)** โ€” 3W stereo audio amplifier in an SOP-16 package. +2. **Dual-Gang 10kฮฉ Potentiometer (RV1)** โ€” Standard stereo volume control dial. +3. **2x 2-pin Screw Terminals (J1, J2)** โ€” Speaker output blocks for Left and Right speakers. +4. **40-pin Raspberry Pi Header (J3)** โ€” Pi HAT connector for power (5V) and audio line signals. +5. **Bulk Decoupling Capacitor (C1)** โ€” 470ยตF electrolytic capacitor to buffer high-current speaker transients. +6. **Filtering Capacitors (C2, C3, C4, C5)** โ€” Small ceramic capacitors (0.1ยตF to 1ยตF) to filter power supply noise and input signals. + +--- + +## ๐Ÿ› ๏ธ Step-by-Step Implementation + +Create a new file in your project or editor and paste the following tscircuit design code. + +### Complete Circuit Code + +import TscircuitIframe from "@site/src/components/TscircuitIframe" + + { + return ( + + {/* 40-pin Raspberry Pi Hat Header */} + + + {/* PAM8403 Class D Amplifier */} + + + {/* 10k Dual-Gang Potentiometer for volume control */} + + + {/* Speaker Output Screw Terminals */} + + + + {/* Input Coupling Capacitors */} + + + + {/* Decoupling & Bypass Capacitors */} + + + + + {/* Connections */} + {/* Power Rails (5V & GND) */} + + + + {/* PAM8403 Power Pin connections */} + {/* PVDD_L */} + {/* PVDD_R */} + {/* VDD */} + {/* MUTE disabled (pulled high) */} + {/* SHDN disabled (pulled high) */} + + {/* PGND_L */} + {/* PGND_R */} + + {/* Power Filtering Caps */} + + + + + + {/* Bypass Reference Capacitor */} + + + + {/* Audio Input Left Connection */} + + + + {/* IN_L */} + + {/* Audio Input Right Connection */} + + + + {/* IN_R */} + + {/* Left Speaker Output */} + + + + {/* Right Speaker Output */} + + + + ) +} +`} /> + +--- + +## ๐Ÿ”Š Important Audio Circuit Design Notes + +1. **Input Coupling Capacitors (C4, C5)**: + - These DC-blocking input capacitors are absolutely critical. They block any DC bias voltage from the host audio source while allowing the AC audio waveform to pass into the PAM8403 input pins. +2. **Bulk Capacitance (C1)**: + - Class D amplifiers switch high currents to drive speakers. A large bulk decoupling capacitor (like the 470ยตF **C1**) must be placed as close to the power pins as possible to handle sudden current draws and prevent power sag. +3. **Filterless Design**: + - The PAM8403 uses a filterless modulation architecture. The inductance of the speaker coils acts as a low-pass filter to recover the audio signal from the PWM carrier, meaning you do not need bulky LC filters at the speaker outputs for short wire lengths. diff --git a/docs/tutorials/i2c-environmental-sensor.mdx b/docs/tutorials/i2c-environmental-sensor.mdx new file mode 100644 index 00000000..3e1313b8 --- /dev/null +++ b/docs/tutorials/i2c-environmental-sensor.mdx @@ -0,0 +1,146 @@ +--- +title: I2C Environmental Sensor Module +description: Learn how to design a compact environmental monitoring module with a BME280 sensor, SSD1306 OLED display, and I2C bus pull-ups using tscircuit. +--- + +## Overview + +In this tutorial, we will build a compact **I2C Environmental Sensor Module**. This board is designed to measure ambient temperature, relative humidity, and barometric pressure, and display the live readings on a local OLED screen. + +We will use **I2C (Inter-Integrated Circuit)**, which is a popular serial communication protocol that allows multiple slave devices (the BME280 sensor and SSD1306 OLED) to communicate with a single master host using only two signal wires: +- **SDA** (Serial Data) +- **SCL** (Serial Clock) + +--- + +## ๐Ÿ“‹ Components Checklist + +Our module will consist of: +1. **BME280 Environmental Sensor (U1)** โ€” Digital sensor for temperature, humidity, and pressure in an LGA-8 package. +2. **SSD1306 OLED Display (U2)** โ€” Standard 0.96-inch 128x64 I2C display panel. +3. **I2C Pull-Up Resistors (R1, R2)** โ€” 4.7kฮฉ resistors to pull the SDA and SCL signal lines high. +4. **Decoupling Capacitors (C1, C2)** โ€” 0.1ยตF capacitors to stabilize power supply inputs. +5. **4-pin Male Header (J1)** โ€” Connecting interface for power (VCC/GND) and communication (SDA/SCL) to a host microcontroller. + +--- + +## ๐Ÿ› ๏ธ Step-by-Step Implementation + +Create a new file in your project or editor and paste the following tscircuit design code. + +### Complete Circuit Code + +import TscircuitIframe from "@site/src/components/TscircuitIframe" + + { + return ( + + {/* 4-pin Host Connection Header */} + + + {/* BME280 Sensor */} + + + {/* SSD1306 128x64 OLED Display (I2C interface) */} + + + {/* I2C Pull-Up Resistors */} + + + + {/* Decoupling Capacitors */} + + + + {/* Connections */} + {/* Power Rail (VCC / GND) */} + + + + {/* BME280 Power */} + {/* VDD */} + {/* VDDIO */} + {/* CSB high enables I2C mode */} + {/* SDO to GND selects address 0x76 */} + + + + {/* OLED Power */} + + + + {/* Decoupling Caps */} + + + + + + {/* SCL Bus */} + + + + + {/* SDA Bus */} + + + + + {/* I2C Pull-Up Connections */} + + + + + + + ) +} +`} /> + +--- + +## ๐Ÿ’ก Crucial Hardware Design Notes + +1. **CSB & SDO Configuration**: + - The BME280 requires the **CSB (Chip Select Bar)** pin to be pulled to **VCC** to enable the **I2C communication interface** (pulling it low selects SPI mode). + - **SDO** is the address select pin. Connecting it to GND sets the 7-bit slave address to `0x76`. Connecting it to VCC sets it to `0x77`. +2. **I2C Bus Pull-Ups**: + - The I2C protocol uses open-drain/open-collector outputs. This means the lines can only pull down to GND; they cannot pull high themselves. + - External pull-up resistors (like **R1** and **R2**) are mandatory to pull SCL and SDA lines up to VCC. Without these, the signals will stay low and the bus will not function. diff --git a/docs/tutorials/usb-pd-trigger-hat.mdx b/docs/tutorials/usb-pd-trigger-hat.mdx new file mode 100644 index 00000000..d8faae55 --- /dev/null +++ b/docs/tutorials/usb-pd-trigger-hat.mdx @@ -0,0 +1,168 @@ +--- +title: USB Power Delivery Trigger HAT +description: Design and build a USB Power Delivery Trigger HAT using tscircuit to negotiate voltages from 5V to 20V from a USB-PD power source. +--- + +## Overview + +In this tutorial, we will build a **USB Power Delivery (PD) Trigger HAT**. This board negotiates voltages (5V, 9V, 12V, 15V, or 20V) from any standard USB PD charger or battery pack and routes that power to a high-current terminal block. + +This board is extremely useful for powering hobbyist projects, single-board computers, or DC motors directly from a USB-PD wall adapter. + +We will use the **CH224K** USB PD sink controller, which handles the CC (Configuration Channel) negotiation protocol automatically without requiring a microcontroller. + +--- + +## ๐Ÿ“‹ Components Checklist + +Our circuit will consist of: +1. **CH224K PD Controller (U1)** โ€” Low-cost USB PD sink chip in an ESSOP-10 package. +2. **USB Type-C Female Port (J1)** โ€” Input receptacle for USB-PD source. +3. **DIP Switch (SW1)** โ€” 3-position switch to select the requested voltage. +4. **2-pin Screw Terminal (J2)** โ€” High-current output terminal for external devices. +5. **Decoupling Capacitors (C1, C2)** โ€” Filtering capacitors to stabilize VBUS and internal VDD. +6. **LED Indicator (D1) & Current Limiting Resistor (R1)** โ€” Visual feedback for power output. + +--- + +## ๐Ÿ› ๏ธ Step-by-Step Implementation + +Create a new file in your project or editor and paste the following tscircuit design code. + +### Complete Circuit Code + +import TscircuitIframe from "@site/src/components/TscircuitIframe" + + { + return ( + + {/* USB-C Input Port */} + + + {/* CH224K USB-PD Controller */} + + + {/* DIP Switch for Configuration */} + + + {/* Output Terminal Block */} + + + {/* Status LED & Resistor */} + + + + {/* Decoupling Capacitors */} + + + + {/* Connections */} + {/* Power Rails */} + + + + + + + {/* CC Line Negotiation */} + + + + {/* VDD Internal LDO Capacitor */} + + + + {/* Input Filtering */} + + + + {/* Output Connections */} + + + + {/* DIP Switch CC Configuration */} + + + + + + + + + {/* LED Indicator Connection */} + + + + + ) +} +`} /> + +--- + +## โšก How the Voltage Negotiation Works + +The CH224K chip negotiates voltages based on the state of the configuration pins (**CFG1**, **CFG2**, and **CFG3**). By toggling the DIP switch, you pull these pins to GND (LOW) or leave them floating (HIGH). + +| CFG1 | CFG2 | CFG3 | Negotiated Voltage | +| :---: | :---: | :---: | :--- | +| Floating | GND | Floating | **5V** (Default USB voltage) | +| GND | GND | Floating | **9V** | +| Floating | Floating | GND | **12V** | +| GND | Floating | GND | **15V** | +| GND | Floating | Floating | **20V** |