Windows IoT


How to read from dht11 ? Raspberry C# UWP


Hello!
My question is: Please how can i read from dht11 temperature and humidity? Please I found only big codes on the internet like 600 lines. I just want to enter humidity and temperature into textboxes . I have raspberry 2b+, Universal windows application.
Thanks!
https://developer.microsoft.com/en-us/windows/iot/samples/gpioonewire
Hello ! Do you think it is good code for dht11 ? Is it Working To you ? I use 3.3 V , Visual Studio 2015, Gpio 4 for data.
using Sensors.Dht;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using TemperatureSensor.Client.Common;
using Windows.Devices.Gpio;
using Windows.UI.Xaml;
using Microsoft.Azure.Devices.Client;
using Newtonsoft.Json;
using System.Text;
namespace TemperatureSensor.Client
{
public sealed partial class MainPage : BindablePage
{
private DispatcherTimer _dispatchTimer;
private GpioPin _temperaturePin;
private IDht _dhtInterface;
private List<int> _retryCount;
private DateTimeOffset _startedAt;
public MainPage()
{
this.InitializeComponent();
// call the method to initialize variables and hardware components
InitHardware();
// set interval of timer to 1 second
_dispatchTimer.Interval = TimeSpan.FromSeconds(1);
// invoke a method at each tick (as per interval of your timer)
_dispatchTimer.Tick += _dispatchTimer_Tick;
// initialize pin (GPIO pin on which you have set your temperature sensor)
_temperaturePin = GpioController.GetDefault().OpenPin(4, GpioSharingMode.Exclusive);
// create instance of a DHT11
_dhtInterface = new Dht11(_temperaturePin, GpioPinDriveMode.Input);
// start the timer
_dispatchTimer.Start();
// set start date time
_startedAt = DateTimeOffset.Now;
}
// method to initialize variables and hardware components
private void InitHardware()
{
_dispatchTimer = new DispatcherTimer();
_temperaturePin = null;
_dhtInterface = null;
_retryCount = new List<int>();
_startedAt = DateTimeOffset.Parse("1/1/1");
}
private async void _dispatchTimer_Tick(object sender, object e)
{
try
{
DhtReading reading = new DhtReading();
reading = await _dhtInterface.GetReadingAsync().AsTask();
if (reading.IsValid) // if we are able to capture value, display those
{
this.Temperature = Convert.ToSingle(reading.Temperature);
this.Humidity = Convert.ToSingle(reading.Humidity);
}
else // log if the reading is not in valid state
{
Debug.WriteLine(string.Format("IsValid: {0}, RetryCount: {1}, TimedOut: {2}, Humidity: {3}, Temperature: {4}", reading.IsValid, reading.RetryCount, reading.TimedOut, reading.Humidity,
reading.Temperature));
}
}
catch(Exception ex) // log any exception that occurs
{
Debug.WriteLine(ex.Message);
}
}
#region application properties
private float _humidity = 0f;
public float Humidity
{
get
{
return _humidity;
}
set
{
this.SetProperty(ref _humidity, value);
this.OnPropertyChanged(nameof(HumidityDisplay));
}
}
public string HumidityDisplay
{
get
{
return string.Format("{0:0.0}% RH", this.Humidity);
}
}
private float _temperature = 0f;
public float Temperature
{
get
{
return _temperature;
}
set
{
SetProperty(ref _temperature, value);
this.OnPropertyChanged(nameof(TemperatureDisplay));
}
}
public string TemperatureDisplay
{
get
{
return string.Format("{0:0.0} °C", this.Temperature);
}
}
#endregion
}
}
Hi ajvnSlovakia,
This is indeed the sample for GPIO and DHT11. From
https://developer.microsoft.com/en-us/windows/iot/samples
GPIO OneWire
Create an app that uses GPIO to read from the DHT11, a temperature and humidity sensor that uses a single-wire protocol
C++
If it is not working for you, please explain where it is failing.
Sincerely,
IoTGirl

Related Links

windows iot remote display security
The accuracy of measuring a plus width by using GPIO event and stopwatch
Installing application on Windows IoT
RPi Serial Port Start Bit
Older Insider Preview ISOs
Formatting an SD card once windows 10 is installed on it
Infrared sensor needed für Win IoT
GPIOOneWire DHT22/AM2302
HD Photo Capture on Dragonboard
How to do plugins or scripting in UWP for Windows 10 IoT Core (RPi)
Checking if SpiDevice is ready
Microsoft.IoT.Lightning namespace unavailable in Microsoft.IoT.Lightning nuget package 1.0.4
serving asp.net pages from my raspberry p2 device
RPi 2 not booting with Windows 10 IoT core
Windows 10 IoT on Raspberry Pi 3 SerialPort Access - missing IoTStartup.exe
What does it mean for IoT device drivers to be Inbox? Direct Memory Mapped?

Categories

MSDN
JScript and Scripting
Microsoft Sync Framework
Smart Device Development
Exchange Server
Archived Forums SA-SM
Archived Forums T-U
Forums Redesign - Q&A ...
Off-Topic Posts (Do No...
Visual Studio Integrate
Visual Studio LightSwi...
Visual Studio LightSwi...
Developing Universal W...
Dev Center App
Store Engagement Frame...
Media Foundation Devel...
Windows Imaging Compon...
Windows Hardware Testi...
Message Analyzer
Developing Apps for Of...
Pricing & Billing
Azure Multi-Factor Aut...
Azure Mobile Apps
Azure Backup
Azure Cache
Azure CDN
Azure Data Factory
StorSimple
Azure Data Lake Analyt...
Azure Analysis Services
Azure Blockchain
.NET Framework Setup a...
Windows Communication ...
Team Foundation Server...
Software Modeling Tools
BizTalk Server Adapter...
BizTalk ESB Toolkit
The Forum of Sho
Microsoft Translator D...
Small Basic
SyncFx - General [Read...
SyncFx - SyncToy-File ...
Microsoft Robotics - C...
SQL Server Analysis Se...
SQL Server Tools
SQL Service Broker
Getting started with S...
Database Design
SQL Server Migration
Power Pivot
SQL Server In-Memory T...
Standard 2009: Embedde...
SQL Server 2012 Setup ...
SQL Server 2012 Databa...
Windows Forms Designer
Windows Live Messenger...
Windows Live ID: Devel...
Bing Maps for Windows ...
Microsoft Atlas APIs: ...
Microsoft Lync Client ...
PivotViewer Control wi...
Expression Studio with...
Expression Studio
Expression Web and Sup...
Windows Performance To...
Retired InfoPath Forms...
.NET Framework 4 setup...
.NET StockTrader Sampl...
ADO.NET Entity Framewo...
Announcements about pr...
AppFabric Service and ...
ASMX Web Services and ...
AppFabric Caching
Dryad, DSC, and DryadL...
Dynamic Languages on .NET
Getting Started With V...
Hobbyist Zone
LINQ to SQL (Pre-Release)
Model-Based Testing wi...
Moderator Posting Only...
Performance Counters f...
Pex and Moles PowerTool
Popfly Game Creator
NUI API and Programmin...
Search Server: Known B...
Silverlight (formerly ...
SQL Creation
Transactions Programming
Using Visual Round Tri...
Visual Studio Applicat...
Visual Studio Class De...
Visual Studio Performa...
Windows CardSpace ('In...
Windows Developer Prev...
Windows Phone push not...
Windows IoT
Microsoft R Open

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile