I just wanted to start experimenting with the DHT22 / AM2302 (temperature and humidity sensor), but I have no idea how to initialize and get data from this ... I tried using GpioPin:
gpioController = GpioController.GetDefault(); if(gpioController == null) { Debug.WriteLine("GpioController Initialization failed."); return; } sensorPin = gpioController.OpenPin(7);
but get an exception: "The resource required for this operation is disabled."
After that, I looked at the library for unixoids and found this:
https://github.com/technion/lol_dht22/blob/master/dht22.c
But I have no idea how to understand that in VCSharp using Windows 10, does anyone have an idea or experience?
Thank you in advance!
UPDATE:
I got a hint that there is no GPIO-Pin 7, and this is true, so I repeated it, but the GPIO-Output seems just HIGH or LOW ... Therefore, I need to use I2C or SPI ... According to this project, I decided to try it with SPI: http://microsoft.hackster.io/windowsiot/temperature-sensor-sample and take steps forward ... the difficulty now is to transfer the above linked C-library with the C-Sharp-SDK to get the right data ...
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); } }
This does not work as well as to be clear: it only works once, starting raspberries pasp2, and then it starts / uninstalls the debugging program, but after exiting the application and restarting it, their SPI is not initialized.
And now I'm working on reading data from a pin and will show the code in a future update. Any comments, answers and / or recommendations are still welcome.