Home

Awesome

THIS REPORT HAS BEEN ARCHIVED

Build status

<img src="https://raw.githubusercontent.com/unosquare/wiringpi-dotnet/master/logos/raspberryio-logo-32.png" alt="wiringpi-dotnet" style="width:16px; height:16px" /> wiringpi-dotnet

:star: Please star this project if you find it useful!

Provides complete managed access to the popular wiringpi C library

The default low-level provider is the wonderful WiringPi library available here. You do not need to install this library yourself. The Unosquare.WiringPi assembly will automatically extract the compiled binary of the library in the same path as the entry assembly.

Installation

Install basic Raspberry.IO package: NuGet version

PM> Install-Package Unosquare.Raspberry.IO

Install WiringPi implementation: NuGet version

PM> Install-Package Unosquare.WiringPi

Obtaining Board and System Information

RaspberryIO contains useful utilities to obtain information about the board it is running on. You can simply call the Pi.Info.ToString() method to obtain a dump of all system properties as a single string, or you can use the individual properties such as Installed RAM, Processor Count, Raspberry Pi Version, Serial Number, etc. There's not a lot more to this.

Please note Pi.Info depends on Wiring Pi, and the /proc/cpuinfo and /proc/meminfo files.

Using the GPIO Pins

Pin reference for the B plus (B+) - Header P1

BCMNameModeVLRVModeNameBCM
3.3v01025v
2SDA.1ALT0103045V
3SCL.1ALT010506GND
4GPIO. 7IN107081ALT0TxD14
GND09101ALT0RxD15
17GPIO. 0IN011120INGPIO. 118
27GPIO. 2IN01314GND
22GPIO. 3IN015160INGPIO. 423
3.3v17180INGPIO. 524
10MOSIIN01920GND
9MISOIN021220INGPIO. 625
11SCLKIN023241INCE08
GND25261INCE17
0SDA.0IN127281INSCL.01
5GPIO.21IN12930GND
6GPIO.22IN131320INGPIO.2612
13GPIO.23IN03334GND
19GPIO.24IN035360INGPIO.2716
26GPIO.25IN037380INGPIO.2820
GND39400INGPIO.2921

The above diagram shows the pins of GPIO Header P1. There is an additional GPIO header on the Pi called P5. More info available here

In order to access the pins, use Pi.Gpio. The pins can have multiple behaviors and fortunately Pi.Gpio can be iterated, addressed by index, addressed by BCM pin number and provides the pins as publicly accessible properties.

Here is an example of addressing the pins in all the various ways:

public static void TestLedBlinking()
{
    // Get a reference to the pin you need to use.
    // All 3 methods below are exactly equivalent
    var blinkingPin = Pi.Gpio[17];
    blinkingPin = Pi.Gpio[BcmPin.Gpio17];
    blinkingPin = Pi.Gpio.Pin17;

    // Configure the pin as an output
    blinkingPin.PinMode = GpioPinDriveMode.Output;

    // perform writes to the pin by toggling the isOn variable
    var isOn = false;
    for (var i = 0; i < 20; i++)
    {
        isOn = !isOn;
        blinkingPin.Write(isOn);
        System.Threading.Thread.Sleep(500);
    }
}

Related Projects and Nugets

NameAuthorDescription
RaspberryIOUnosquareThe Raspberry Pi's IO Functionality in an easy-to-use API for .NET (Mono/.NET Core).
PiGpio.netUnosquareProvides complete managed access to the popular pigpio C library
Raspberry AbstractionsUnosquareAllows you to implement your own provider for RaspberryIO.
Raspberry# IOraspberry-sharpRaspberry# IO is a .NET/Mono IO Library for Raspberry Pi. This project is an initiative of the Raspberry# Community.
WiringPi.NetDaniel RichesA simple C# wrapper for Gordon's WiringPi library.
PiSharpAndy BradfordPi# is a library to expose the GPIO functionality of the Raspberry Pi computer to the C# and Visual Basic.Net languages