Skip to content

Conversation

Copy link

Copilot AI commented Sep 12, 2025

This PR adds comprehensive SPI DAC support to the CircuitPython Synthio Tutorial, providing an alternative to I2S DACs for audio output with synthio. This addresses scenarios where users want to use SPI-based Digital-to-Analog Converters instead of the standard I2S options.

New Features

Core SPI DAC Module

  • audiobusio_spi.py - Main implementation providing SPIOut class that mimics the audiobusio.I2SOut interface
  • Drop-in replacement for I2S audio output with the same API
  • Supports configurable sample rates, channel counts, and bit depths

Multiple DAC Chip Support

  • MCP4922 - 12-bit dual channel DAC (recommended)
  • MCP4912 - 10-bit dual channel DAC
  • TLV5618 - 12-bit dual channel DAC
  • Extensible architecture for adding additional SPI DAC chips

Hardware Features

  • LDAC pin support for simultaneous stereo channel updates
  • Configurable SPI communication parameters
  • Proper chip select and timing management
  • Output filtering recommendations

Example Usage

import board
import busio
from audiobusio_spi import SPIOut, DAC_MCP4922

# Initialize SPI bus
spi = busio.SPI(clock=board.GP18, MOSI=board.GP19)

# Create SPI DAC audio output
audio = SPIOut(spi=spi, 
               cs=board.GP20, 
               dac_type=DAC_MCP4922,
               sample_rate=22050,
               channel_count=2,
               ldac=board.GP21)

# Use with synthio just like I2S
mixer.play(audio)

Files Added

  • audiobusio_spi.py - Core SPI DAC implementation
  • synth_setup_spi.py - SPI DAC version of synth setup
  • code_helloboop_spi.py - "Hello world" example using SPI DAC
  • code_spi_dac_demo.py - Interactive demo with controls
  • test_spi_dac.py - Functionality test script
  • README-SPI-DAC.md - Comprehensive documentation (174 lines)

Benefits

  • Hardware flexibility - Use common, inexpensive SPI DAC chips
  • Educational value - Demonstrates SPI communication and audio processing
  • Cost effective - SPI DACs often cheaper than I2S modules
  • Compatibility - Works with existing synthio tutorial structure
  • Performance - Optimized SPI protocols for audio applications

Documentation

The implementation includes comprehensive documentation covering:

  • Hardware setup and wiring diagrams
  • Supported DAC chips and specifications
  • Performance considerations and optimization tips
  • Troubleshooting guide
  • Instructions for adding new DAC chip support

This addition expands the tutorial's hardware compatibility while maintaining the same learning progression and code structure.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@todbot todbot closed this Sep 12, 2025
Copilot AI changed the title [WIP] How to add a audiobusio SPI DAC as a new core module to the CircuitPython codebase? Add SPI DAC support as audiobusio core module alternative for synthio Sep 12, 2025
Copilot AI requested a review from todbot September 12, 2025 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants