想知道是否有任何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