.NET Core IoT Libraries on Friendly ELEC NanoPi M1 Plus

Posted by Maurizio Attanasi on April 14, 2020 · 3 mins read
In the wake of the previous note, Set Up .NET Core 3.1 ARM Development Toolchain with Visual Studio Code, this time the goal is to check whether Microsoft's .NET Core IoT Libraries works also with the NanoPi M1 Plus even if this device is not in the list of supported devices.



Following the instructions in the led-blink sample, we will connect pin 17 (GPIOA17) to the cathode of a LED interposing a resistor, and pin 39 (GND) to the anode.

    class Program
{
static void Main(string[] args)
{
var pin = 17;
var lightTimeInMilliseconds = 1000;
var dimTimeInMilliseconds = 200;

Console.WriteLine($"Let's blink an LED!");
using (GpioController controller = new GpioController())
{
controller.OpenPin(pin, PinMode.Output);
Console.WriteLine($"GPIO pin enabled for use: {pin}");

Console.CancelKeyPress += (object sender, ConsoleCancelEventArgs eventArgs) =>
{
controller.Dispose();
};

while (true)
{
Console.WriteLine($"Light for {lightTimeInMilliseconds}ms");
controller.Write(pin, PinValue.High);
Thread.Sleep(lightTimeInMilliseconds);
Console.WriteLine($"Dim for {dimTimeInMilliseconds}ms");
controller.Write(pin, PinValue.Low);
Thread.Sleep(dimTimeInMilliseconds);
}
}
}

The code above, copied and pasted from the sample, is self-explanatory, in fact
  1. we select pin 17 and configure it as an output

    controller.OpenPin(pin, PinMode.Output);

  2. turn the LED on for 1 second

                        controller.Write(pin, PinValue.High);
    Thread.Sleep(lightTimeInMilliseconds);

  3. then we turn it off for 200 ms

                        controller.Write(pin, PinValue.Low);
    Thread.Sleep(dimTimeInMilliseconds);

  4. repeat from point 1.
As we've done in the previous note, we will configure our tasks.json and launch.json files in order to allow remote debugging via ssh

Only one caveat has to be considered this time in order to allow vsdg to change the mode of a pin.
In fact, this operation requires root permissions, and to get this result, one possible way is to prepend sudo before the vsdbg path in the launch.json configuration.

            "debuggerPath": "sudo ~/vsdbg/vsdbg"

The following video shows a remote debug test of the program, and demonstrate that.
  • The Microsoft .NET Core IoT Libraries works as expected;
  • We are able to use the remote debugger stopping code execution at our breakpoints


The code of this note is available here on my Github repo.

As always

Enjoy,

and if we are still under COVID-19 attack, #staysafe, #StayAtHome.