Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
R

raspberryio

> 编程语言
Open source

The Raspberry Pi's IO Functionality in an easy-to-use API for Mono/.NET/C#

672 stars0 likes1 views
WebsiteGitHub

About

The Raspberry Pi's IO Functionality in an easy-to-use API for Mono/.NET/C#

** THIS REPO HAS BEEN ARCHIVED **

RaspberryIO - Pi's hardware access from .NET

WE ARE LOOKING FOR A NEW HOME FOR THIS PROJECT. APPLY AT: https://adoptoposs.org/p/9f5b74b9-04f2-42b6-891f-c5294c9ef1c5

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

The Raspberry Pi's IO Functionality in an easy-to-use API for .NET (Mono/.NET Core). Our mission is to make .NET a first-class citizen in the Python-centric community of Raspberry Pi developers.

Table of contents

  • Features
    • Peripherals
  • Breaking changes
    • Version ≥ 0.18.0
  • Installation
  • Running the latest version of Mono
    • For Debian Stretch
  • Running .NET Core 3.1
  • Usage
    • Run the app on the raspberry
  • Obtaining Board and System Information
  • Using the GPIO Pins
    • Pin Information
    • Digital Read and Write
    • Hardware PWM
    • Software PWM
    • Tone Generation
    • Interrupts and Callbacks
  • Using the SPI Bus
  • I2C to connect ICs
  • Timing and Threading
    • Timing
    • Threading
  • Serial Ports (UART)
  • The Camera Module
    • Capturing Images
    • Capturing Video
  • Audio settings
  • Handy Notes
  • Related Projects and Nugets

Features

This library enables developers to use the various Raspberry Pi's hardware modules:

  • Pi.Camera Provides access to the official Raspberry Pi Camera module.
  • Pi.Info Provides information on this Raspberry Pi's CPU and form factor.
  • Pi.Gpio Provides access to the Raspberry Pi's GPIO as a collection of GPIO Pins.
  • Pi.Spi Provides access to the 2-channel SPI bus.
  • Pi.I2c Provides access to the functionality of the I2C bus.
  • Pi.Timing Provides access to The PI's Timing and threading API.

Peripherals

We offer an additional package with helpful classes to use peripherals, many of them are from pull requests from our contributors. The current set of peripherals supported are:

  • Infrared Sensor HX-1838
  • Led Strip APA-102C
  • NFC/RFID Controller MFRC-522
  • DHT family digital relative humidity and temperature sensors:
    • DHT11
    • DHT12
    • DHT21 / AM-2301
    • DHT22 / AM-2302
  • OLED Display SSD-1306
  • Generic Button connected to GPIO
  • GY-521 MPU6050 Accelerometer
  • Ultrasonic Sensor HC-SR04
  • ADS1015 and ADS1115 I2C Analog-to-Digital Converter devices

Breaking changes

Version > 0.24.0

This version requires .NET core 3.0 to build and run.

Version ≥ 0.18.0

In the beginning, RaspberryIO was built around WiringPi library and all our classes, properties, enums, etc. was based on those ones used in WiringPi too.

Now, we are working on a more general version of RaspberryIO (Abstractions) that, could use any core library (WiringPi, PiGpio or even new ones). So, it was necessary to change certain properties and enums for more general ones.

Pinout numbering system

A breaking change in this new general version is the pinout numbering system. As we already explained above, RaspberryIO was using the WiringPi pinout numbering system, but now it uses the BCM pinout numbering system.

Note: The pin numbers are totally different in both systems, so we recommend you to double check carefully the physical pins where you connect any device.

Installation

Install basic Raspberry.IO package:

PM> Install-Package Unosquare.Raspberry.IO

If you want to implement your own provider for RaspberryIO, you must use the following package to implement all the Pi providers:

PM> Install-Package Unosquare.WiringPi

Note: For now, we have fully implemented the WiringPi library and we are working in the PiGpio implementation.

Note: The latest development builds require .NET core 3.0 to build and run. You should upgrade to the latest Version of Visual Studio first.

Install Raspberry.IO Peripherals package (Optional):

PM> Install-Package Unosquare.RaspberryIO.Peripherals

Running the latest version of Mono

It is recommended that you install the latest available release of Mono because what is available in the Raspbian repo is quite old (3.X). These commands were tested using Raspbian Stretch. The version of Mono that is installed at the time of this writing is:

Mono JIT compiler version 5.20.1.19 (tarball Thu Apr 11 19:13 UTC 2019)

The commands to get Mono installed are the following:

For Debian Stretch

bash
sudo apt install apt-transport-https dirmngr gnupg ca-certificates
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb https://download.mono-project.com/repo/debian stable-raspbianstretch main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list
sudo apt update
sudo apt-get install mono-complete

Now, verify your version of Mono by running mono --version. Version 4.6 and above should be good enough.

Running .NET Core 3.1

This project can also run in .NET Core. To install .Net Core 3.1 sdk please execute the following commands:

$ sudo apt-get -y update
$ sudo apt-get -y install libunwind8 gettext
$ wget https://download.visualstudio.microsoft.com/download/pr/67766a96-eb8c-4cd2-bca4-ea63d2cc115c/7bf13840aa2ed88793b7315d5e0d74e6/dotnet-sdk-3.1.100-linux-arm.tar.gz
$ sudo mkdir -p /usr/share/dotnet
$ sudo tar -xvf dotnet-sdk-3.1.100-linux-arm.tar.gz -C /usr/share/dotnet
$ sudo ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet

If you want to install just the runtime, use the following commands:

$ sudo apt-get -y update
$ sudo apt-get -y install libunwind8 gettext
$ wget https://download.visualstudio.microsoft.com/download/pr/60d21925-7f8f-4004-9afe-aebd041d2d4a/0db2946738642d7f88f71f7800522e8c/dotnet-runtime-3.1.0-linux-arm.tar.gz
$ sudo mkdir -p /usr/share/dotnet
$ sudo tar -xvf dotnet-runtime-3.1.0-linux-arm.tar.gz -C /usr/share/dotnet
$ sudo ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet

Now, verify your version of .Net Core by running dotnet --info. Visit https://aka.ms/dotnet-download (or https://dotnet.microsoft.com/download/dotnet-core/3.1) to check for newer versions of the .Net Core runtime (or SDK). The Raspberry Pi running the default Raspbian OS needs the versions named "Linux ARM32".

Usage

Before start using RaspberryIO, you must initialize Pi class (bootstrapping process) with the valid Abstractions implementation, in order to let Pi know what implementation is going to use:

csharp
 Pi.Init();

Note: This sample code uses the wiringpi-dotnet implementation, you can use this implementation adding the Unosquare.WiringPi nuget package to your project.

Run the app on the raspberry

Deploy using dotnet-sshdeploy

  • You need to publish the project and you can accomplish this by using dotnet-sshdeploy but first, you must edit these properties inside the csproj file in order to establish an ssh connection with your raspberry
xml
172.16.17.54
/home/pi/Playground
pi
raspberry
  • Install dotnet-sshdeploy as a global tool by running
$ dotnet tool install -g dotnet-sshdeploy
  • Execute dotnet-sshdeploy push in the same folder where Unosquare.RaspberryIO.Playground.csproj resides and if everything executes correctly you should see an output like this:
…
  • The default TargetFramework is net461 but you can change this by either modifying the RuntimeIdentifier property inside the csproj file or supplying it as a parameter like this dotnet-sshdeploy push -f netcoreapp2.2. More information about dotnet-sshdeploy see this

Deploy using Visual Studio "Publish" and WinSCP

Alternatively, you can use Visual Studio's Publish feature and a SCP (SSH Copy) application such as WinSCP or FileZilla. This uses the example project from this library:

  • Right click on "Unosquare.RaspberryIO.Playground" and select "Publish..."
  • Select the publish profile you want to use (debug or release) and click on "Publish" on the right.
  • Wait for the project to build and note the output path
  • Open WinSCP, ensure you can connect to your raspberry
  • Navigate to the output folder noted above on your local computer
  • Select "Commands -> Keep remote folder current", check the local and remote folder entries in the dialog and choose "In new Window" from the "Start" button.
  • Answer "Yes" to start an initial synchronisation. WinSCP will now automatically update the files on your Pi whenever you click the "Publish" button in Visual Studio. Note though that just building will not update the publish folder.

Run the project

  • Using Mono:

    First of all, you need to give permissions to run the project by running the next command on your target folder:

        ubuntu@ubuntu:~/publish$ sudo chmod u+x *

    Or you just can add the SshDeployExecutePermission tag in your project's csproj file:

        true

    Or use the appropriate command line argument:

        dotnet-sshdeploy push ... -x true

    Then you can run your project:

     ubuntu@ubuntu:~/publish$ ./Unosquare.RaspberryIO.Playground
  • Using .Net Core

      ubuntu@ubuntu:~/publish$ dotnet Unosquare.RaspberryIO.Playground.dll

    or

      ubuntu@ubuntu:~/publish$ chmod +x Unosquare.RaspberryIO.Playground
      ubuntu@ubuntu:~/publish$ ./Unosquare.RaspberryIO.Playground

    (the first line only needs to be executed once or after an update, since copying may not automatically set the execute bit)

    Note: Depending on the underlying library, you may need to use root user privileges to run the app.

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.

Using the GPIO Pins

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

BCM Name Mode V L R V Mode Name BCM
3.3v 01 02 5v
2 SDA.1 ALT0 1 03 04 5V
3 SCL.1 ALT0 1 05 06 GND
4 GPIO. 7 IN 1 07 08 1 ALT0 TxD 14
GND 09 10 1 ALT0 RxD 15
17 GPIO. 0 IN 0 11 12 0 IN GPIO. 1 18
27 GPIO. 2 IN 0 13 14 GND
22 GPIO. 3 IN 0 15 16 0 IN GPIO. 4 23
3.3v 17 18 0 IN GPIO. 5 24
10 MO

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C#cameracaptured-imagesdotnetdotnetcore

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言