Since dotnet core now runs on most Linux systems including the Raspberry Pi, I thought I would give it a go and see how it works. Only problem might be talking to the GPIO pins on the board but I am sure I can find some type of solution
- Loading dotnet Core onto the RPi
I followed the instructions on this page with a few minor changes after I ran into trouble.
These are the commands I used:
$ apt-get install wiringpi
$ sudo apt-get -y update
$ sudo apt-get -y install libunwind8 gettext
$ wget https://dotnetcli.blob.core.windows.net/dotnet/Sdk/2.1.300/dotnet-sdk-2.1.300-linux-arm.tar.gz
$ wget https://dotnetcli.blob.core.windows.net/dotnet/aspnetcore/Runtime/2.1.0/aspnetcore-runtime-2.1.0-linux-arm.tar.gz
$ sudo mkdir /opt/dotnet
$ sudo tar -xvf dotnet-sdk-2.1.300-linux-arm.tar.gz -C /opt/dotnet/
$ sudo tar -xvf aspnetcore-runtime-2.1.0-linux-arm.tar.gz -C /opt/dotnet/
$ sudo ln -s /opt/dotnet/dotnet /usr/local/bin - SSH Deploy to the rescue.
I have VS2017 installed on a windows PC, and decided to use that for my development environment but there is a problem ... How do I easily get the code from my Windows PC onto the RPI to test. Luckily I found this program called SshDeploy. This made my life much easier.
Following the instructions on the site I installed it added the xml tags to my project and tested it. Each time after a successful compile it auto sends the program data to the pi.
- Finding a Nuget Package for the GPIO pins.
Next thing was to proof that I can communicate with the GPIO pins correctly. I did a search on NUGET for GPIO and went to each web site to see how much info there was in case I got stuck. I settled on Unosquare Raspberry IO.Lots of help and a good description. What sold me on the solution was the ability to use callbacks so no need for a while (true) loop. - Testing the GPIO pins.
I created a new dotnet core 2.1 command line program, followed the steps of SSH Deploy and added this code:
using System;
using Unosquare.RaspberryIO;
using Unosquare.RaspberryIO.Gpio;
namespace TestGpio
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Gpio Callback Test 3");
var pin = Pi.Gpio.Pin00;
pin.PinMode = GpioPinDriveMode.Input;
pin.InputPullMode =
GpioPinResistorPullMode.PullUp;
pin.RegisterInterruptCallback (
EdgeDetection.RisingAndFallingEdges,
Pin00Callback);
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
static void Pin00Callback()
{
var pin = Pi.Gpio.Pin00;
var state = pin.ReadValue();
Console.WriteLine("Pin Activated..." + state);
}
}
}
- I compiled the code, and confirmed it SFTPed it to the Raspberry Pi.
- I logged into the RaspBerry Pi with my user name and went to the deployed folder and verified the files were recent.
- Then I ran the program using this command:
$ sudo dotnet TestGpio.dll - This is the output:
No comments:
Post a Comment