Академический Документы
Профессиональный Документы
Культура Документы
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
Source Code
Contact
Preface
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
1.1 Arduino
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 http://arduino.cc/en/ .
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 http://arduino.cc/en/Main/Buy. The following is the list of Arduino store you
can buy
Arduino store, http://store.arduino.cc/
Amazon, http://www.amazon.com
Cooking-hacks, http://www.cooking-hacks.com/index.php/shop/arduino.html
RS Components, http://www.rs-components.com
Element 14, http://www.element14.com
EXP-Tech, http://www.exp-tech.de
Because Arduino is an open-source hardware, people can build it. Its called Arduino
compatible. Generally its sold in low prices.
http://arduino.cc/en/Main/ArduinoBoardMega2560 .
1.2.2 Fritzing
Store website: http://shop.fritzing.org/ .
You can buy Fritzing Starter Kit with Arduino UNO or Fritzing Starter Kit with Arduino
Mega.
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.
1.6 Testing
For testing, I used Arduino Uno R3 on Windows 10.
This chapter explains how to work with Arduino and Windows 10 for getting started.
Then you run Arduino software. In general it will detect Arduino hardware include
Arduino type and model.
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.
On Arduino software, Click File -> Examples -> 01.Basics -> Blink.
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.
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.
I will explain them on the next section. Now we must configure Arduino board and
computer to establish a connection.
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.
Lets 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.
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):
Microsoft.Maker.RemoteWiring.winmd
Microsoft.Maker.Firmata.winmd
Microsoft.Maker.Serial.winmd
<Implementation>Microsoft.Maker.RemoteWiring.dll</Implementation>
You also need to configure Package.appxmanifest file to enable Serial port capability.
Open Package.appxmanifest file and add the following script on <Capabilities>
</Capabilities> tag.
<DeviceCapability Name="serialcommunication">
<Device Id="any">
<Function Type="name:serialPort"/>
</Device>
</DeviceCapability>
connection.ConnectionEstablished += Connection_ConnectionEstablish
connection.begin(57600, SerialConfig.SERIAL_8N1);
}
private void Connection_ConnectionEstablished()
{
arduino.pinMode(LED1, PinMode.OUTPUT);
arduino.pinMode(LED2, PinMode.OUTPUT);
arduino.pinMode(LED3, PinMode.OUTPUT);
txtStatus.Text = "Connected";
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 also declare TurnOffLeds() to turn off LEDs. This is connected to button clicked
event.
private void TurnOffLeds(object sender, RoutedEventArgs e)
{
chkLed1.IsChecked = false;
chkLed2.IsChecked = false;
chkLed3.IsChecked = false;
}
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.
Just connect your Bluetooth module on Tx and Rx from Arduino. Then, pair Bluetooth
module on Arduino to Bluetooth PC. Add Bluetooth capability on Package.appxmanifest
file.
<DeviceCapability Name="bluetooth.rfcomm">
<Device Id="any">
<Function Type="name:serialPort"/>
</Device>
</DeviceCapability>
...
private BluetoothSerial connection;
private RemoteDevice arduino;
On instantiate stage, you just construct connection object with BluetoothSerial() with
passing Bluetooth name.
connection = new BluetoothSerial("MyBluetooth");
connection.ConnectionFailed += Connection_ConnectionFailed;
arduino = new RemoteDevice(connection);
connection.ConnectionEstablished += Connection_ConnectionEstablish
connection.begin(115200, 0);
Just it!
Now you can program as usual with RemoteDevice object.
3. Digital I/O
In this chapter Im going to explain how to remote Arduino Digital I/O using WRA.
In this scenario, I use USB as bridge to Arduino. You can replace it by Bluetooth.
Lets start!.
3.2 Wiring
Connect LED to Digital 12 on Arduino and pushbutton to Digital 11. The following is a
sample of wiring.
connection.ConnectionEstablished += Connection_ConnectionEstablish
connection.begin(57600, SerialConfig.SERIAL_8N1);
}
private void Connection_ConnectionEstablished()
{
System.Diagnostics.Debug.WriteLine("Connected");
arduino.pinMode(LED, PinMode.OUTPUT);
arduino.pinMode(PUSHBUTTON, PinMode.INPUT);
arduino.DigitalPinUpdatedEvent += Arduino_DigitalPinUpdatedEvent;
}
private void Arduino_DigitalPinUpdatedEvent(byte pin, PinState state)
{
if(pin==PUSHBUTTON)
{
arduino.digitalWrite(LED, state);
}
}
{
this.InitializeComponent();
this.Unloaded += MainPage_Unloaded;
InitWRA();
}
private void MainPage_Unloaded(object sender, RoutedEventArgs e)
{
arduino.Dispose();
}
3.5 Testing
Now you can compile and run this program. For testing, try to press pushbutton. You
should see a lighting LED.
4. Analog I/O
This chapter explains how to work with Arduino Analog I/O via WRA.
All scenarios use USB for connectivity between Arduino and PC.
Lets start.
Note:
Pin 1: Red
For Arduino Uno R3, you can see PWM pins as below.
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
connection.ConnectionEstablished += Connection_ConnectionEstablish
connection.begin(57600, SerialConfig.SERIAL_8N1);
}
private void SetColor(ushort red, ushort green, ushort blue)
{
arduino.analogWrite(RED, red);
arduino.analogWrite(GREEN, green);
arduino.analogWrite(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()
{
System.Diagnostics.Debug.WriteLine("Connected");
arduino.pinMode(RED, PinMode.PWM);
arduino.pinMode(GREEN, PinMode.PWM);
arduino.pinMode(BLUE, PinMode.PWM);
index = 1;
timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromMilliseconds(500);
timer.Tick += Timer_Tick;
timer.Start();
}
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.
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.
using Windows.ApplicationModel.Core;
using Microsoft.Maker.Serial;
using Microsoft.Maker.RemoteWiring;
}
private async void UpdateData(ushort value)
{
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.
() =>
{
txtVal.Text = Convert.ToString(value);
});
}
private void Arduino_AnalogPinUpdatedEvent(byte pin, ushort value)
{
if (pin == POT)
{
UpdateData(value);
}
}
4.3.3 Testing
Compile and run this program. If success, you can see analog value on UI.
In this chapter we learn how to work with I2C using Windows Remote Arduino.
In addition, you can find this device on your local electronics store/online store.
This module has mini form model too, for instance, you can find it on Amazon,
http://www.amazon.com/WaveShare-PCF8591T-Converter-EvaluationDevelopment/dp/B00KM6X2OI/ .
This module use PCF8591 IC and you can read the datasheet on the following URLs.
http://www.electrodragon.com/w/images/e/ed/PCF8591.pdf
http://www.nxp.com/documents/data_sheet/PCF8591.pdf
The next step is to modify MainPage.xaml.cs file. Firstly, we add our namespace.
using System.Text;
using Windows.ApplicationModel.Core;
using Microsoft.Maker.Serial;
using Microsoft.Maker.RemoteWiring;
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;
connection.ConnectionEstablished += Connection_ConnectionEstablish
connection.begin(57600, SerialConfig.SERIAL_8N1);
}
private void Connection_ConnectionEstablished()
{
System.Diagnostics.Debug.WriteLine("Connected");
arduino.pinMode(NUM_DIGITAL_PINS + SDA, PinMode.I2C);
arduino.pinMode(NUM_DIGITAL_PINS + SCL, PinMode.I2C);
index = 0;
arduino.I2c.I2cReplyEvent += I2c_I2cReplyEvent;
timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromMilliseconds(2000);
timer.Tick += Timer_Tick;
timer.Start();
}
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:
i2cReading.Enqueue(index);
System.Diagnostics.Debug.WriteLine("PCF8591_ADC_CH0"
ReadADC(PCF8591_ADC_CH0);
break;
case 1:
i2cReading.Enqueue(index);
System.Diagnostics.Debug.WriteLine("PCF8591_ADC_CH1"
ReadADC(PCF8591_ADC_CH1);
break;
case 2:
i2cReading.Enqueue(index);
System.Diagnostics.Debug.WriteLine("PCF8591_ADC_CH2"
ReadADC(PCF8591_ADC_CH2);
break;
}
index++;
if (index > 2)
index = 0;
}
void ReadADC(byte config)
{
arduino.I2c.enable();
arduino.I2c.write(PCF8591, "" + (char)config);
arduino.I2c.read(PCF8591,2);
arduino.I2c.stop(PCF8591);
}
5.3 Testing
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.
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.
The next step we are going to build a Windows Universal with Arduino and servo motor.
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 next step is to modify MainPage.xaml.cs file. Firstly, we add our namespace.
using System.Text;
using Windows.ApplicationModel.Core;
using Microsoft.Maker.Serial;
using Microsoft.Maker.RemoteWiring;
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;
connection.ConnectionEstablished += Connection_ConnectionEstablish
connection.begin(57600, SerialConfig.SERIAL_8N1);
}
private void Connection_ConnectionEstablished()
{
System.Diagnostics.Debug.WriteLine("Connected");
arduino.pinMode(SERVO, PinMode.PWM);
direction = 1;
fwd = true;
timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromMilliseconds(2000);
timer.Tick += Timer_Tick;
timer.Start();
}
On Tick event from Timer object, we read change servo motor angle. Then, we define
UpdateData() to update app UI.
direction++;
else
direction--;
if (direction > 6)
{
fwd = false;
direction = 6;
}
else
if (direction < 0)
{
fwd = true;
direction = 0;
}
}
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.
Source Code
Contact