如何使用C#从Raspberry PI 3的GPIO5引脚读取值?

时间:2017-09-25 04:59:13

标签: c# iot raspberry-pi3 gpio windows-10-iot-core

我使用Q4XTBLAF300-Q8将传感器配置为Raspberry PI 3,并将其连接到GPIO5,以便根据传感器范围内输入为高的值来读取值。当它超出范围时,传感器将变低。但我不知道如何根据Q4XTBLAF300-Q8这个传感器状态编写从GPIO5引脚读取值的代码。

那么,您能否告诉我如何从Raspberry PI 3的GPIO5引脚读取值?

2 个答案:

答案 0 :(得分:2)

以下是您可以参考的代码段:

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();

要使用Windows 10 iot核心控制覆盆子pi上的GPIO,您可以检查this tutorial

更多样本为here

答案 1 :(得分:0)

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

}