2017-05-20 1 views
-1


이 같은 센서가 있습니다 https://easyelectronyx.com/wp-content/uploads/2017/03/flame.jpg?i=1

이 사람이 나를 도울 수하세요? C#에서 코드를 읽을 필요가 있습니다. 나는 라스베리 파이 2 모델 B, Windows 10 IoT 코어 및 프로그래밍 C# 있습니다. 인터넷에서 설명서를 찾을 수 없습니다. 아날로그 출력을 배선해야합니까?

감사C#에서 불꽃 센서를 읽는 방법?

+0

당신의 센서 장치는 무엇입니까? 당신이 첨부 한 사진에서 나는 유용한 정보를 얻을 수 없습니다. –

+0

라스베리 파이 2 모델 B –

+0

** 나는 라스베리 파이가 아닌 ** 센서 **를 물었습니다. –

답변

1

이 프레임 센서 장치는 datasheet에 기초한 디지털 또는 아날로그 출력을 제공 할 수있다.

당신이 디지털 핀의 출력을 얻을 수있는 아날로그 출력을 사용하는 것이 마음에 들지 않으면 마십시오.

먼저 프레임 센서와 Raspberry Pi를 연결하십시오. 다음 그림과 같이 VCC, GND 및 DO를 연결하십시오. 디지털 핀의 경우 여기 GPIO27을 선택하면 원하는 다른 핀을 선택할 수 있습니다.

enter image description here

둘째, 코드를 작성합니다. UWP 앱을 만듭니다 (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(); 
    } 

} 
+0

답변으로 문제가 해결 되었습니까? –

관련 문제