© 2017 The Programmator. Theme WPBoot by Just Free Themes.
Because there is currently no way to autodiscover an Arduino as an USB peripheral from a Raspberry Pi running Windows 10, I have to resort to I²C communication to get messages from and to the Arduino. I will use a DHT 11 humidity and temperature sensor I had laying around.
For this article to make any sense, you’re expected to have basic knowledge of your Arduino, the Arduino IDE (or deploying via Visual Studio), how to create a very basic Windows Universal Application, and you need to have Windows 10 installed on your Raspberry Pi.
I have a Raspberry Pi 2 model B v1.1 and a cheap Arduino. Your pins may vary. Please do not blindly connect pins.
Setting up serial communication on the Arduino is pretty simple. First we need to let the outside world know on which address we will be sending data. Second, include and use the Wire library to set up the communication line on that address. And last, we send the data over the Wire.
As you can see, the declaration of our Arduino project is straightforward. We include the libraries, define the address, I have the DHT11 sensor on digital pin 4, and the latest DHT library requires us to define the type of sensor in the DHTTYPE property.
Next, we instantiate a new dht object, and reserve 2 char arrays of data to be sent.
Create an empty Windows Universal Application. This application will read and display the temperature coming from the sensor attached to the Arduino!
Open the MainPage code behind, and create an async method to initialize the connection. The following block of code creates a connection to the Arduino on the aforementioned address.
When auto-resolving missing libraries for I2c namespace objects, I got a series of errors about .winmd. Remove the Windows.Devices.LowLevel… reference, and add a manual reference to “Windows IOT Extensions for the UWP”.
In the timer callback, we read the data and send it to the UI.
Finally, set debug target on “Remote Device”, select your Raspberry running Windows 10 and hit Debug!
All source code for this sample (and others) is available on GitHub.