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/i2c-environmental-sensor.mdx b/tutorials/i2c-environmental-sensor.mdx new file mode 100644 index 00000000..a0495436 --- /dev/null +++ b/tutorials/i2c-environmental-sensor.mdx @@ -0,0 +1,118 @@ +# I2C Environmental Sensor Module Tutorial + +## Overview + +Build a BME280-based environmental sensor module that measures temperature, humidity, and pressure over I2C, with an optional OLED display. + +## Components + +| Component | Quantity | Notes | +|-----------|----------|-------| +| BME280 Breakout | 1 | Temperature/Humidity/Pressure | +| SSD1306 OLED 128x64 | 1 | I2C display (optional) | +| 4.7kΩ Resistor | 2 | I2C pull-up | +| 100nF Capacitor | 2 | Decoupling | +| Pin Header (2.54mm) | 1 | 6-pin for external connection | +| 0.96" OLED Module | 1 | I2C, SSD1306 | + +## Schematic + +```typescript +import { createCircuit } from "@tscircuit/core" + +export default function EnvironmentalSensor() { + return ( + + {/* BME280 Sensor */} + + + {/* I2C Pull-ups */} + + + + {/* Decoupling */} + + + + {/* Optional OLED */} + + + {/* Pin header for I2C connection */} + + + ) +} +``` + +## I2C Connection + +| Pin Header | BME280 | OLED | Function | +|---|---|---|---| +| Pin 1 | VIN | VCC | 3.3V/5V Power | +| Pin 2 | GND | GND | Ground | +| Pin 3 | SCK | SCL | I2C Clock (with pull-up) | +| Pin 4 | SDI | SDA | I2C Data (with pull-up) | +| Pin 5 | CSB | - | Chip Select (tie high for I2C) | +| Pin 6 | SDO | - | I2C Address select | + +## Microcontroller Code + +```c +#include +#include +#include + +Adafruit_BME280 bme; +Adafruit_SSD1306 display(128, 64, &Wire, -1); + +void setup() { + Serial.begin(115200); + Wire.begin(); + + if (!bme.begin(0x76)) { + Serial.println("BME280 not found!"); + while (1); + } + + if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { + Serial.println("OLED not found!"); + } + + display.clearDisplay(); + display.setTextSize(1); + display.setTextColor(WHITE); +} + +void loop() { + float temp = bme.readTemperature(); + float humidity = bme.readHumidity(); + float pressure = bme.readPressure() / 100.0F; + + display.clearDisplay(); + display.setCursor(0, 0); + display.print("Temp: "); display.print(temp); display.println(" C"); + display.print("Hum: "); display.print(humidity); display.println(" %"); + display.print("Pres: "); display.print(pressure); display.println(" hPa"); + display.display(); + + delay(2000); +} +``` + +## PCB Layout Tips + +1. Place BME280 away from heat-generating components +2. Add thermal relief pads under the sensor for better air flow +3. Keep I2C traces short and use pull-ups near the sensor +4. Consider adding a ventilation hole above the sensor + +## Calibration + +The BME280 typically needs no calibration for general use. For precise measurements: +- Compare temperature readings against a known reference +- Apply offset correction in software +- For altitude: calibrate pressure against local weather station + +## Estimated Cost + +~$8 in single quantities (BME280 + OLED + passives)