Skip to content

Wiring — current setup (Raspberry Pi 3)

Part What it is
Computer Raspberry Pi 3 B/B+ running the Nerves firmware
Audio HiFiBerry Amp2 stacked on the Pi’s 40-pin header, two speakers
Light controller One ESP32 DevKit, 30-pin (classic ESP32 with a CP2102 USB-C chip — not an ESP32-S3). It is powered from the Pi’s 5 V pin (header pin 2 or 4 → ESP32 VIN) and talks to the Pi over its UART pins (GPIO14/15), both reached under the Amp2
Light 60-LED WS2812B strip on the ESP32’s D13, with its own 5 V supply
Bedside button optional: LoRa module on the Pi’s SPI

There is no second ESP32 and no ESP32-S3 in this build. (The two-ESP32 version is the future board bench.)

Three independent circuits hang on the Pi 3. Build them one at a time and check each before the next: audio, light, bedside button.

Pin numbers are physical pin numbers (not GPIO numbers). The chart is drawn as on a pinout poster: pin 1 at the top, odd pins on the left (the inner row) and even pins on the right (the outer row, nearest the edge of the board). Pin 1 is the square pad, next to the corner of the board closest to the SD slot.

odd pins · inner roweven pins · outer row13V325 V from Amp2, → ESP32 VIN3SDA · Amp245 V from Amp25SCL · Amp26GND → ESP327GPIO48TXD → ESP329GND10RXD ← ESP3211GPIO1712I²S clock · Amp213GPIO2714GND15GPIO2216GPIO23173.3 V → LoRa18GPIO2419MOSI → LoRa20GND21MISO ← LoRa22GPIO2523SCLK → LoRa24CE0 → LoRa25GND → LoRa26GPIO7 CE127ID_SD28ID_SC29GPIO530GND31GPIO632GPIO1233GPIO1334GND35I²S frame · Amp236GPIO1637GPIO2638I²S in · Amp239GND40I²S out · Amp2
Power (+)I²CGroundUARTI²S audio3.3 VSPI
Everything this build uses. The Amp2 takes pins 2/4 (5 V out to the Pi), 3/5 (I²C) and 12/35/38/40 (I²S) by sitting on the header.

Finding the pins when the HAT hides the names

Section titled “Finding the pins when the HAT hides the names”

With the amplifier fitted, the names printed on the Pi are covered. Find a pin by position, not by name:

  1. Turn the board so the SD card slot is on your left and the 40-pin header runs along the top edge.
  2. The header has two rows of 20 pins. The top row (nearest the board edge) is the even pins 2, 4, 6 … 40; the bottom row is the odd pins 1, 3, 5 … 39.
  3. Count from the left end: pin 1 is the first of the bottom row, pin 2 the first of the top row. Pin n is the ⌈n ÷ 2⌉-th pin of its row.
◀ SD card slot sidefar end ▶123456GND → ESP3278TXD → ESP32910RXD ← ESP32111213141516173V3 → LoRa1819MOSI → LoRa2021MISO ← LoRa2223SCLK → LoRa24CE0 → LoRa25GND → LoRa262728293031323334353637383940top row = even pins (outer row, nearest the board edge) · bottom row = odd pins
GroundUART3.3 VSPI
Positions only: this is where to land each wire, whatever is printed on the board.
Pin Row Count from the left Function here
6 top 3rd GND → ESP32
8 top 4th TXD → ESP32 D18
10 top 5th RXD ← ESP32 TX2
17 bottom 9th 3V3 → LoRa
19 bottom 10th MOSI → LoRa
21 bottom 11th MISO ← LoRa
23 bottom 12th SCLK → LoRa
24 top 12th CE0 → LoRa NSS
25 bottom 13th GND → LoRa

Check you are on the right pin with a continuity tester, everything unpowered: pin 6 must beep with pins 9, 14, 20, 25, 30, 34 and 39 (all ground). If it does not, you are one position off, or on the wrong row.

The Amp2 itself needs no wire: it takes the I²C and I²S pins and feeds the Pi with 5 V simply by sitting on the header.

You need: Pi 3 B/B+, HiFiBerry Amp2, a regulated 16.5 V / 2 A supply, two passive 4–8 Ω speakers.

Power supply16.5 V · 2 A regulatedHiFiBerry Amp2on the Pi 3 headerSpeakers2 × passive, 4–8 Ω+ (centre)− (sleeve)V+ INGND INLEFT +LEFT −RIGHT +RIGHT −L +L −R +R −+16.5 VGNDL +L −R +R −Match the +/− markings printed on the Amp2 terminal block.
Power (+)GroundSpeaker
The Amp2 plugs onto the Pi's header and powers the Pi through it: no separate USB power.
  1. Fit the Amp2 on the Pi’s 40-pin header, all 40 pins seated.
  2. Connect both speakers, respecting polarity. Do not join the two “−” wires.
  3. Connect the supply last, then switch it on.
  4. Boot, open the web interface and play a manual test sound at low volume. The card is detected automatically (alsa_device: "auto").

You need: ESP32 DevKit 30-pin (CP2102), a 60-LED WS2812B strip, a separate 5 V supply sized for the strip (up to 3.6 A at full white; the firmware caps the brightness), a 330 Ω resistor, Dupont wires.

Raspberry Pi 3header under the Amp2ESP32 DevKit30-pin · runs pi_lightWS2812B strip60 LED5 V supplystrip onlyGPIO14 TXD · pin 8GPIO15 RXD · pin 10GND · pin 65 V · pin 2D18 (GPIO18) RXTX2 (GPIO17) TXGNDVIN (5 V)D13 (GPIO13)GNDDINGND+5 V+5 VGNDTXD → RXRXD ← TXGND5 V from the Amp2via 330 Ωcommon GNDUART2 · 115 200 baud · 8N1 · 3.3 V logic: straight wires, no level shifter.TX goes to RX and RX to TX: the lines cross.
UARTGroundPower (+)Signal
Two things power the light: the ESP32 from the Pi's 5 V pin (the Amp2 supplies it), the strip from its own 5 V supply. Their grounds are joined.
  1. Join the grounds: Pi GND, ESP32 GND, strip GND and the 5 V supply GND must all meet. Without a common ground the data signal is garbled.
  2. Wire the UART: Pi pin 8 → ESP32 D18, Pi pin 10 ← ESP32 TX2.
  3. Put the 330 Ω resistor in series on the data line, close to the strip’s DIN (the end where the arrows point into the strip).
  4. Feed the strip’s +5V/GND from the 5 V supply, not from the ESP32 or the Pi.
  5. Power the ESP32 from the Pi: header pin 2 (or 4, both are 5 V) → ESP32 VIN. About 50–80 mA, well within what the Amp2 supplies to the Pi. Do not also plug a USB cable into the ESP32 while VIN is wired: two 5 V sources feed into each other. To flash the ESP32 from the Pi’s USB port, unplug the VIN wire first, flash, then put it back and unplug the USB cable.
  6. Check from the web interface: on the evening screen (Soir), start a sunrise or the reading light.

3. Bedside button — LoRa module (SX1276 / RFM95)

Section titled “3. Bedside button — LoRa module (SX1276 / RFM95)”

You need: an RFM95 (or Ra-01H) 868 MHz module, a 868 MHz antenna (a plain wire of about 86 mm works), a 10 kΩ resistor, 100 nF and 10 µF capacitors.

Raspberry Pi 3SPI0 · /dev/spidev0.0RFM95 / SX1276868 MHz · 3.3 V only3V3 · pin 17GND · pin 25GPIO11 SCLK · pin 23GPIO9 MISO · pin 21GPIO10 MOSI · pin 19GPIO8 CE0 · pin 243.3VGNDSCKMISOMOSINSS (CS)RESET · 10 kΩ → 3.3 VDIO0 — not connected3.3 VGNDSCLK → SCKMISO ← MISOMOSI → MOSICE0 → NSSAdd 100 nF + 10 µF between 3.3 V and GND, right at the module.Antenna on the module before any transmission.
3.3 VGroundSPI
3.3 V only. DIO0 stays unconnected: the driver polls the radio every 25 ms.

On power-up the driver reads the module’s version register and expects 0x12. Any other value (loose wire, wrong module) puts the radio in an unavailable state instead of listening with a broken radio. Protocol and pairing: remote button note.

  1. All grounds joined, all wires checked against the figures.
  2. Speakers connected.
  3. Antenna on the LoRa module.
  4. ESP32 VIN wire to the Pi’s 5 V (it is only live once the Amp2 supply is on).
  5. Amp2 supply (this powers the Pi), then the 5 V strip supply.
  6. Never hot-plug the Amp2 supply.
From Pin To Notes
Pi 8 · GPIO14 TXD ESP32 D18 UART, mini UART ttyS0
Pi 10 · GPIO15 RXD ESP32 TX2 UART
Pi 6 · GND ESP32 GND common ground
Pi 2 · 5 V ESP32 VIN power, no USB cable
ESP32 D13 strip DIN via 330 Ω
5 V supply +5 V / GND strip +5V / GND joined to ESP32 GND
Pi 17 · 3V3 LoRa 3.3V + 100 nF, 10 µF
Pi 25 · GND LoRa GND any GND pin works
Pi 23 · SCLK LoRa SCK SPI0
Pi 21 · MISO LoRa MISO SPI0
Pi 19 · MOSI LoRa MOSI SPI0
Pi 24 · CE0 LoRa NSS SPI0 chip select
LoRa RESET 3.3 V via 10 kΩ pull-up