I really was using the wrong GPIO-Pin-Port, because the GpioPin 7 does not exist, but using the right Pin of it, results as value just HIGH, but the Sensor Output should be more complex, so I tried to use this as template:
http://microsoft.hackster.io/windowsiot ... sor-sample
But using the SPI just goes a little step forward, because I have to restart the Raspberry Pi 2 every time, I want to start my app for testing purposes, otherwise the device will not be found, furthermore Im not sure how to get the right values from it, so lets share the current Code:
Code for initialization of the SpiDevice
Code: Select all
private async void InitSPI()
{
try
{
var settings = new SpiConnectionSettings(SPI_CHIP_SELECT_LINE);
settings.ClockFrequency = 500000;
settings.Mode = SpiMode.Mode0;
string spiAqs = SpiDevice.GetDeviceSelector(SPI_CONTROLLER_NAME);
var deviceInfo = await DeviceInformation.FindAllAsync(spiAqs);
SpiDisplay = await SpiDevice.FromIdAsync(deviceInfo[0].Id, settings);
}
catch(Exception ex)
{
Debug.WriteLine("SPI Initialization failed: " + ex.Message);
}
}
Code for trying to read the data, according to the C-Library found here:
https://github.com/technion/lol_dht22/b ... er/dht22.c
Code: Select all
private string ToValue()
{
string retString = "";
uint laststate = 1;
uint counter = 0;
uint j = 0, i;
int[] dht22_dat = new int[5]{ 0, 0, 0, 0, 0 };
byte[] buffer = new byte[1];
int MAXTIMINGS = 85;
for (i = 0; i < MAXTIMINGS; ++i)
{
counter = 0;
while (sizecvt(read()) == laststate)
{
++counter;
if (counter == 255)
{
break;
}
}
laststate = sizecvt(read());
if (counter == 255) break;
if ((i >= 4) && (i % 2 == 0))
{
dht22_dat[j / 8] <<= 1;
if (counter < 16)
{
dht22_dat[j / 8] |= 1;
}
++j;
}
}
if ((j >= 40) && dht22_dat[4] == ((dht22_dat[0] + dht22_dat[1] + dht22_dat[2] + dht22_dat[3]) & 0xFF))
{
float t, h;
h = (float)dht22_dat[0] * 256 + (float)dht22_dat[1];
h /= 10;
t = (float)(dht22_dat[2] & 0x7F) * 256 + (float)dht22_dat[3];
t /= 10;
if((dht22_dat[2] & 0x80) != 8) t *= -1;
retString = String.Format("Humidity = {0} && Temperature = {1]", h, t);
return retString;
}
else
{
retString = "Data not good, skip";
return retString;
}
}
private int read()
{
byte[] buffer = new byte[1];
SpiDisplay.Read(buffer);
return (int)buffer[0];
}
private uint sizecvt(int read)
{
if(read > 255 || read < 0)
{
Debug.WriteLine("Invalid data");
return 0;
}
return (uint)read;
}
But I just get "Data not good, skip"