From 2099e48be384e2405bb109c7a6d046cc0ff1860b Mon Sep 17 00:00:00 2001 From: baeltaezaer Date: Sun, 5 Jul 2026 15:32:13 -0600 Subject: [PATCH] docs: add class d audio amplifier hat tutorial --- .../pi-hats/class-d-audio-amplifier-hat.mdx | 415 ++++++++++++++++++ 1 file changed, 415 insertions(+) create mode 100644 docs/tutorials/pi-hats/class-d-audio-amplifier-hat.mdx 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..df3062a3 --- /dev/null +++ b/docs/tutorials/pi-hats/class-d-audio-amplifier-hat.mdx @@ -0,0 +1,415 @@ +--- +title: Building a Class D Audio Amplifier HAT +description: >- + This tutorial walks through building a Raspberry Pi HAT around a PAM8403 + class D amplifier, with volume control, speaker terminals, and Raspberry Pi + integration notes. +--- + +## Overview + +This tutorial shows how to build a compact stereo audio HAT for a Raspberry Pi +using a PAM8403-style class D amplifier. The design includes: + +- stereo line-level input +- a simple volume control path +- two speaker terminals +- decoupling and shutdown wiring for a stable 5V board + +import CircuitPreview from "@site/src/components/CircuitPreview" + +```mermaid +flowchart LR + Pi["Raspberry Pi header"] -->|5V + GND| Amp["PAM8403 amp"] + Source["Audio source"] --> Pots["Volume control"] + Pots --> Amp + Amp --> Left["Left speaker terminal"] + Amp --> Right["Right speaker terminal"] +``` + +## Why Class D? + +Class D amplifiers are efficient because their output stage switches rapidly +rather than running in a linear mode. For a small HAT, that matters: + +- less heat +- better battery-friendly behavior +- easy 5V power from the Pi header +- plenty of power for small speakers + +The PAM8403 class is a good fit for compact stereo builds because it is small, +cheap, and practical for short speaker runs. + +## Circuit Requirements + +For this tutorial, the HAT needs to: + +- accept stereo line input +- provide volume control before amplification +- drive left and right speakers from separate outputs +- stay powered from the Raspberry Pi 5V rail + +## Step 1: Place the HAT and amplifier + +We start with the Raspberry Pi HAT board and the amplifier core. + + ( + + + + + + + +`}/> + +## Step 2: Add input connectors and volume control + +The input side is intentionally simple. Each stereo channel gets its own +potentiometer so both channels stay balanced. + + ( + + + + + + + + + + + + + + + + + + + + + + +`}/> + +## Step 3: Add speaker terminals + +The amplifier outputs are routed to separate left and right speaker terminals. +Keep these traces short and away from the input path. + + ( + + + + + + + + + + + + + + + + +`}/> + +## Step 4: Add decoupling + +Class D stages are sensitive to supply noise. A small bulk capacitor plus a +small ceramic capacitor near the amplifier helps keep the rail stable. + + ( + + + + + + + + + + + + + + +`}/> + +## Step 5: Place the PCB + +For a HAT, aim to keep the board within the standard footprint and place the +speaker connectors near the edge. The amplifier should sit close to the +terminal outputs, and the input path should stay on the opposite side. + + ( + + + + + + + + + + + + + + +`}/> + +## Raspberry Pi integration + +The HAT itself is just the amplifier and support parts. In practice you will +feed it from a line-level audio source: + +- a Raspberry Pi with audio enabled +- a small external DAC +- a USB audio adapter + +Once the Pi is outputting audio, wire the left and right channels into the +input connector and set the volume with the potentiometers on the HAT. + +On Raspberry Pi OS, the usual setup is: + +1. pick the correct audio output in system settings +2. set a sensible mixer level in `alsamixer` +3. keep the master volume near the middle before tuning the hardware pots + +If you are using a DAC add-on instead of onboard audio, configure that device +first, then feed its line output into `J_IN`. + +## Audio configuration guide + +For a clean first power-up: + +1. start with the volume pots turned down +2. power the HAT from a current-limited bench supply or the Pi itself +3. verify that `VDD` is close to 5V +4. confirm that the amplifier stays enabled through `SHDN` +5. connect a small speaker first, then raise the volume slowly + +If you hear distortion early, reduce the gain or lower the source level before +touching the hardware wiring. + +## Ordering the PCB + +After the schematic and layout look right, generate fabrication files and send +them to your PCB house of choice. A 5V class D HAT is a good candidate for a +small two-layer board with short, direct speaker routes. + +## Next steps + +- add reverse-polarity protection on the 5V input +- add a mute switch to the shutdown line +- add mounting holes aligned to the HAT outline +- add a silkscreen legend for the speaker terminals