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
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.




\

Now that we’re all set up, let’s get into some code!

You can obtain the VID & PID combination of your USB device by following these steps:





I really hope you enjoy replicating this project and using it as a baseline for an incredible new set of Maker projects!
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 Arduino
First thing's first, let's program the Arduino.- Download and install the Arduino software from http://arduino.cc.
- Connect your Arduino device to the computer using USB.
- Launch the Arduino application.
- Verify that you have the correct Arduino board selected under Tools > Board
- Verify that you have the correct COM Port selected under Tools > Port
- In the Arduino IDE, navigate to File > Examples > Firmata > StandardFirmata
- Verify that StandardFirmata will use the correct baud rate for your connection. (See note on baud rate below)
- Press “Upload” to deploy the StandardFirmata sketch to the Arduino device.
Baud Rate
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 thesetup
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 Up
You 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!- Connect the power and ground rails on the breadboard to the 5V and GND pins, respectively, on the Arduino. Using color coded wires (red and black) will make it easy to keep track of the power connections.

- Plug your bluetooth device on the breadboard and connect the VCC and GND pins to the power and ground rails, respectively, on the breadboard.

- Connect the TX-0 pin on the bluetooth device to the RX pin on the
Arduino. Similarly, connect the RX-1 pin on the bluetooth device to the
TX pin on the Arduino.


- Make sure that your code is already uploaded on the Arduino before making this connection. The Arduino Uno uses the same serial (TX and RX) pins for flashing the device, which prevents any code from being uploaded to it when another device is connected to these serial pins.
- Add
an LED to the breadboard. Note that the longer (or bent) leg is the
anode (positive) and the shorter leg is the cathode (negative).
- Connect the cathode of the LED to the ground rail of the breadboard using a 330Ω resistor. A 330Ω resistor is striped orange, orange, brown, gold as shown in the image.
- Connect the anode of the LED to any digital I/O pin on the Arduino. We are using pin 13 in the example.
- You setup is now ready! It should look similar to the setup shown in the image below.
\

Code
Download the sample repository here. If you'd prefer to create your own project, follow the project set up guide hereNow that we’re all set up, let’s get into some code!
- Create your project
.listAvailableDevicesAsync()
function on BluetoothSerial (and USBSerial) class before constructing your object.
Note for USB:
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 aDeviceInformation
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:
- Open Device Manager through the Control Panel or by pressing both Windows + Pause keys and choosing the Device Manager link on the left.
- Expand the Ports (COM & LPT) menu
- Right-click your Arduino Device and select Properties
- On the Details tab, select Hardware Ids from the drop-down menu.
- You may see multiple entries in the Value box, but any entries will have matching PID and VID.
- The entries will have the format "USB\VID_****&PID_****" where **** are the numeric ID values.
USBSerial usb = new USBSerial( "VID_2341", "PID_0043" );
is guaranteed to work only for the following hardware device:
Note for USB:
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.
- Jump over to the MainPage.xaml file and create a couple buttons that
will turn an LED on and off. You’ll notice I’ve added button callbacks
to the
Click
event & set theIsEnabled
property to false, and you’ll see why in the next step!

- I’ve implemented three functions in this step. First, the
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. - I’ve also set up the
.digitalWrite()
calls in the button callbacksOnButton_Click
andOffButton_Click

- Build and deploy! Your buttons will be enabled when the connection is established, and you can freely toggle your LED on and off at will! Here is a screenshot of this basic example running on Windows Phone 10.

I really hope you enjoy replicating this project and using it as a baseline for an incredible new set of Maker projects!
No comments:
Post a Comment