0% found this document useful (0 votes)
129 views85 pages

Getting Started With Windows Remote Arduino PDF

Uploaded by

tariq
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
129 views85 pages

Getting Started With Windows Remote Arduino PDF

Uploaded by

tariq
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
  • Preface
  • 1. Preparing Development Environment

free ebooks ==> www.ebook777.

com

[Link]
Copyright
free ebooks ==> [Link]

Getting Started with Windows Remote Arduino


Agus Kurniawan
1st Edition, 2015
Copyright © 2015 Agus Kurniawan
free ebooks ==> [Link]

Table of Contents
Copyright
Preface
1. Preparing Development Environment
1.1 Arduino
1.1.1 Arduino Uno
1.1.2 Arduino Leonardo
1.1.3 Arduino Mega 2560
1.1.4 Arduino Due
1.2 Electronics Components
1.2.1 Arduino Starter Kit
1.2.2 Fritzing
1.2.3 Cooking-Hacks: Arduino Starter Kit
1.2.4 Arduino Sidekick Basic kit v2
1.2.5 Grove - Starter Kit for Arduino
1.2.6 DFRobot - Arduino Kit for Beginner v3
1.3 Windows 10 and Visual Studio 2015
1.4 Windows Remote Arduino
1.5 Arduino Software
1.6 Testing
2. Windows Remote Arduino for Windows 10
2.1 Setting Up Arduino on Windows 10
2.1.1 Arduino Hardware Driver on Windows 10
2.1.2 Simple Testing
2.2 Arduino and Windows Remote Arduino (WRA)
2.2.1 Configuring Arduino Board
2.2.2 Compiling Windows Remote Arduino
2.3 Windows Remote Arduino with USB
2.3.1 Wiring
2.3.2 Creating A Project

[Link]
2.3.3 Adding Reference Files for Windows Remote Arduino
free ebooks ==> [Link]
2.3.4 Configuring Windows Remote Arduino (WRA) on Project
2.3.5 Writing Program
2.3.6 Testing
2.4 Windows Remote Arduino with Bluetooth
3. Digital I/O
3.1 Getting Started
3.2 Wiring
3.3 Creating and Configuring a Project
3.4 Writing a Program
3.5 Testing
4. Analog I/O
4.1 Getting Started
4.2 Demo Analog Output: RGB LED
4.2.1 Arduino Analog output (PWM)
4.2.2 Wiring
4.2.3 Writing Program
4.2.4 Testing
4.3 Demo Analog Input: Working with Potentiometer
4.3.1 Wiring
4.3.2 Writing Program
4.3.3 Testing
5. Working with I2C
5.1 Getting Started
5.2 Writing Program
5.3 Testing
6. Servo Motor
6.1 Servo Motor
6.2 Wiring
6.3 Writing A Program
6.4 Testing
free ebooks ==> [Link]
Source Code
Contact

[Link]
Preface
free ebooks ==> [Link]


This book was written to help anyone want to get started with Arduino and Windows Remote Arduino. It describes
the basic elements of the integration of Arduino and Windows Remote Arduino.


Agus Kurniawan
Depok, June 2015
free ebooks ==> [Link]
1. Preparing Development Environment

In this chapter, you will learn the following topics:

Introducing Arduino board


Introducing electronics component for testing
Introducing development tools, Visual Studio and Windows 10
Introducing Windows Remote Arduino
Introducing Arduino software

[Link]
1.1 Arduino
free ebooks ==> [Link]
Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use
hardware and software. This board uses Atmel microcontroller series. There are many
Arduino hardware models that you can use. Further information about Arduino products,
you can visit on website [Link] .
You must one Arduino hardware to follow practices in this book. I recommend to obtain
one of the following Arduino hardware:

Arduino Uno
Arduino Leonardo
Arduino Mega 2560
Arduino Due

You can buy this product on your local electronic store. You also can order it by online.
Find it on [Link] The following is the list of Arduino store you
can buy

Arduino store, [Link]


Amazon, [Link]
Cooking-hacks, [Link]
RS Components, [Link]
Element 14, [Link]
EXP-Tech, [Link]

Because Arduino is an open-source hardware, people can build it. It’s called Arduino
compatible. Generally it’s sold in low prices.

1.1.1 Arduino Uno


The Arduino Uno is a microcontroller board based on the ATmega328. You can download
the datasheet file, [Link] .
Further information about Arduino Uno, you can read it on
[Link] .
free ebooks ==> [Link]

1.1.2 Arduino Leonardo


The Arduino Leonardo is a microcontroller board based on the ATmega32u4. Download
datasheet for this product on
[Link] .
Visit this product to get the further information on
[Link] .

1.1.3 Arduino Mega 2560


The Arduino Mega 2560 is a microcontroller board based on the ATmega2560. You can
download the datasheet file on
[Link]
Further information about Arduino Mega 2560, you can visit on

[Link]
[Link] .
free ebooks ==> [Link]

1.1.4 Arduino Due


The Arduino Due is a microcontroller board based on the Atmel SAM3X8E ARM Cortex-
M3 CPU. You can download the datasheet, [Link]
If you want to know about Arduino Due, I recommend to visit this website,
[Link]
free ebooks ==> [Link]
1.2 Electronics Components
We need electronic components to build our testing, for instance, Resistor, LED, sensor
devices and etc. I recommend you can buy electronic component kit.

1.2.1 Arduino Starter Kit


Store website: [Link]

1.2.2 Fritzing
Store website: [Link] .
You can buy Fritzing Starter Kit with Arduino UNO or Fritzing Starter Kit with Arduino
Mega.

[Link]
free ebooks ==> [Link]

1.2.3 Cooking-Hacks: Arduino Starter Kit


Store website: [Link]
kits/[Link]
free ebooks ==> [Link]

1.2.4 Arduino Sidekick Basic kit v2


Store website: [Link]
[Link]
You also can find this kit on this online store.
[Link]

[Link]
free ebooks ==> [Link]
1.2.5 Grove - Starter Kit for Arduino
Another option, you can buy this kit on
Seeedstudio, [Link]
[Link] .

1.2.6 DFRobot - Arduino Kit for Beginner v3


DFRobot provides Arduino kit too. You can buy it on the following website.
[Link]
free ebooks ==> [Link]

[Link]
1.3 Windows 10 and Visual Studio 2015
free ebooks ==> [Link]
To develop app with Windows Remote Arduino, we use Visual Studio 2015 and Windows
10. Please install them for our development environment.
free ebooks ==> [Link]
1.4 Windows Remote Arduino
Windows Remote Arduino is an open-source Windows Runtime Component library which
allows Makers to control an Arduino through a Bluetooth or USB connection! It is
intended for Windows Runtime (WinRT) Developers who want to harness the power of
Arduino hardware using the Windows Runtime Languages. This library can be download
on [Link]
We will deploy and test program based Windows Remote Arduino on the next chapter.

[Link]
1.5 Arduino Software
free ebooks ==> [Link]
To develop application based on Arduino board, we need Arduino software. You can
obtain it on [Link] . Download Arduino IDE for Windows
platform.
Execute that setup file. Select all items on installation.

At the middle of installation process, you get security confirmation. Please click Install
button to install Arduino driver.

After completed installation, you can run Arduino at the first. You may get security
confirmation. Please give a permission by clicking Allow access button.
free ebooks ==> [Link]

Finally, you should see Arduino IDE.

[Link]
free ebooks ==> [Link]
free ebooks ==> [Link]
1.6 Testing
For testing, I used Arduino Uno R3 on Windows 10.

I also used Arduino Sidekick Basic kit for electronic components.

[Link]
2. Windows Remote Arduino for Windows 10
free ebooks ==> [Link]

This chapter explains how to work with Arduino and Windows 10 for getting started.
free ebooks ==> [Link]
2.1 Setting Up Arduino on Windows 10
After you installed Arduino software, you can plugin Arduino board into computer via
USB.

Then you run Arduino software. In general it will detect Arduino hardware include
Arduino type and model.

2.1.1 Arduino Hardware Driver on Windows 10


If you open Device Manager, you should see Arduino detected on Ports (COM & LPT).

[Link]
free ebooks ==> [Link]

However, if you get a problem about Arduino hardware driver, you update that driver.

You can update this device driver by navigating hardware driver on the driver folder of
Arduino software installation folder.
free ebooks ==> [Link]
2.1.2 Simple Testing
Now you’re ready to get started. For illustration, I use the sample code from Arduino,
Blink. You can visit on [Link] for configuration.
For this scenario, we use attached LED which is connected on Digital 13. Open Arduino
IDE.

On Arduino software, Click File -> Examples -> [Link] -> Blink.

[Link]
free ebooks ==> [Link]

Then you will get a sample code of Blink app.


free ebooks ==> [Link]

Now try to connect your Arduino into computer. Select Arduino Uno for board target. You
can select it by clicking menu Tools -> Board : Arduino Uno.

[Link]
free ebooks ==> [Link]
Furthermore, you must select Arduino port. Select menu Tools -> Port -> (your Arduino
port which already connected).

Now you can compile and upload this program into Arduino board.

If success, you should see blinking LED on Arduino board.


free ebooks ==> [Link]

[Link]
2.2 Arduino and Windows Remote Arduino (WRA)
free ebooks ==> [Link]
To communicate between Arduino and computer/tablet/embedded board based Windows
10, we can use Windows Remote Arduino. There are two types of connectivity for
Windows Remote Arduino:

Serial port (USB)


Bluetooth

I will explain them on the next section. Now we must configure Arduino board and
computer to establish a connection.

2.2.1 Configuring Arduino Board


To work with Windows Remote Arduino, we must configure Arduino board to be
deployed Firmata library. Firmata is a protocol for communicating with microcontrollers
from software on a computer (or smartphone/tablet, etc). The protocol can be
implemented in firmware on any microcontroller architecture as well as software on any
computer software package. Further information about Firmata, you can read it
on [Link] .
To deploy Firmata into Arduino board, you do it opening Arduino IDE. Select menu File -
> Examples -> Firmata -> StandardFirmata.
free ebooks ==> [Link]

Then, you will get Firmata code on Arduino IDE.

[Link]
free ebooks ==> [Link]
By default, Firmata on Arduino uses a baud rate 57600. You can change it according to
your serial port (USB) or Bluetooth, for instance, 115200. After that, please compile and
upload this program into Arduino board.

Finally, Arduino board is ready for running with Firmata protocol.

2.2.2 Compiling Windows Remote Arduino


The next step is to compile Windows Remote Arduino library. You can download it
on [Link] It provides library for Windows 10 and
Windows 8.1. Open for Solution file (*.sln) for Windows 10 using Visual Studio 2015.
free ebooks ==> [Link]

Compile these libraries for ARM, x86, and x64 targets.


If finished, you should see the compiled files. Compiled ARM, x64, and x86 targets will
generate ARM, x64 and Debug folders.

[Link]
2.3 Windows Remote Arduino with USB
free ebooks ==> [Link]
In this section, we build a blinking LED program via USB using Windows Universal app.
The USB usage is applied as a bridge to remote Arduino board.
Our scenario needs the following items:

Three LEDs
USB cable
Jumper cables

To build the program, you can do the following steps:

Wiring
Creating a project
Adding reference files for Windows Remote Arduino
Configuring Windows Remote Arduino on project
Writing program
Testing

Let’s start!

2.3.1 Wiring
Connect three LEDs on Digital 12, 11, 10. Other LED pins are be connected to GND.
Now you connect Arduino board to Computer via USB cable.
free ebooks ==> [Link]

2.3.2 Creating A Project


Open Visual Studio 2015. Create a new project with template Blank App (Windows
Universal). It’s located on Visual C# -> Windows -> Windows Universal.
Fill the project name, called BlinkingLed.

[Link]
free
If done, click OK button. ebooks ==> [Link]

2.3.3 Adding Reference Files for Windows Remote Arduino


The next step is to add Windows Remote Arduino into our project. Firstly, add Microsoft
Visual C++ AppLocal Runtime from Windows Universal -> Extensions.

Then, we add our compiled files from Windows Remote Arduino (read section 2.2.2).
Add the following files (depend on your target: ARM, x64, x86):

[Link]
[Link]
[Link]
free ebooks ==> [Link]

Click OK button if finished.


Finally, you should see our referenced files on our project.

[Link]
free ebooks ==> [Link]

2.3.4 Configuring Windows Remote Arduino (WRA) on


Project
After added WRA Reference files, we must configure project config file and activate USB
capability on app.
To configure project config file (*.csproj) , you just unload the project (not solution). Or
you edit project file (*.csproj) directly.
Add this script into <Reference Include “[Link]”></Reference> tag
<IsWinMDFile>true</IsWinMDFile>
<Implementation>[Link]</Implementation>

Add this script into<Reference Include=“[Link]”></Reference>


tag
<IsWinMDFile>true</IsWinMDFile>
free ebooks ==> [Link]
<Implementation>[Link]</Implementation>

Add this script into<Reference Include=“[Link]”></Reference> tag


<IsWinMDFile>true</IsWinMDFile>
<Implementation>[Link]</Implementation>

You also need to configure [Link] file to enable Serial port capability.
Open [Link] file and add the following script on <Capabilities>
</Capabilities> tag.
<DeviceCapability Name="serialcommunication">
<Device Id="any">
<Function Type="name:serialPort"/>
</Device>
</DeviceCapability>

[Link]
free ebooks ==> [Link]

2.3.5 Writing Program


Now we develop UI on XAML. We modify [Link] file and build the following
UI.
free ebooks ==> [Link]

We need three CheckBox, a TextBlock and a Button. The following is a script of


[Link].
<Page
x:Class="[Link]"
xmlns="[Link]
xmlns:x="[Link]
xmlns:local="using:BlinkingLed"
xmlns:d="[Link]
xmlns:mc="[Link]
mc:Ignorable="d">

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"


<CheckBox x:Name="chkLed1" Content="LED 1" Checked="HandleCheck"
<CheckBox x:Name="chkLed2" Content="LED 2" Checked="HandleCheck"
<CheckBox x:Name="chkLed3" Content="LED 3" Checked="HandleCheck"
<TextBlock x:Name="txtStatus" HorizontalAlignment="Left" Margin=
<Button x:Name="btnClose" Content="Turn Off All LEDs" HorizontalAlignm

</Grid>
</Page>

[Link]
free ebooks ==> [Link]

On [Link], we modify this code. Firstly, we add our namespace.


using [Link];
using [Link];

Then, we declare some variables.


private UsbSerial connection;
private RemoteDevice arduino;
private const byte LED1 = 12;
private const byte LED2 = 11;
private const byte LED3 = 10;

LED 1, 2, 3 are connected to Digital 12, 11, and 10 on Arduino.


We define InitWRA() method and subscribe ConnectionEstablished event. We set pin
mode using pinMode() method.
private void InitWRA()
{
connection = new UsbSerial("VID_2341", "PID_0043");
arduino = new RemoteDevice(connection);

[Link] += Connection_ConnectionEstablish
[Link](57600, SerialConfig.SERIAL_8N1);

private void Connection_ConnectionEstablished()


{
[Link](LED1, [Link]);
[Link](LED2, [Link]);
[Link](LED3, [Link]);

[Link] = "Connected";
free ebooks ==> [Link]
}

You can see parameters on UsbSerial(). These values can be obtained from SerialPort
(USB) property which Arduino board is connected. For instance, My Arduino is
connected to COM3. You can open COM property from Device Manager.

We handle CheckBox checked or unchecked in HandleCheck() and HandleUnchecked()


methods. If it checked, we turn on LED. Otherwise, we turn off LED.
private void HandleCheck(object sender, RoutedEventArgs e)
{
CheckBox cb = sender as CheckBox;
if([Link]== "chkLed1")
{
[Link](LED1, [Link]);
}
if ([Link] == "chkLed2")
{
[Link](LED2, [Link]);
}
if ([Link] == "chkLed3")
{
[Link](LED3, [Link]);
}

}

[Link]
private void HandleUnchecked(object sender, RoutedEventArgs e)
{
free ebooks ==> [Link]
CheckBox cb = sender as CheckBox;
if ([Link] == "chkLed1")
{
[Link](LED1, [Link]);
}
if ([Link] == "chkLed2")
{
[Link](LED2, [Link]);
}
if ([Link] == "chkLed3")
{
[Link](LED3, [Link]);
}
}

We also declare TurnOffLeds() to turn off LEDs. This is connected to button clicked
event.
private void TurnOffLeds(object sender, RoutedEventArgs e)
{
[Link] = false;
[Link] = false;
[Link] = false;
}

Finally, on class constructor, we call InitWRA() method.


public MainPage()
{
[Link]();

[Link] += MainPage_Unloaded;

InitWRA();
}

private void MainPage_Unloaded(object sender, RoutedEventArgs e)


{
[Link]();
}

2.3.6 Testing
Run this program. If success, you can see our program UI. Try to do checked on
CheckBoxs. Then, you should see lighting LED.
free ebooks ==> [Link]

[Link]
2.4 Windows Remote Arduino with Bluetooth
free ebooks ==> [Link]
WRA also support using Bluetooth to remote Arduino. You can use Bluetooth module
from SparkFun Bluetooth Mate Silver, [Link] .
Don’t forget to modify Firmata code on Arduino about baud rate.

Just connect your Bluetooth module on Tx and Rx from Arduino. Then, pair Bluetooth
module on Arduino to Bluetooth PC. Add Bluetooth capability on [Link]
file.
<DeviceCapability Name="[Link]">
<Device Id="any">
<Function Type="name:serialPort"/>
</Device>
</DeviceCapability>

On our program, we change UsbSerial to BluetoothSerial object.


private UsbSerial connection;
private RemoteDevice arduino;
free ebooks ==> [Link]
...

private BluetoothSerial connection;


private RemoteDevice arduino;

On instantiate stage, you just construct connection object with BluetoothSerial() with
passing Bluetooth name.
connection = new BluetoothSerial("MyBluetooth");
[Link] += Connection_ConnectionFailed;
arduino = new RemoteDevice(connection);

[Link] += Connection_ConnectionEstablish
[Link](115200, 0);

Just it!
Now you can program as usual with RemoteDevice object.

[Link]
3. Digital I/O
free ebooks ==> [Link]

In this chapter I’m going to explain how to remote Arduino Digital I/O using WRA.
free ebooks ==> [Link]
3.1 Getting Started
In this chapter, we learn how to access Arduino digital I/O via Windows Remote Arduino.
Our scenario is to use a pushbutton and LED. If pushbutton is pressed, LED will lighting.
You can find a pushbutton on the following online store:

Sparkfun, [Link]
Adafruit, [Link]
eBay, [Link]

In this scenario, I use USB as bridge to Arduino. You can replace it by Bluetooth.
Let’s start!.

[Link]
3.2 Wiring
free ebooks ==> [Link]
Connect LED to Digital 12 on Arduino and pushbutton to Digital 11. The following is a
sample of wiring.
free ebooks ==> [Link]
3.3 Creating and Configuring a Project
Create a new project, called DigitalIoDemo. Follow instructions to create and configure
the project as explained on section 2.3.2, 2.3.3 and 2.3.4.

[Link]
3.4 Writing a Program
free ebooks ==> [Link]
We modify [Link]. Add the following namespace.
using [Link];
using [Link];

Define some variables for LED and pushbutton.


private UsbSerial connection;
private RemoteDevice arduino;
private const byte LED = 12;
private const byte PUSHBUTTON = 11;

We define InitWRA() to initialize WRA. Then, we subscribe DigitalPunUpdateEvent


event. We update a state on LED from pushbutton state.
private void InitWRA()
{
connection = new UsbSerial("VID_2341", "PID_0043");
arduino = new RemoteDevice(connection);

[Link] += Connection_ConnectionEstablish
[Link](57600, SerialConfig.SERIAL_8N1);

private void Connection_ConnectionEstablished()


{
[Link]("Connected");

[Link](LED, [Link]);
[Link](PUSHBUTTON, [Link]);

[Link] += Arduino_DigitalPinUpdatedEvent;

private void Arduino_DigitalPinUpdatedEvent(byte pin, PinState state)


{
if(pin==PUSHBUTTON)
{
[Link](LED, state);
}
}

Finally, we call InitWRA() method on class constructor.


public MainPage()
free ebooks ==> [Link]
{
[Link]();
[Link] += MainPage_Unloaded;

InitWRA();
}

private void MainPage_Unloaded(object sender, RoutedEventArgs e)


{
[Link]();
}

Save this code.

[Link]
3.5 Testing
free ebooks ==> [Link]
Now you can compile and run this program. For testing, try to press pushbutton. You
should see a lighting LED.
free ebooks ==> [Link]
4. Analog I/O

This chapter explains how to work with Arduino Analog I/O via WRA.

[Link]
4.1 Getting Started
free ebooks ==> [Link]
Arduino board provides Analog I/O which can be connected to sensor or actuator devices.
In this chapter, we try to access Arduino Analog I/O using Windows Remote Arduino.
There are two scenarios for our cases:

Controlling RGB LED


Reading Analog input using Potentiometer

All scenarios use USB for connectivity between Arduino and PC.
Let’s start.
free ebooks ==> [Link]
4.2 Demo Analog Output: RGB LED
In this scenario we build a Windows Universal application to control RGB LED color
using Arduino Analog output (PWM). RGB LED has 4 pins that you can see it on Figure
below.

To understand these pins, you can see the following Figure.

Note:

Pin 1: Red

[Link]
Pin 2: Common pin
Pin 3: Green free ebooks ==> [Link]
Pin 4: Blue

Now we can start to build a Windows Universal application and hardware


implementation.

4.2.1 Arduino Analog output (PWM)


Please be careful if you want to work with Arduino PWM. If you have Arduino Mega, you
will see PWM label so you obtain PWM pins easily but if you have Arduino Uno, it writes
DIGITAL (PWM ~). It means your PWM pins can be found on DIGITAL pins which pin
with ~, for instance, ~3,~5,~6,~9, ~10, ~11.
For Arduino Mega 2560, you can see PWM pins on picture below (see red arrow).

For Arduino Uno R3, you can see PWM pins as below.
free ebooks ==> [Link]

4.2.2 Wiring
For our testing, we configure the following PWM pins.
Arduino Mega 2560:

RGB LED pin 1 (red) is connected to Arduino PWM pin 4


RGB LED pin 2 is connected to Arduino VCC 5V
RGB LED pin 3 (green) is connected to Arduino PWM pin 3
RGB LED pin 4 (blue) is connected to Arduino PWM pin 2

Arduino Uno R3:

RGB LED pin 1 (red) is connected to Arduino PWM pin 9


RGB LED pin 2 is connected to Arduino VCC 5V
RGB LED pin 3 (green) is connected to Arduino PWM pin 10
RGB LED pin 4 (blue) is connected to Arduino PWM pin 11

Here is a sample implementation with Arduino Uno R3.

[Link]
free ebooks ==> [Link]

4.2.3 Writing Program


Firstly, create a new project, called RGBDemo. Follow instructions to create and
configure the project as explained on section 2.3.2, 2.3.3 and 2.3.4.
Now we modify [Link] file. Add these namespace.
using [Link];
using [Link];

Declare some variables.


private UsbSerial connection;
private RemoteDevice arduino;
private const byte RED = 9;
private const byte GREEN = 10;
private const byte BLUE = 11;
private DispatcherTimer timer;
private int index = 1;

We define InitMRA(), SetColor() and ColorDemo() methods.


free ebooks ==> [Link]
private void InitWRA()
{
connection = new UsbSerial("VID_2341", "PID_0043");
arduino = new RemoteDevice(connection);

[Link] += Connection_ConnectionEstablish
[Link](57600, SerialConfig.SERIAL_8N1);

}
private void SetColor(ushort red, ushort green, ushort blue)
{
[Link](RED, red);
[Link](GREEN, green);
[Link](BLUE, blue);
}

private void ColorDemo(int index)


{
if(index==1)
SetColor(255, 0, 0); // red
if (index == 2)
SetColor(0, 255, 0); // green
if (index == 3)
SetColor(0, 0, 255); // blue
if (index == 4)
SetColor(255, 255, 0); // yellow
if (index == 5)
SetColor(80, 0, 80); // purple
if (index == 6)
SetColor(0, 255, 255); // aqua

A timer is used to running our RGB LED which consists of 6 color demo by calling
ColorDemo().
private void Connection_ConnectionEstablished()
{
[Link]("Connected");

[Link](RED, [Link]);
[Link](GREEN, [Link]);
[Link](BLUE, [Link]);

index = 1;
timer = new DispatcherTimer();
[Link] = [Link](500);
[Link] += Timer_Tick;
[Link]();

[Link]
private void Timer_Tick(object sender, object e)
{
free ebooks ==> [Link]
ColorDemo(index);
index++;
if (index > 6)
index = 1;

We call InitWRA() method on class constructor


public MainPage()
{
[Link]();
[Link] += MainPage_Unloaded;

InitWRA();
}
private void MainPage_Unloaded(object sender, RoutedEventArgs e)
{
[Link]();
}

4.2.4 Testing
Compile and run the program. You should see several color on RGB LED.
The following is a sample demo on RGB LED.
free ebooks ==> [Link]

[Link]
4.3 Demo Analog Input: Working with Potentiometer
free ebooks ==> [Link]
In this section, we learn how to read analog input on Arduino board. For illustration, I use
Potentiometer as analog input source. Our scenario is to read analog value from
Potentiometer. Then, display it on app UI.
Let’s start!.

4.3.1 Wiring
To understand Potentiometer, you see its scheme in Figure below.

You can connect VCC to Arduino board VCC 5V. Vout to Arduino board Analog input
A0. In addition, GND to Arduino board GND. The following is hardware implementation.
I use slide potentiometer.
free ebooks ==> [Link]

4.3.2 Writing Program


Firstly, create a new project, called RGBDemo. Follow instructions to create and
configure the project as explained on section 2.3.2, 2.3.3 and 2.3.4.
The first step is to develop app UI on [Link]. We add two TextBlock. One of
TextBlock will be used to display Analog value. The following is complete code for
[Link] file.
<Page
x:Class="[Link]"
xmlns="[Link]
xmlns:x="[Link]
xmlns:local="using:PotDemo"
xmlns:d="[Link]
xmlns:mc="[Link]
mc:Ignorable="d">

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"


<TextBlock x:Name="textBlock" HorizontalAlignment="Left" Margin=
<TextBlock x:Name="txtVal" HorizontalAlignment="Left" Margin="80,28,0,

</Grid>
</Page>

Now we modify [Link] file. Add these namespace.

[Link]
using [Link];
using [Link];
free ebooks ==> [Link]
using [Link];

We declare some variables for our app.


private UsbSerial connection;
private RemoteDevice arduino;
private const byte NUM_DIGITAL_PINS = 14; // Arduino Uno
private const byte POT = 0;

We define InitWRA() method and subscribe ConnectionEstablished event. On this event,


we subscribe AnalogPinUpdateEvent event. On AnalogPinUpdateEvent event, we update
TextBlock UI. Because we update UI from other thread, we use [Link]().
We define UpdateDate().
private void InitWRA()
{
connection = new UsbSerial("VID_2341", "PID_0043");
arduino = new RemoteDevice(connection);

[Link] += Connection_ConnectionEstablished;
[Link](57600, SerialConfig.SERIAL_8N1);

private void Connection_ConnectionEstablished()


{
[Link]("Connected");
[Link](NUM_DIGITAL_PINS + POT, [Link]);

var val = [Link](NUM_DIGITAL_PINS + POT);


[Link] = [Link](val);
[Link] += Arduino_AnalogPinUpdatedEvent;

}
private async void UpdateData(ushort value)
{
await [Link](Windows.
() =>
{
[Link] = [Link](value);
});
}

private void Arduino_AnalogPinUpdatedEvent(byte pin, ushort value)


{
if (pin == POT)
{
UpdateData(value);
free ebooks ==> [Link]
}
}

Finally, we call InitWRA() on class constructor.


public MainPage()
{
[Link]();
[Link] += MainPage_Unloaded;
InitWRA();
}

private void MainPage_Unloaded(object sender, RoutedEventArgs e)


{
[Link]();
}

Save this code.

4.3.3 Testing
Compile and run this program. If success, you can see analog value on UI.

[Link]
5. Working with I2C
free ebooks ==> [Link]

In this chapter we learn how to work with I2C using Windows Remote Arduino.
free ebooks ==> [Link]
5.1 Getting Started
The I2C (Inter-Integrated Circuit) bus was designed by Philips in the early ’80s to allow
easy communication between components which reside on the same circuit board. TWI
stands for Two Wire Interface and for most marts this bus is identical to I²C. The name
TWI was introduced by Atmel and other companies to avoid conflicts with trademark
issues related to I²C.
I2C bus consists of two wires, SDA (Serial Data Line) and SCL (Serial Clock Line).
Arduino Uno has I2C/TWI on Analog A4 (SDA) and Analog A5 (SCL).
For testing, I used PCF8591 AD/DA Converter module with sensor and actuator devices.
You can find it on the following online store:

Amazon, [Link]
Conversion/dp/B00BXX4UWC/
eBay, [Link]
Dealextreme, [Link]
analog-converter-module-w-dupont-cable-deep-blue-336384
Aliexpress, [Link]

In addition, you can find this device on your local electronics store/online store.

[Link]
This module has mini form model too, for instance, you can find it on Amazon,
free ebooks ==> [Link]
[Link]
Development/dp/B00KM6X2OI/ .

This module use PCF8591 IC and you can read the datasheet on the following URLs.

[Link]
[Link]

The following is our wiring lab:

PCF8591 AD/DA SDA —> Arduino Analog A4 (SDA)


PCF8591 AD/DA SCL —> Arduino Analog A5 (SCL)
PCF8591 AD/DA GND —> Arduino GND
PCF8591 AD/DA VCC —> Arduino VCC +3.3V

Hardware implementation can be shown in Figure below.


free ebooks ==> [Link]

[Link]
5.2 Writing Program
free ebooks ==> [Link]
Firstly, create a new project, called I2CDemo. Follow instructions to create and configure
the project as explained on section 2.3.2, 2.3.3 and 2.3.4.
The first step is to develop app UI on [Link]. We add six TextBlock to display
Analog values. The following is complete code for [Link] file.
<Page
x:Class="[Link]"
xmlns="[Link]
xmlns:x="[Link]
xmlns:local="using:I2CDemo"
xmlns:d="[Link]
xmlns:mc="[Link]
mc:Ignorable="d">

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"


<TextBlock x:Name="textBlock" HorizontalAlignment="Left" Margin=
<TextBlock x:Name="textBlock1" HorizontalAlignment="Left" Margin=
<TextBlock x:Name="textBlock2" HorizontalAlignment="Left" Margin=
<TextBlock x:Name="txtThermistor" HorizontalAlignment="Left" Margin=
<TextBlock x:Name="txtPhoto" HorizontalAlignment="Left" Margin="163,77
<TextBlock x:Name="txtPot" HorizontalAlignment="Left" Margin="163,102,

</Grid>
</Page>

The next step is to modify [Link] file. Firstly, we add our namespace.
free ebooks ==> [Link]
using [Link];
using [Link];
using [Link];
using [Link];

Declare some variables. PCF8591 uses I2C address on 0x90. To get Thermistor value, we
send a command 0x40. Photo-voltaic value can be acquired by sending a command 0x41.
The last, Potentiometer, can be acquired using 0x43 command.
private UsbSerial connection;
private RemoteDevice arduino;
private const byte NUM_DIGITAL_PINS = 14; // Arduino Uno
private const byte SDA = 4;
private const byte SCL = 5;
private const byte PCF8591 = (0x90 >> 1); // Device address
private const byte PCF8591_ADC_CH0 = 0x40; // thermistor
private const byte PCF8591_ADC_CH1 = 0x41; // photo-voltaic cell
private const byte PCF8591_ADC_CH2 = 0x42;
private const byte PCF8591_ADC_CH3 = 0x43; // potentiometer
private int index = 0;
private Queue<int> i2cReading = new Queue<int>();

private DispatcherTimer timer;

We define InitWRA() method and subscribe ConnectionEstablished event. On this event,


we subscribe I2cReplyEvent event. On I2cReplyEvent event, we update TextBlock UI.
Because we update UI from other thread, we use [Link](). We define
UpdateDate().
private void InitWRA()
{
connection = new UsbSerial("VID_2341", "PID_0043");
arduino = new RemoteDevice(connection);

[Link] += Connection_ConnectionEstablish
[Link](57600, SerialConfig.SERIAL_8N1);

private void Connection_ConnectionEstablished()


{
[Link]("Connected");
[Link](NUM_DIGITAL_PINS + SDA, PinMode.I2C);
[Link](NUM_DIGITAL_PINS + SCL, PinMode.I2C);

index = 0;
arduino.I2c.I2cReplyEvent += I2c_I2cReplyEvent;

timer = new DispatcherTimer();
[Link] = [Link](2000);

[Link]
[Link] += Timer_Tick;
[Link]();
free ebooks ==> [Link]
}

private void I2c_I2cReplyEvent(byte address_, string response)


{
byte[] data = [Link](response);
int curr = [Link]();
UpdateData(curr, data[1]);
[Link]("" + [Link](address_)
}

On Tick event from Timer object, we read analog values from PCF8591. Then, we define
UpdateData() to update app UI.
private void Timer_Tick(object sender, object e)
{
switch (index)
{
case 0:
[Link](index);
[Link]("PCF8591_ADC_CH0"
ReadADC(PCF8591_ADC_CH0);
break;
case 1:
[Link](index);
[Link]("PCF8591_ADC_CH1"
ReadADC(PCF8591_ADC_CH1);
break;
case 2:
[Link](index);
[Link]("PCF8591_ADC_CH2"
ReadADC(PCF8591_ADC_CH2);
break;

}
index++;
if (index > 2)
index = 0;

void ReadADC(byte config)


{
[Link]();
[Link](PCF8591, "" + (char)config);
[Link](PCF8591,2);
[Link](PCF8591);
}
free ebooks ==> [Link]
private async void UpdateData(int index, byte value)
{
await [Link](Wind
() =>
{
switch(index)
{
case 0:
[Link] = [Link](value
break;
case 1:
[Link] = [Link](value);
break;
case 2:
[Link] = [Link](value);
break;
}
});
}

Finally, we call InitWRA() on class constructor.


public MainPage()
{
[Link]();
[Link] += MainPage_Unloaded;

InitWRA();
}

private void MainPage_Unloaded(object sender, RoutedEventArgs e)


{
[Link]();
[Link]();
}

Save this code.

[Link]
5.3 Testing
free ebooks ==> [Link]
Now you can compile and run the program.
If success, you can see sensor values via I2C on app UI. The following is a sample output.
free ebooks ==> [Link]
6. Servo Motor

This chapter explains how to work with servo motor connected to Arduino board using
Windows Remote Arduino. We explore how to access PWM (Pulse Width Modulation)
Arduino.

[Link]
6.1 Servo Motor
free ebooks ==> [Link]
Servo motor provides a shaft movement 360 degree. We can control this movement based
on its degree. In this scenario, you can use any DC motor (servo) that will be connected to
Arduino. I used a mini servo from Arduino Sidekick Basic kit.
The following is a picture of my mini servo motor.

To understand servo’s cables, you can identify as follows:

Red cable is be connected to 5V


Black or brown cable is be connected to GND
The rest (yellow or orange cable) is be connected to Arduino PWM pin

The next step we are going to build a Windows Universal with Arduino and servo motor.
free ebooks ==> [Link]
6.2 Wiring
To build hardware implementation, you can connect servo motor to Arduino by following
configuration:

Red cable is be connected to 5V


Black or brown cable is be connected to GND
The rest (yellow or orange cable) is be connected to Arduino PWM pin. I used pin 10
for Arduino Uno R3 or Arduino Mega 2560

The following is a sample of hardware implementation.

[Link]
6.3 Writing A Program
free ebooks ==> [Link]
Firstly, create a new project, called ServoMotor. Follow instructions to create and
configure the project as explained on section 2.3.2, 2.3.3 and 2.3.4.
The first step is to develop app UI on [Link]. We add two TextBlock to display
servo motor angle. The following is complete code for [Link] file.
<Page
x:Class="[Link]"
xmlns="[Link]
xmlns:x="[Link]
xmlns:local="using:ServoMotor"
xmlns:d="[Link]
xmlns:mc="[Link]
mc:Ignorable="d">

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"


<TextBlock x:Name="textBlock" HorizontalAlignment="Left" Margin=
<TextBlock x:Name="txtVal" HorizontalAlignment="Left" Margin="151,49,0

</Grid>
</Page>

The next step is to modify [Link] file. Firstly, we add our namespace.
using [Link];
using [Link];
using [Link];
using [Link];
free ebooks ==> [Link]

Declare some variables. Servo motor uses PWM Digital 10. We also define a list of angle:
0, 30, 60, 90, 120, 150 and 180.
private UsbSerial connection;
private RemoteDevice arduino;
private const byte SERVO = 10;
private byte[] angles = new byte[] { 0, 30, 60, 90, 120, 150, 180
private int direction;
private bool fwd;
private DispatcherTimer timer;

We define InitWRA() method and subscribe ConnectionEstablished event. On this event,


we call a timer.
private void InitWRA()
{
connection = new UsbSerial("VID_2341", "PID_0043");
arduino = new RemoteDevice(connection);

[Link] += Connection_ConnectionEstablish
[Link](57600, SerialConfig.SERIAL_8N1);

private void Connection_ConnectionEstablished()


{
[Link]("Connected");
[Link](SERVO, [Link]);

direction = 1;
fwd = true;
timer = new DispatcherTimer();
[Link] = [Link](2000);
[Link] += Timer_Tick;
[Link]();

On Tick event from Timer object, we read change servo motor angle. Then, we define
UpdateData() to update app UI.
private void Timer_Tick(object sender, object e)
{
[Link]("Dir " + [Link]() +
UpdateData(angles[direction]);
[Link](SERVO, angles[direction]);

if(fwd)

[Link]
direction++;
else
free ebooks ==>
direction--;
[Link]

if (direction > 6)
{
fwd = false;
direction = 6;
}
else
if (direction < 0)
{
fwd = true;
direction = 0;
}

}

private async void UpdateData(byte value)


{
await [Link](Wind
() =>
{
[Link] = [Link](value);
});
}

Finally, we call InitWRA() on class constructor.


public MainPage()
{
[Link]();
[Link] += MainPage_Unloaded;

InitWRA();
}
private void MainPage_Unloaded(object sender, RoutedEventArgs e)
{
[Link]();
[Link]();
}

Save this code.


free ebooks ==> [Link]
6.4 Testing
Compile and run the program. You should see servo motor is moving from angle with
incrementing angle 30. A sample output on app UI can be seen on Figure below.

Output program on debug mode also can be seen on Figure below.

[Link]
Source Code
free ebooks ==> [Link]

You can download source code on


[Link] .
free ebooks ==> [Link]
Contact

If you have question related to this book, please contact me at aguskur@[Link] . My


blog: [Link]

[Link]

free ebooks ==>   www.ebook777.com (http://www.ebook777.com)
www.ebook777.com
free ebooks ==>   www.ebook777.com
Copyright
Getting Started with Windows Remote Arduino
Agus Kurniawan
1st Edition, 2015
Cop
free ebooks ==>   www.ebook777.com (http://www.ebook777.com)
Table of Contents
Copyright
Preface
1. Preparing Development Env
free ebooks ==>   www.ebook777.com
2.3.3 Adding Reference Files for Windows Remote Arduino
2.3.4 Configuring Windows Remote A
free ebooks ==>   www.ebook777.com (http://www.ebook777.com)
Source Code
Contact
www.ebook777.com
free ebooks ==>   www.ebook777.com
Preface
 
 
This book was written to help anyone want to get started with Arduino and Wind
free ebooks ==>   www.ebook777.com (http://www.ebook777.com)
1. Preparing Development Environment
In this chapter, you will l
free ebooks ==>   www.ebook777.com
1.1 Arduino
Arduino is an open-source electronics prototyping platform based on flexible,
free ebooks ==>   www.ebook777.com (http://www.ebook777.com)
1.1.2 Arduino Leonardo
The Arduino Leonardo is a microcontroller
free ebooks ==>   www.ebook777.com
http://arduino.cc/en/Main/ArduinoBoardMega2560 .
1.1.4 Arduino Due
The Arduino Due is a mi

You might also like