Pradeep
Pradeep

Reputation: 5510

how to read value from GPIO5 pin of Raspberry PI 3 using C#?

I configured the Raspberry PI 3 with Q4XTBLAF300-Q8 this sensor and it is connected to GPIO5 for reading the value based on whenever something is in range of the sensor the input will be high. When it is out of range, the sensor will be low. But I don’t know to how to write the code for reading the value from GPIO5 pin based on Q4XTBLAF300-Q8 this sensor status.

So, can you please tell me how to read value from GPIO5 pin of Raspberry PI 3?

Upvotes: 1

Views: 3639

Answers (2)

Devdatt
Devdatt

Reputation: 82

using Windows.Devices.Gpio;

public void GPIO()

{

       // Get the default GPIO controller on the system

       GpioController gpio = GpioController.GetDefault();

       if (gpio == null)
           return; // GPIO not available on this system


      // Open GPIO 5

      using (GpioPin pin = gpio.OpenPin(5))

      {
        // Latch HIGH value first. This ensures a default value when the pin is set as output

         pin.Write(GpioPinValue.High);

        // Set the IO direction as output
        pin.SetDriveMode(GpioPinDriveMode.Output);

     } // Close pin - will revert to its power-on state

}

Upvotes: 1

Rita Han
Rita Han

Reputation: 9700

Here is a code snippet you can reference:

using Windows.Devices.Gpio;

private const int GPIO_PIN_NUM = 5;

//Initialize gpio    
pin = GpioController.GetDefault().OpenPin(GPIO_PIN_NUM);
pin.SetDriveMode(GpioPinDriveMode.Input);

//Read gpio value    
var pinValue = pin.Read();

For controlling GPIO on the raspberry pi with windows 10 iot core you can check this tutorial.

More samples are here.

Upvotes: 2

Related Questions