examples/SpecialDrivers/Adafruit/SAMD_SingleSPI/README.md
This example demonstrates using FastLED with SPI-based LED chipsets on SAMD21 and SAMD51 platforms.
| Platform | MCU | Speed | RAM | Flash | Board Examples |
|---|---|---|---|---|---|
| SAMD21 | Cortex-M0+ | 48 MHz | 32 KB | 256 KB | Arduino Zero, Adafruit Feather M0 |
| SAMD51 | Cortex-M4F | 120 MHz | 192 KB | 512 KB | Adafruit Feather M4, Grand Central M4 |
This example works with SPI-based LED chipsets that require both DATA and CLOCK signals:
LED Strip SAMD Board
───────── ──────────
DATA ────────> MOSI pin (see pin table below)
CLOCK ────────> SCK pin (see pin table below)
GND ────────> GND
VCC ────────> External 5V power supply (do NOT use board 5V for strips!)
⚠️ Important Power Notes:
| Board | MOSI (DATA) | SCK (CLOCK) | SERCOM Unit |
|---|---|---|---|
| Arduino Zero | Pin 11 (ICSP) | Pin 13 (ICSP) | SERCOM1 |
| Adafruit Feather M0 | Pin 23 | Pin 24 | SERCOM4 |
| Adafruit Feather M4 | Pin 23 | Pin 24 | SERCOM1 |
| Adafruit Grand Central M4 | Pin 51 (ICSP) | Pin 52 (ICSP) | SERCOM2 |
Note: These pins are automatically configured by the example sketch based on the detected board.
In the sketch, uncomment the line matching your LED chipset:
// Default: APA102 (DotStar)
FastLED.addLeds<APA102, DATA_PIN, CLOCK_PIN, BGR>(leds, NUM_LEDS);
// Or choose another:
// FastLED.addLeds<SK9822, DATA_PIN, CLOCK_PIN, BGR>(leds, NUM_LEDS);
// FastLED.addLeds<LPD8806, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<P9813, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
Set NUM_LEDS to match your strip:
#define NUM_LEDS 30 // Change to your actual LED count
Some LED strips have different color orderings. Try these if colors are wrong:
RGB - Red, Green, BlueBGR - Blue, Green, Red (common for APA102/SK9822)GRB - Green, Red, BlueRBG, BRG, GBR - Other orderings# Using PlatformIO
pio run -e adafruit_feather_m4 -t upload
# Or using FastLED build system
uv run ci/ci-compile.py adafruit_feather_m4 --examples SpecialDrivers/Adafruit/SAMD_SingleSPI
Open serial monitor at 115200 baud to see:
| Platform | Typical FPS | Notes |
|---|---|---|
| SAMD51 | ~250 FPS | @ 30 LEDs, 120 MHz CPU |
| SAMD21 | ~150 FPS | @ 30 LEDs, 48 MHz CPU |
Performance scales with LED count. More LEDs = lower FPS.
This example uses FastLED's standard single-SPI backend (SAMDHardwareSPIOutput class) which leverages the Arduino SPI library:
::SPI.begin() from Arduino coreSPI.beginTransaction() / SPI.transfer() / SPI.endTransaction()FastLED includes infrastructure for Dual-SPI and Quad-SPI on SAMD platforms:
Files:
src/platforms/arm/d21/spi_hw_2_samd21.cpp - SAMD21 Dual-SPI driversrc/platforms/arm/d51/spi_hw_2_samd51.cpp - SAMD51 Dual-SPI driver (SERCOM-based)src/platforms/arm/d51/spi_hw_4_samd51.cpp - SAMD51 Quad-SPI driver (QSPI peripheral)src/platforms/arm/sam/spi_device_proxy.h - Device proxy for bus manager integrationStatus:
Recommendation: Use single-SPI mode (this example) for production applications. Parallel SPI infrastructure is experimental and requires hardware validation.
addLeds() call (RGB, BGR, GRB, etc.)NUM_LEDS for testingdelay(20) in loop()SAMD platforms use SERCOM peripherals (Serial Communication) that can be configured as:
Each board has a default SPI instance connected to specific pins. This example uses the board's default hardware SPI pins for maximum compatibility.
The SPI clock speed is automatically configured by FastLED based on the LED chipset:
SAMD platforms support:
In practice, LED chipset limits are the bottleneck, not the MCU.
Potential improvements for SAMD parallel SPI implementation:
These enhancements require hardware testing and validation before production use.
This example is part of the FastLED library and is released under the same license.
Found a bug or have an improvement? Please submit an issue or pull request to the FastLED repository.