diff --git a/docs/tutorials/pi-hats/class-d-audio-amplifier-hat.mdx b/docs/tutorials/pi-hats/class-d-audio-amplifier-hat.mdx new file mode 100644 index 00000000..038a64cc --- /dev/null +++ b/docs/tutorials/pi-hats/class-d-audio-amplifier-hat.mdx @@ -0,0 +1,106 @@ +--- +title: Class D Audio Amplifier HAT +description: Build a Class D Audio Amplifier HAT with PAM8403 for 3W per channel stereo output. +--- + +## Overview + +This tutorial shows you how to build a Class D Audio Amplifier HAT using the PAM8403 chip, delivering 3W per channel of stereo audio output with volume control and speaker terminals. + +## What You'll Need + +- PAM8403 Class D amplifier chip +- Volume control potentiometer (10k) +- Speaker terminals (2-pin, screw type) +- Input filtering capacitors +- Power supply decoupling capacitors +- 3.5mm audio input jack + +## Circuit Design + +import TscircuitIframe from "@site/src/components/TscircuitIframe" + + { + return ( + + {/* Audio Input Jack */} + + {/* Volume Control */} + + + {/* PAM8403 Amplifier */} + + {/* Output Filter Inductors */} + + + {/* Decoupling Capacitors */} + + + {/* Speaker Terminals */} + + + + ) +} +`} /> + +## Step-by-Step Instructions + +### 1. Audio Input +Place a 3.5mm audio jack at the edge of the board. This accepts stereo line-level input from any audio source. + +### 2. Volume Control +Add dual 10k potentiometers for left and right channel volume control. Wire them as voltage dividers between the audio input and ground. + +### 3. PAM8403 Amplifier +The PAM8403 is a 3W+3W Class D amplifier. Place it centrally with adequate copper pour for heat dissipation. It operates on 5V supply. + +### 4. Output LC Filter +Class D amplifiers require output inductors to filter the PWM switching waveform. Use ferrite bead inductors on each output. + +### 5. Power Supply Decoupling +Add a 100uF bulk capacitor and 1uF ceramic capacitor near the PAM8403 VDD pin to prevent supply ripple. + +### 6. Speaker Terminals +Use screw terminals for speaker connections, supporting 4-8 ohm speakers rated for at least 3W. + +## Specifications + +- **Supply Voltage:** 5V DC +- **Output Power:** 3W per channel (4 ohm load) +- **Efficiency:** >85% (Class D) +- **THD+N:** <0.2% at 1W +- **Frequency Response:** 20Hz - 20kHz + +## Testing + +1. Connect 5V power supply (capable of at least 2A) +2. Connect 4-8 ohm speakers to terminal blocks +3. Feed audio signal via 3.5mm jack +4. Adjust volume potentiometers +5. Verify clean audio output with no audible distortion + +## Safety Notes + +- Do not short speaker outputs +- Use speakers rated for at least 3W +- Keep audio input traces away from output traces to prevent oscillation diff --git a/docs/tutorials/pi-hats/i2c-environmental-sensor-hat.mdx b/docs/tutorials/pi-hats/i2c-environmental-sensor-hat.mdx new file mode 100644 index 00000000..1f153b5f --- /dev/null +++ b/docs/tutorials/pi-hats/i2c-environmental-sensor-hat.mdx @@ -0,0 +1,93 @@ +--- +title: I2C Environmental Sensor Module +description: Build an I2C Environmental Sensor Module with BME280 for temperature, humidity, and pressure readings. +--- + +## Overview + +This tutorial guides you through building an I2C Environmental Sensor Module using the BME280 sensor, capable of measuring temperature, humidity, and atmospheric pressure. An optional OLED display shows real-time readings. + +## What You'll Need + +- BME280 sensor (temperature, humidity, pressure) +- I2C pull-up resistors (4.7k) +- Optional SSD1306 OLED display +- Pin header for external connection +- Decoupling capacitors + +## Circuit Design + +import TscircuitIframe from "@site/src/components/TscircuitIframe" + + { + return ( + + {/* BME280 Environmental Sensor */} + + {/* I2C Pull-up Resistors */} + + + {/* Optional OLED Display */} + + {/* Decoupling Capacitor */} + + + {/* Pin Header */} + + + ) +} +`} /> + +## Step-by-Step Instructions + +### 1. BME280 Sensor Placement +Place the BME280 sensor in an LGA-8 footprint at the center of the board. Ensure adequate airflow around the sensor for accurate readings. + +### 2. I2C Pull-up Resistors +Add 4.7k pull-up resistors on both SDA and SCL lines. These are essential for proper I2C communication. Connect them between the I2C lines and VCC. + +### 3. Power Supply Filtering +Place 100nF and 1uF decoupling capacitors close to the BME280 VDD pin to filter power supply noise. + +### 4. Optional OLED Display +Mount an SSD1306 128x64 OLED display sharing the same I2C bus. It connects to the same SDA/SCL lines with no additional components needed. + +### 5. Pin Header +Add a 6-pin header for external connections: VCC, GND, SDA, SCL, and two spare pins for additional sensors. + +## Software Setup + +```python +# Raspberry Pi I2C Setup +import board +import adafruit_bme280 + +i2c = board.I2C() +sensor = adafruit_bme280.Adafruit_BME280_I2C(i2c) + +print(f"Temperature: {sensor.temperature:.1f} C") +print(f"Humidity: {sensor.humidity:.1f} %") +print(f"Pressure: {sensor.pressure:.1f} hPa") +``` + +## Calibration + +- For accurate altitude readings, calibrate the pressure sensor to your local sea-level pressure +- Allow 5 minutes warm-up time for stable temperature readings +- Avoid placing near heat-generating components + +## Testing + +1. Power on the module (3.3V) +2. Run `i2cdetect -y 1` to verify BME280 at address 0x76 or 0x77 +3. Read sensor values and verify they match ambient conditions +4. If using OLED, verify display shows correct readings diff --git a/docs/tutorials/pi-hats/usb-power-delivery-trigger-hat.mdx b/docs/tutorials/pi-hats/usb-power-delivery-trigger-hat.mdx new file mode 100644 index 00000000..e84a47a4 --- /dev/null +++ b/docs/tutorials/pi-hats/usb-power-delivery-trigger-hat.mdx @@ -0,0 +1,88 @@ +--- +title: USB Power Delivery Trigger HAT +description: Build a USB Power Delivery Trigger HAT with voltage negotiation using the FP28XX/CH224K controller. +--- + +## Overview + +This tutorial walks you through building a USB Power Delivery (PD) Trigger HAT for Raspberry Pi using tscircuit. The HAT negotiates voltages from 5V to 20V via USB PD and provides terminal block outputs with status indication. + +## What You'll Need + +- USB PD controller (FP28XX, CH224K, or PD2001) +- USB-C connector +- Terminal blocks for power output +- Status LEDs +- Filtering capacitors (100uF, 10uF) +- Pull-up/pull-down resistors for PD negotiation + +## Circuit Design + +import TscircuitIframe from "@site/src/components/TscircuitIframe" + + { + return ( + + {/* USB-C Input Connector */} + + {/* USB PD Controller - CH224K */} + + {/* Voltage Select Resistors */} + + + {/* Output Filter Capacitors */} + + + {/* Status LED */} + + + {/* Terminal Block Output */} + + + ) +} +`} /> + +## Step-by-Step Instructions + +### 1. USB-C Input +Place the USB-C connector at one edge of the board. This serves as the power input and PD communication interface. + +### 2. PD Controller +The CH224K USB PD controller handles voltage negotiation. Connect CC1/CC2 lines from the USB-C connector to the controller for PD communication. + +### 3. Voltage Selection +Configure the desired output voltage (5V, 9V, 12V, 15V, or 20V) using pull-down resistors on the CFG pins: +- **5V:** CFG1=Low, CFG2=Low, CFG3=Low +- **9V:** CFG1=High, CFG2=Low, CFG3=Low +- **12V:** CFG1=Low, CFG2=High, CFG3=Low +- **15V:** CFG1=High, CFG2=High, CFG3=Low +- **20V:** CFG1=Low, CFG2=Low, CFG3=High + +### 4. Output Filtering +Add bulk (100uF) and decoupling (10uF) capacitors on the output to reduce voltage ripple. + +### 5. Status LED +Add a green LED with a 1k current-limiting resistor to indicate when power is active. + +### 6. Terminal Block Output +Use a 2-pin screw terminal for the regulated output, making it easy to connect external devices. + +## Testing + +1. Connect a USB-C PD power supply to the input +2. Verify the negotiated voltage on the terminal block with a multimeter +3. Check the status LED illuminates +4. Measure output ripple under load (should be <100mV) + +## Safety Notes + +- Ensure adequate trace width for higher currents (use 2oz copper for 20V/3A) +- Add a polyfuse on the output for overcurrent protection +- Keep PD communication traces short and away from high-current paths diff --git a/tutorials/usb-power-delivery-hat.mdx b/tutorials/usb-power-delivery-hat.mdx new file mode 100644 index 00000000..06def86b --- /dev/null +++ b/tutorials/usb-power-delivery-hat.mdx @@ -0,0 +1,130 @@ +# USB Power Delivery Trigger HAT Tutorial + +## Overview + +In this tutorial, we'll build a USB Power Delivery (PD) Trigger HAT that can negotiate voltages from 5V to 20V from any USB PD power supply. This is useful for powering custom electronics projects with modern USB-C chargers. + +## Components Needed + +| Component | Quantity | Notes | +|-----------|----------|-------| +| CH224K USB PD Controller | 1 | or FP2844S | +| USB-C Receptacle (16-pin) | 1 | Through-hole | +| 100nF Ceramic Capacitor (0805) | 4 | Decoupling | +| 10µF Ceramic Capacitor (0805) | 2 | Bulk filtering | +| 100µF Electrolytic (16V+) | 1 | Output filter | +| 5mm Terminal Block | 1 | 2-pin output | +| 3mm LED | 1 | Status indicator | +| 1kΩ Resistor (0805) | 1 | LED current limit | +| 10kΩ Resistor (0805) | 3 | PD config pull-down | +| Tactile Switch | 3 | Voltage select | + +## Schematic Design + +### Step 1: USB-C Input + +Place the USB-C receptacle and connect: + +``` +USB-C Pin -> CH224K Pin +--- --- +CC1 (A5) -> CC1 (Pin 1) +CC2 (B5) -> CC2 (Pin 2) +VBUS (A4/B4) -> VIN (Pin 3) +GND (A1/B1) -> GND +``` + +### Step 2: PD Controller Circuit + +The CH224K handles PD negotiation automatically: + +```typescript +// tscircuit schematic +import { createCircuit } from "@tscircuit/core" + +export default function USBPDHat() { + return ( + + {/* USB-C Input */} + + + {/* PD Controller */} + + + {/* Decoupling capacitors */} + + + + + + {/* Voltage selection resistors */} + + + + {/* Status LED */} + + + + {/* Output terminal block */} + + + {/* Voltage select buttons */} +