想知道是否有任何Raspberry Pi 3 + Windows 10物联网核心+ DHT22的样本接线和代码?谢谢!使用Raspberry Pi 3 + Windows 10物联网核心+ DHT22
0
A
回答
0
static class DHT22
{
private const int intGpioData = 18;
private static GpioPin gpioData;
public static void Start()
{
//Init GPIO And Capture Data Every 2000ms
GpioController gpioController = GpioController.GetDefault();
gpioData = gpioController.OpenPin(intGpioData);
gpioData.SetDriveMode(GpioPinDriveMode.InputPullUp);
new Timer(new TimerCallback((obj) => { GetData(); }), null, 2000, 2000);
}
private static void GetData()
{
byte[] data = new byte[40];
gpioData.SetDriveMode(GpioPinDriveMode.Output);
gpioData.Write(GpioPinValue.Low);
Task.Delay(1).Wait();
gpioData.SetDriveMode(GpioPinDriveMode.InputPullUp);
//Record Data
while (gpioData.Read() == GpioPinValue.High) ;
while (gpioData.Read() == GpioPinValue.Low) ;
while (gpioData.Read() == GpioPinValue.High) ;
byte low;
for (int i = 0; i < 40; i++)
{
low = 0;
data[i] = 0;
while (gpioData.Read() == GpioPinValue.Low && low <= byte.MaxValue)
low++;
while (gpioData.Read() == GpioPinValue.High && data[i] <= byte.MaxValue)
data[i]++;
}
//Analyze Data
byte humiH = 0;
byte humiL = 0;
byte tempH = 0;
byte tempL = 0;
byte sum = 0;
for (short i = 7; i >= 0; i--)
{
byte bit = data[7 - i] >= 11 ? (byte)1 : (byte)0;
humiH += (byte)(bit << i);
}
for (short i = 7; i >= 0; i--)
{
byte bit = data[15 - i] >= 11 ? (byte)1 : (byte)0;
humiL += (byte)(bit << i);
}
for (short i = 7; i >= 0; i--)
{
byte bit = data[23 - i] >= 11 ? (byte)1 : (byte)0;
tempH += (byte)(bit << i);
}
for (short i = 7; i >= 0; i--)
{
byte bit = data[31 - i] >= 11 ? (byte)1 : (byte)0;
tempL += (byte)(bit << i);
}
for (short i = 7; i >= 0; i--)
{
byte bit = data[39 - i] >= 11 ? (byte)1 : (byte)0;
sum += (byte)(bit << i);
}
//Verify Data
if ((byte)(humiH + humiL + tempH + tempL) == sum)
{
double humidity = (double)(humiH * 256 + humiL)/10;
double temperature = (double)(tempH * 256 + tempL)/10;
Debug.WriteLine(humidity + "% " + temperature + "°C");
}
}
}
0
0
如果您使用的是C++,这里就是一个例子。 https://github.com/Microsoft/Windows-iotcore-samples/tree/develop/Samples/GpioOneWire
此外,如果你想坚持到C#,这是行不通的。今天我用了2个dht11传感器。
这是GitHub的链接: https://github.com/porrey/Dht
NuGet包: https://www.nuget.org/packages/Dht/
如果您熟悉C++,然后使用。如果没有,我推荐Nuget包,只是因为我证实它今天有效。 dht11传感器似乎有很大的差异。我在两个传感器上有3度不同。
相关问题
- 1. Windows物联网 - Raspberry pi
- 2. Windows 10物联网核心主机Web API ASP.Net核心。可能?
- 3. Windows 10 iot部署到Raspberry Pi 3
- 4. 物联网Raspberry Pi传感器标签
- 5. 赢10物联网:WindowsIoTCoreWatcher.exe不显示我的Raspberry PI设备
- 6. 使用RFID RC522 Library for Windows物联网核心
- 7. 内置Raspberry Pi 3上的蓝牙Windows Windows物联网 - 找不到适配器
- 8. 使用Windows 10 IoT核心Raspberry Pi 2板载UART用于串行io?
- 9. 的Windows 10物联网核心蓝牙支持覆盆子PI3
- 10. UWP在Windows 10物联网
- 11. 单元测试c#Windows 10物联网核心应用程序(错误:DEP0700)
- 12. Windows 10物联网核心 - UWP - 发送电子邮件背景
- 13. 设置代理Windows物联网核心
- 14. 的Windows 10物联网覆盆子3
- 15. Windows IoT Raspberry Pi 3 C#GetDiskFreeSpace
- 16. Windows 8可以构建Windows 10物联网核心应用程序吗?
- 17. 在Raspberry Pi上的Windows 10物联网UWP应用程序中使用ARM编译的DLL 2
- 18. 无法应用程序部署到树莓派3时,Windows 10物联网核心
- 19. 访问网络从Windows 10物联网树莓派共享
- 20. 如何在Windows 10物联网核心上创建Web服务器
- 21. 使用IBM Bluemix注册Raspberry Pi
- 22. 检查是否有多个按钮被推送Windows物联网与Raspberry PI 3B
- 23. 调试的Windows 10物联网核心后台应用程序直接在Windows 10
- 24. Raspberry pi 3 cpuinfo ARMv7
- 25. 我可以在Windows 10 IOT - Raspberry Pi 3中使用Visual Basic 6程序吗?
- 26. Raspberry Pi 3录制声音
- 27. 的Windows 10物联网 - 支持绑定
- 28. 码头集装箱运行在Windows物联网核心
- 29. 无法使用蓝牙配对Raspberry Pi 3和iBeacon
- 30. Raspberry pi 3使用Windows的Putty拒绝SSH访问
虽然此代码可能会回答问题,但提供有关如何解决问题和/或为何解决问题的其他上下文将提高答案的长期价值。 – kayess