ws281x.Net 1.0.6

dotnet add package ws281x.Net --version 1.0.6                
NuGet\Install-Package ws281x.Net -Version 1.0.6                
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="ws281x.Net" Version="1.0.6" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ws281x.Net --version 1.0.6                
#r "nuget: ws281x.Net, 1.0.6"                
#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.
// Install ws281x.Net as a Cake Addin
#addin nuget:?package=ws281x.Net&version=1.0.6

// Install ws281x.Net as a Cake Tool
#tool nuget:?package=ws281x.Net&version=1.0.6                

ws281x.Net

AppVeyor NuGet

A .Net Standard 2.0 wrapper for the rpi_ws281x library for controlling WS281X LEDs on a Raspberry Pi. This library has been tested on a Raspberry Pi 3 B+.

Usage

This library adapts to the python wrapper of rpi_ws281x. The API is almost the same.

// Initialize a new instance of the wrapper
var neopixel = new ws281x.Net.Neopixel(ledCount: 42, pin: 18);

// You can also choose a custom color order
neopixel = new ws281x.Net.Neopixel(ledCount: 42, pin: 18, stripType: rpi_ws281x.WS2811_STRIP_RBG);

// Always initialize the wrapper first
neopixel.Begin();

// Set color of all LEDs to red
for (var i = 0; i < neopixel.GetNumberOfPixels(); i++)
{
    neopixel.SetPixelColor(i, System.Drawing.Color.Red);
}

// Apply changes to the led
neopixel.Show();

// Dispose after use
neopixel.Dispose();

The application has to be run in sudo mode to be able to access the GPIO pins.

Installation

As this is just a wrapper for a native library you have to put the native binary into the lib order of your Raspberry Pi (which should be /usr/local/lib in most cases).

Prebuild binary

Take the prebuild binary from src/ws281x.Net/Native/librpi_ws281x.so and copy it to the library path of your Pi.

Afterwards make sure to update the library links:

sudo ldconfig

Compile by yourself

Make sure gcc is installed on your Pi.

sudo apt-get install -y gcc

Copy all files from src/ws281x.Net/Native to a temporary build folder on your pi.

Compile the sources first:

gcc -c -fpic ws2811.c rpi_ws281x_wrap.c

Then link them to a library

gcc -shared ws2811.o rpi_ws281x_wrap.o -o librpi_ws281x.so

Copy the output library librpi_ws281x.so to your lib folder. Afterwards make sure to update the library links:

sudo ldconfig

Troubleshooting

ws2811_init failed with code -5 (mmap() failed)

Make sure you started your program is started with sudo. Afterwards check the connections to your LED strip.

Library rpi_ws281x is not found

This is the most annoying error as debugging is quite difficult. Ensure you placed the native library at the right place (usually /usr/local/lib), it is named librpi_ws281x.so and run sudo ldconfig to update the library links.

Projects

This projects are using ws281x.Net:

If you want your project to be added to this list just create an issue.

Building this library

The native interface is generated by swig. The wrapper classes are already created. If you change one of the native libraries or the wrapper interface rpi_ws281x.i you have to run swig -csharp rpi_ws281x.i and then copy the output C# classes to the Types folder. Afterwards, a normal compile will do the job.

dotnet build -c Release
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

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
1.0.6 1,366 9/8/2018
1.0.4 708 9/8/2018