Getting Started With Windows Remote Arduino - Agus Kurniawan...
Copyright
Getting Started with Windows Remote Arduino Agus Kurniawan 1st Edition, 2015 Copyright © 2015 Agus Kurniawan
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
2.3.3 Adding Reference Files for Windows Remote Arduino 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
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. 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
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. 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, http://www.atmel.com/dyn/resources/prod_documents/doc8161.pdf . Further information about Arduino Uno, you can read it on http://arduino.cc/en/Main/ArduinoBoardUno .
1.1.2 Arduino Leonardo The Arduino Leonardo is a microcontroller board based on the ATmega32u4. Download datasheet for this product on http://www.atmel.com/dyn/resources/prod_documents/7766S.pdf . Visit this product to get the further information on http://arduino.cc/en/Main/ArduinoBoardLeonardo .
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 http://www.atmel.com/dyn/resources/prod_documents/doc2549.PDF. Further information about Arduino Mega 2560, you can visit on
http://arduino.cc/en/Main/ArduinoBoardMega2560 .
1.1.4 Arduino Due The Arduino Due is a microcontroller board based on the Atmel SAM3X8E ARM CortexM3 CPU. You can download the datasheet, http://www.atmel.com/Images/doc11057.pdf. If you want to know about Arduino Due, I recommend to visit this website, http://arduino.cc/en/Main/ArduinoBoardDue.
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: http://arduino.cc/en/Main/ArduinoStarterKit
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.
1.2.3 Cooking-Hacks: Arduino Starter Kit Store website: http://www.cooking-hacks.com/index.php/shop/arduino/starterkits/arduino-starter-kit.html
1.2.4 Arduino Sidekick Basic kit v2 Store website: http://www.seeedstudio.com/depot/Sidekick-Basic-Kit-for-Arduino-V2-p1858.html You also can find this kit on this online store. http://www.exp-tech.de/seeed-studio-sidekick-basic-kit-for-arduino-v2
1.2.5 Grove - Starter Kit for Arduino Another option, you can buy this kit on Seeedstudio, http://www.seeedstudio.com/depot/Grove-Starter-Kit-for-Arduino-p1855.html .
1.2.6 DFRobot - Arduino Kit for Beginner v3 DFRobot provides Arduino kit too. You can buy it on the following website. http://www.dfrobot.com/index.php?route=product/product&path=35_49&product_id=345
1.3 Windows 10 and Visual Studio 2015 To develop app with Windows Remote Arduino, we use Visual Studio 2015 and Windows 10. Please install them for our development environment.
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 https://github.com/ms-iot/remote-wiring/. We will deploy and test program based Windows Remote Arduino on the next chapter.
1.5 Arduino Software To develop application based on Arduino board, we need Arduino software. You can obtain it on http://arduino.cc/en/Main/Software . 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.
Finally, you should see Arduino IDE.
1.6 Testing For testing, I used Arduino Uno R3 on Windows 10.
I also used Arduino Sidekick Basic kit for electronic components.
2. Windows Remote Arduino for Windows 10
This chapter explains how to work with Arduino and Windows 10 for getting started.
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).
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.
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 http://arduino.cc/en/Tutorial/Blink for configuration. For this scenario, we use attached LED which is connected on Digital 13. Open Arduino IDE.
On Arduino software, Click File -> Examples -> 01.Basics -> Blink.
Then you will get a sample code of Blink app.
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.
If success, you should see blinking LED on Arduino board.
2.2 Arduino and Windows Remote Arduino (WRA) 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 https://github.com/firmata/protocol . To deploy Firmata into Arduino board, you do it opening Arduino IDE. Select menu File > Examples -> Firmata -> StandardFirmata.
Then, you will get Firmata code on Arduino IDE.
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 https://github.com/ms-iot/remote-wiring/. It provides library for Windows 10 and Windows 8.1. Open for Solution file (*.sln) for Windows 10 using Visual Studio 2015.
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.
2.3 Windows Remote Arduino with USB 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.
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.
If done, click OK button.
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): Microsoft.Maker.RemoteWiring.winmd Microsoft.Maker.Firmata.winmd Microsoft.Maker.Serial.winmd
Click OK button if finished. Finally, you should see our referenced files on our project.
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 tag true Microsoft.Maker.Firmata.dll
Add this script into tag true
Microsoft.Maker.RemoteWiring.dll
Add this script into tag true Microsoft.Maker.Serial.dll
You also need to configure Package.appxmanifest file to enable Serial port capability. Open Package.appxmanifest file and add the following script on tag.
2.3.5 Writing Program Now we develop UI on XAML. We modify MainPage.xaml file and build the following UI.
We need three CheckBox, a TextBlock and a Button. The following is a script of MainPage.xam.
6) { fwd = false; direction = 6; } else if (direction < 0) { fwd = true; direction = 0; } }
private async void UpdateData(byte value) { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Wind () => { txtVal.Text = Convert.ToString(value); }); }
Finally, we call InitWRA() on class constructor. public MainPage() { this.InitializeComponent(); this.Unloaded += MainPage_Unloaded; InitWRA(); } private void MainPage_Unloaded(object sender, RoutedEventArgs e) { connection.end(); arduino.Dispose(); }
Save this code.
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.
Source Code
You can download source code on http://www.aguskurniawan.net/book/wra_20062015_01.zip .
Contact
If you have question related to this book, please contact me at
[email protected] . My blog: http://blog.aguskurniawan.net