In this project, we will use Windows Remote Arduino to turn an LED on and off. It is a simple example, but will reveal the power that the library can give you to create many more advanced projects. Let’s get started!
You can download the "samples" repository here. This sample is "RemoteBlinky" inside the appropriate platform folder, either Win10 or Win8.1. Make sure to clone the repository recursively so that you also obtain a copy of the library (more info in the readme)! The downloadable sample includes code for both USB and Bluetooth connections, while this guide mainly covers Bluetooth (with some short USB asides) since it involves extra hardware steps and is just so much more awesome.
It is also possible to connect to your Arduino through the network, but you'll require a WiFi shield or Ethernet shield. Further instructions can be found on the Windows Remote Arduino repository page, linked directly below.
If you'd prefer to create your own project, follow the project set up guide here
You can find the Windows Remote Arduino repository here
Program the ArduinoFirst thing's first, let's program the Arduino.
StandardFirmata uses the Serial lines to talk to a Bluetooth device or over USB. By default, it uses a baud rate of 57,600 bps. Depending on the configuration of your Bluetooth device, you may need to modify that rate. It can be found in the setup
method and looks like this:
Firmata.begin(57600);
Change this value to the correct baud rate. For USB, this value is configurable on both the device and in the Windows Remote Arduino connection parameters. If you are using Bluetooth, the baud rate depends on the device you are using.
Hardware Set UpYou can always use a USB, WiFi, or Ethernet connection to get started, but let’s cover simple hook up of a Bluetooth device and an LED that we will turn on and off over Bluetooth using the Windows Remote Arduino library!
Arduino Sketch (Firmata)
Install Arduio Firmata Library:
Goto Sketch menu / Include Library / Manage Library and search for "Firmata" and install latest version of the library.
Now open & upload "StandardFirmata" example from File / Examples / Firmata / StandardFirmata.
It's done at Arduino side. Now we will see for Windows Universal Platform App.
Windows Universal Platform App
Download the sample repository here. If you'd prefer to create your own project, follow the project set up guide here.
Now that we’re all set up, let’s get into some code!
I’ve set up a project called RemoteBlinky by following the steps in the setup guide. In the screenshot below, you will see the code-behind file MainPage.xaml.cs which simply creates a Bluetooth connection object and passes it to the RemoteDevice class in the constructor. You’ll see that I’ve specified my device name in this example. You may also enumerate the available devices by invoking the static .listAvailableDevicesAsync()
function on BluetoothSerial (and USBSerial) class before constructing your object.
USBSerial
has many options available to specify your device. In the constructor, you can provide the VID and PID of your device, the VID only, or a DeviceInformation
object (obtained from the above mentioned listAvailableDevicesAsync
function). Similarly, BluetoothSerial
allows you to provide a device id (as a string), device name (also a string), or the DeviceInformation
object.
You can obtain the VID & PID combination of your USB device by following these steps:
USBSerial usb = new USBSerial( "VID_2341", "PID_0043" );
is guaranteed to work only for the following hardware device:
Next, I’m going to add a callback function to the DeviceReady event on the RemoteDevice object. This function will automatically be called when the Bluetooth device is connected and all necessary settings have been initialized. You’ll notice that I haven’t implemented anything in that function at this time. Last, call .begin()
on the connection object to tell it to connect.
The parameters to the .begin()
function do not matter for Bluetooth, but you must use the same baud rate on both the Arduino and the UsbSerial object (first parameter). Also, the 2nd parameter must be "SerialConfig.8N1"
. The rest of the example will work exactly the same regardless of which connection type you are using.
Click
event & set the IsEnabled
property to false, and you’ll see why in the next step!OnDeviceReady
function now enables the buttons on the UI thread! This guarantees that the buttons will be enabled only when the Bluetooth connection is ready, as it typically takes a few seconds for this to happen..digitalWrite()
calls in the button callbacks OnButton_Click
and OffButton_Click
I really hope you enjoy replicating this project and using it as a baseline for an incredible new set of Maker projects!
Read moreRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4