【发布时间】: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