回声引脚始终读低

时间:2019-01-08 10:54:06

标签: c# raspberry-pi

我正在尝试用我的Raspberry Pi编码距离传感器HC-SR04。以下代码始终读为低。

using System;
using System.Threading;
using RaspberryPiDotNet;

namespace Pi_Projects
{
  class Program
  {
    static GPIOMem echo = new GPIOMem(GPIOPins.V2_GPIO_02, GPIODirection.In);
    static GPIOMem trigger = new GPIOMem(GPIOPins.V2_GPIO_03, GPIODirection.Out);

    static void Main(string[] args)
    {
        Thread.Sleep(1000);
        trigger.Write(PinState.High);
        Thread.Sleep(1);
        trigger.Write(PinState.Low);

        while(true)
        {
            Console.WriteLine(echo.Read());
        }

    }
  }
}

为确保连接和代码正常工作,我用3.3V电源触摸了ECHO引脚,然后控制台显示为High。将LED插入ECHO引脚后,它会快速闪烁,因此从技术上讲控制台应显示为High。另外,有python代码来测试传感器。我在做什么错了?

0 个答案:

没有答案