Pi5Pixel.WS2812 0.2.5

dotnet add package Pi5Pixel.WS2812 --version 0.2.5
                    
NuGet\Install-Package Pi5Pixel.WS2812 -Version 0.2.5
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Pi5Pixel.WS2812" Version="0.2.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Pi5Pixel.WS2812" Version="0.2.5" />
                    
Directory.Packages.props
<PackageReference Include="Pi5Pixel.WS2812" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Pi5Pixel.WS2812 --version 0.2.5
                    
#r "nuget: Pi5Pixel.WS2812, 0.2.5"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Pi5Pixel.WS2812@0.2.5
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Pi5Pixel.WS2812&version=0.2.5
                    
Install as a Cake Addin
#tool nuget:?package=Pi5Pixel.WS2812&version=0.2.5
                    
Install as a Cake Tool

WS2812 LED Strip Controller for Raspberry Pi 5

Since I did not find any library or NuGet package to control the WS2812 with C# and .NET, I made this.

Acknowledgements

This project was inspired by niklasr22 and his work on rpi5-ws2812. Thanks for providing the foundational code that made this C# adaptation possible.

Wiring

Important: While it's possible to power the LED strip directly from the Raspberry Pi, it's not recommended for longer strips or higher brightness settings. Using an external power supply ensures stable operation and prevents potential damage to your Pi or your LED strip.

Required Components

  • Raspberry Pi 5
  • WS2812 LED Strip
  • Jumper Wires or Soldering Iron
  • Optional: External 5V Power Supply

Connection Instructions

  • Power Connections
    • Positive (5V)
      • Raspberry Pi Pin 2 or Pin 4
      • Note: For longer strips, consider using an external 5V power supply connected to the additional power wires on the LED strip.
    • Ground (GND)
      • Raspberry Pi Pin 6, 9, 14, 25, 30, 34, or 39
    • Data Connection
      • Data In
        • Connect to Raspberry Pi MOSI (Pin 19 / GPIO 10)
    • LED Strip Wires
      • Outer Wires
        • Red: 5V Power
        • White: Ground
      • Middle Wire
        • Green: Data

Configure your Raspberry Pi

Enable SPI in the Raspberry Pi config with sudo raspi-config

Installation

dotnet add package Pi5Pixel.WS2812

Usage

var driver = new WS2812Driver(bus, device, ledCount); // Initialize with bus = 0 and device = 0

var strip = driver.GetStrip();

strip.SetAllPixels(255, 255, 255); // Perform your effect

strip.Show(); // Changes are only visible after calling strip.Show();

Caution

Disclaimer: I am not an expert in electronics, Raspberry Pi hardware, SPI or WS2812 hardware and protocol. While I have taken care to ensure the accuracy of the information and instructions provided in this repository, mistakes can still occur. Proceed with caution and at your own risk.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.5 222 2/16/2025
0.2.2 212 2/16/2025
0.1.0 163 2/10/2025
0.0.3 187 1/1/2025
0.0.2 182 1/1/2025
0.0.1 179 1/1/2025