Close

GPIO Test on Raspberry Pi 4 Using .NET 8 (C#)

A project log for SigCore UC - Universal Controller

Universal industrial I/O controller with relays, analog/digital I/O, Modbus & OPC-UA support. Powered by Raspberry Pi.

edwardEdward 07/30/2025 at 22:120 Comments

Today we successfully tested direct GPIO output control on a Raspberry Pi 4B using C# and .NET 8. Here's a quick recap of the progress:

1. GPIO Setup

2. Power Supply

3. C# Code

4. Outcome

Code

using System;
using System.Device.Gpio;
using System.Threading;

class Program {
    static void Main() {
        int pin = 17; // GPIO17
        using var controller = new GpioController();

        controller.OpenPin(pin, PinMode.Output);
        Console.WriteLine("Setting GPIO17 HIGH (3.3V)");
        controller.Write(pin, PinValue.High);

        Thread.Sleep(10000); // Hold for 10 seconds

        Console.WriteLine("Turning GPIO17 LOW (0V)");
        controller.Write(pin, PinValue.Low);

        controller.ClosePin(pin);
        Console.WriteLine("Done.");
    }
}

Discussions