Raspberryio
The Raspberry Pi's IO Functionality in an easy-to-use API for Mono/.NET/C#
Install / Use
/learn @unosquare/RaspberryioREADME
** THIS REPO HAS BEEN ARCHIVED **
<img src="https://github.com/unosquare/raspberryio/raw/master/logos/raspberryio-logo-32.png"></img> 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
- Breaking changes
- Installation
- Running the latest version of Mono
- Running .NET Core 3.1
- Usage
- Obtaining Board and System Information
- Using the GPIO Pins
- Using the SPI Bus
- I2C to connect ICs
- Timing and Threading
- Serial Ports (UART)
- The Camera Module
- Audio settings
- Handy Notes
- Related Projects and Nugets
Features
This library enables developers to use the various Raspberry Pi's hardware modules:
Pi.CameraProvides access to the official Raspberry Pi Camera module.Pi.InfoProvides information on this Raspberry Pi's CPU and form factor.Pi.GpioProvides access to the Raspberry Pi's GPIO as a collection of GPIO Pins.Pi.SpiProvides access to the 2-channel SPI bus.Pi.I2cProvides access to the functionality of the I2C bus.Pi.TimingProvides 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
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:
Pi.Init<BootstrapWiringPi>();
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
<SshDeployHost>172.16.17.54</SshDeployHost>
<SshDeployTargetPath>/home/pi/Playground</SshDeployTargetPath>
<SshDeployUsername>pi</SshDeployUsername>
<SshDeployPassword>raspberry</SshDeployPassword>
- Install dotnet-sshdeploy as a global tool by running
$ dotnet tool install -g dotnet-sshdeploy
- Execute
dotnet-sshdeploy pushin the same folder where Unosquare.RaspberryIO.Playground.csproj resides and if everything executes correctly you should see an output like this:
SSH Deployment Tool [Version 0.3.1.0]
(c)2015 - 2017 Unosquare SA de CV. All Rights Reserved.
For additional help, please visit https://github.com/unosquare/sshdeploy
Deploying...
Configuration Debug
Framework dotnetcore2.2
Source Path C:\raspberryio\src\Unosquare.RaspberryIO.Playground\bin\Debug\dotnetcore2.2\publish
Excluded Files .ready|.vshost.exe|.vshost.exe.config
Target Address 172.16.17.54:22
Username pi
Target Path /home/pi/Playground
Clean Target NO
Pre Deployment
Post Deployment
Connecting to host 172.16.17.54:22 via SSH.
Connecting
