I know it is not a rocket science to connect a sensor to your computer and read its measurements. But if you haven’t been doing it before, I will show you a simple experiment with a Raspberry Pi and a temperature sensor.
I used a Raspberry Pi 3 Model B, though Pi 2 would be of use as well. If you already have Windows 10 IoT Core installed on your Raspberry Pi – that’s fine. If not, there is a good guide how to install it: How to install Windows 10 IoT Core on Raspberry Pi 3. The only remark I would add is my advice to format your MicroSD card with an SD Memory Card Formatter before installing any OS on it.
Next, we will need a sensor. I bought a cheap (and not too accurate) Humidity and Temperature Sensor DHT11. It has three pins:
- Power supply 3 – 5.5 V DC (+)
- Serial data output
- Ground (-)
Having everything in hand, connect the sensor to the Raspberry Pi as shown below:
When everything is set up, connected and switched on, open Windows 10 IoT Core Dashboard and connect to your Raspberry Pi (see instructions if something went wrong).
Find your device in the list, right-click on it and select Open in Device Portal. This will launch the Windows Device Portal. The Windows Device Portal lets you manage your device remotely over a network. In order to enable remote display functionality on your Raspberry, choose Remote from the options on the left, and Enable Window IoT Remote Server.
Install the Windows IoT Remote Client on your workstation and run it. Connect to your Raspberry Pi device through the client. You should see a window like this one on the left.
Now, you can download a source code of the TemperatureSensor project from GitHub: https://github.com/jevgenij-p/blog/tree/master/Temperature%20Sensor.
Open the project in the Visual Studio 2017 and build it. You will find a separate library Sensors.Dht, written by Daniel Porrey. I used his code to read sensor’s data.
Set the solution platform to ARM and the target as Remote Machine in the tool bar:
Open the TemperatureSensor project properties and choose Debug page. Check that Remote machine field contains your Raspberry Pi device name or IP address:
Press F5 to build and deploy the application to your Raspberry Pi. The sensor should start sending temperature and humidity values every second, and the Windows IoT Remote Client will show a screen like this one:
Voila!
The source code of the Visual Studio project can be found there