简体   繁体   中英

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?

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 .

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

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM