1

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?

Rita Han
  • 9,574
  • 1
  • 11
  • 24
Pradeep
  • 5,101
  • 14
  • 68
  • 140

2 Answers2

2

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.

Rita Han
  • 9,574
  • 1
  • 11
  • 24
  • Rita, I used the same code it works fine but it gives the value will be High or Low. but actually this Q4XTBLAF300-Q8 sensor gives the output as distance in mm. can you please tell me how to read the exact value from this Q4XTBLAF300-Q8 sensor. – Pradeep Sep 25 '17 at 12:25
  • What's your sensor's datasheet? – Rita Han Sep 26 '17 at 02:12
  • This link for my sensor datasheet http://info.bannerengineering.com/cs/groups/public/documents/literature/181484.pdf – Pradeep Sep 26 '17 at 04:07
  • But its output is sending to the display, am I right? – Rita Han Sep 26 '17 at 05:14
  • Yes Rita. whenever object near to the sensor it display the distance from object. – Pradeep Sep 26 '17 at 05:30
1
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

}
rollstuhlfahrer
  • 3,988
  • 9
  • 25
  • 38
Devdatt
  • 82
  • 5
  • While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value. – rollstuhlfahrer Mar 26 '18 at 14:32