-1


I have sensor like this: https://easyelectronyx.com/wp-content/uploads/2017/03/flame.jpg?i=1

Please can anyone help me ? I need to find code to read from it , in C#. I have Raspberry Pi 2 Model B , Windows 10 IoT Core and programming in C#. I cant find documentation on the Internet. Is it needed to wire Analog output ?

Thanks

Rita Han
  • 9,574
  • 1
  • 11
  • 24
Ivan Čík
  • 19
  • 1

1 Answers1

2

This Frame sensor device can provide digital or analog output based on its datasheet.

If you don't like to use analog output you can get output from digital pin DO.

First, connect the Frame sensor and Raspberry Pi. Connect VCC, GND and DO like the following picture show. For digital pin, I choose GPIO27 here, you can choose other pin you like.

enter image description here

Second, write the code. Create the UWP app(Start here).

MainPage.xaml

<StackPanel VerticalAlignment="Center" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <TextBlock Name="SensorOuputValue" />
</StackPanel>

MainPage.xaml.cs

public sealed partial class MainPage : Page
{
    private const int SENSOR_PIN = 27;
    private GpioPin pin;
    private GpioPinValue pinValue;
    private DispatcherTimer timer;

    public MainPage()
    {
        InitializeComponent();

        timer = new DispatcherTimer();
        timer.Interval = TimeSpan.FromMilliseconds(1000);
        timer.Tick += ReadSensor;
        InitGPIO();
        if (pin != null)
        {
            timer.Start();
        }
    }

    private void InitGPIO()
    {
        var gpio = GpioController.GetDefault();

        // Show an error if there is no GPIO controller
        if (gpio == null)
        {
            pin = null;
            System.Diagnostics.Debug.WriteLine("There is no GPIO controller on this device.");
            return;
        }

        pin = gpio.OpenPin(SENSOR_PIN);
        pin.SetDriveMode(GpioPinDriveMode.Input);

        System.Diagnostics.Debug.WriteLine("GPIO pin initialized correctly.");

    }

    private void ReadSensor(object sender, object e)
    {
        SensorOuputValue.Text = pin.Read().ToString();
    }

}
Rita Han
  • 9,574
  • 1
  • 11
  • 24