.NET核心物联网(在没有Grove Shield的情况下使用时,没有来自Seed Studio Grove DTH11传感器的数据)

.NET核心物联网(在没有Grove Shield的情况下使用时,没有来自Seed Studio Grove DTH11传感器的数据),.net,.net-core,raspberry-pi,iot,gpio,.net,.net Core,Raspberry Pi,Iot,Gpio,我使用Grove DTH11传感器连接到raspberry pi 4,并使用.NET Core IOT和GPIO引脚从传感器获取读数。我将传感器直接连接到Pi,而不使用Grove Pi+或Grove Shield 问题是我没有从传感器获得任何读数。下面是我正在使用的代码 int pin = 4; using (GpioController controller = new GpioController()) { Console.WriteLine("Opening Pin

我使用Grove DTH11传感器连接到raspberry pi 4,并使用.NET Core IOT和GPIO引脚从传感器获取读数。我将传感器直接连接到Pi,而不使用Grove Pi+或Grove Shield

问题是我没有从传感器获得任何读数。下面是我正在使用的代码

int pin = 4;
using (GpioController controller = new GpioController()) 
{ 
    Console.WriteLine("Opening Pin - " + pin);
    controller.OpenPin(pin, PinMode.Input);
    Console.WriteLine("Pin - " + pin + " opened successfully");
 
    using (Dht11 dth11Obj = new Dht11(pin, PinNumberingScheme.Logical)) 
    { 
        Console.WriteLine("Dht11 object created");
        while (!Console.KeyAvailable) 
        { 
            Console.WriteLine("reading data"); 
            var temp = dth11Obj.Temperature; 
            var hum = dth11Obj.Humidity; 
            Console.WriteLine("data read successfully"); 

            if (dth11Obj.IsLastReadSuccessful) 
            {
                Console.WriteLine($"Temperature: {temp.DegreesCelsius}\u00B0C, Relative humidity: {hum.Percent}%"); 
                Console.WriteLine($"Heat index: {WeatherHelper.CalculateHeatIndex(temp, hum).DegreesCelsius:0.#}\u00B0C"); 
                Console.WriteLine($"Dew point: {WeatherHelper.CalculateDewPoint(temp, hum).DegreesCelsius:0.#}\u00B0C"); 
             } 
             else 
             { 
                 Console.WriteLine("Error reading DHT sensor"); 
             }
             
             Thread.Sleep(2000); 
        } 
    } 
} 
下面是上述代码的输出

Opening Pin - 4
Pin - 4 opened successfully
Dht11 object created
reading data
显示“读取数据”后执行受阻,没有传感器读数

Raspberry Pi和传感器的连接如下-

Pin GND of Dth11 Sensor is Connected to Pin 6 of Raspberry Pi 4
Pin VCC of Dth11 Sensor is Connected to Pin 1 of Raspberry Pi 4
Pin NC  of Dth11 Sensor is Connected to Nothing
Pin SIG of Dth11 Sensor is Connected to Pin 7 (GPIO 4) of Raspberry Pi 4

你不应该在之前打开别针。 删除行
控制器.OpenPin(pin,PinMode.Input)

请参阅:

我尝试在不打开pin的情况下使用它,但没有成功。此错误与未处理的异常有关。System.InvalidOperationException:引脚4不支持模式输入上拉。位于System.Device.Gpio.GpioController.SetPinMode(Int32 pinNumber,PinMode模式)。Github问题-您应该尝试最新的1.3版本来解决此问题。您可能遇到了两个不同的累积问题:-RPI4上不支持InputPullUp-某些RPI4上存在板检测问题