【问题标题】:.NET Core IOT (No Data coming from Seed Studio Grove DTH11 Sensor when using without Grove Shield).NET Core IOT(不使用 Grove Shield 时没有来自 Seeed Studio Grove DTH11 传感器的数据)
【发布时间】:2020-11-12 16:12:47
【问题描述】:

我正在使用 Grove DTH11 传感器连接到树莓派 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

显示“读取数据”后执行卡住并且没有传感器读数。

树莓派和传感器的连接如下-

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

【问题讨论】:

    标签: .net .net-core raspberry-pi iot gpio


    【解决方案1】:

    您之前不应该打开别针。 删除行controller.OpenPin(pin, PinMode.Input); 见:https://github.com/dotnet/iot/blob/c8130309c99a35ce68a10c40ca9003b0261cc2ef/src/devices/Dhtxx/DhtBase.cs#L100

    【讨论】:

    • 我尝试在不打开 pin 的情况下使用它,但没有运气。此错误与未处理的异常有关。 System.InvalidOperationException:引脚 4 不支持模式 InputPullUp。在 System.Device.Gpio.GpioController.SetPinMode(Int32 pinNumber,PinMode 模式)。 Github 问题 - github.com/dotnet/iot/issues/1291
    • 您应该尝试可以解决问题的最新 1.3 版本。您可能遇到了 2 个不同的累积问题: - RPI4 不支持 InputPullUp - 某些 RPI4 上的板检测问题
    猜你喜欢
    • 1970-01-01
    • 2017-02-07
    • 2023-03-06
    • 1970-01-01
    • 2019-11-29
    • 1970-01-01
    • 1970-01-01
    • 2021-02-05
    • 2021-02-21
    相关资源
    最近更新 更多