r/libreELEC

▲ 1.8k r/libreELEC+2 crossposts

Optical audio out with a 1 cents led on RPI5

Yes, this is audio over light from a Raspberry Pi 5 GPIO.

I wrote an experimental Linux driver for the Pi 5 that generates an optical S/PDIF signal on GPIO12 using RP1 PIO + DMA. For this first test, I used a cheap LED placed close to a TOSLINK receiver.

On a bare-metal microcontroller like an STM32 or ESP32, generating a precise bitstream is fairly straightforward. On a Raspberry Pi running Linux, it is harder because the OS is not real-time enough for accurate GPIO bit-banging.

The Raspberry Pi 5 is interesting because it has the RP1 I/O chip with PIO. I use the PIO like a small hardware bitstream engine:

Linux audio -> ALSA driver -> S/PDIF encoder -> DMA -> RP1 PIO -> GPIO12 -> optical receiver

So this is not just blinking an LED. It is a real S/PDIF audio stream generated from a Raspberry Pi 5 GPIO.

Linux sees it as a normal ALSA sound card, so it can be used with CamillaDSP for routing, filters, crossover experiments, and optical output.

Full technical explanation, install notes, GPIO12 wiring, limits, and validation:

https://github.com/RASPIAUDIO/CamillaDSP/blob/main/prototypes/pi5_spdif_gpio/README.md

My mid-term goal is to build an easy-to-set-up open DSP box where the Raspberry Pi 5 is seen by a PC as an 8-channel USB sound card, using USB gadget mode and a USB-C power/data splitter. The same box can then provide S/PDIF output, demonstrated here, plus 8 analog outputs using the four I2S lanes of the Pi 5 and a DAC board.

The use case is DIY active speakers, digital crossovers, FIR/PEQ/delay, and home cinema experiments.

Ongoing project:

https://github.com/RASPIAUDIO/CamillaDSP

u/JUNIORP26 — 4 hours ago