Playing with a radio controlled toy is much fun. When is comes to water vehicle, we love them maneuvering whole day. If you are passionate for Windows and are a good hacker, this article is for you.
This article reveal the technique to modify RC Boat that will be controlled using Windows Phone. In addition, the source code contains libraries to develop application for Windows based OS, too.
Whats new in this article?
Arduino Wiring Project for Windows IoT Core
Microsoft has released awesome features to the Windows IoT build 10.0.10556 (Insider Preview). With this build, now you can write Arduino sketch for Windows IoT Core directly from Visual Studio 2015 (Refer this article for more information).
Overcome Existing Limitation of Windows IoT Core (Serial-UART, PWM)
RPi2 supports for PWM and UART on board but current release of Windows IoT Core (10.0.10556) doesn't. Regarding to this project, we need PWM to control motor speed and serial (UART) for ESP8266-01 and GPS.
As per Windows IoT Release notes, ADC and PWM is supported via external chips but I'm not sure about the availability of that chips in all regions. While Arduino is widely available worldwide. So why not to chose Arduino. In addtion, it is a full-fledged microcontroller having its own benefits.
Essential
Before going further, you must need following:
- Your Raspberry Pi 2 must have latest Windows IoT Core Insider Preview. (Download) (How to install Windows IoT Core on RPi2?)
- Raspberry Pi 2 must be setup for Lightning feature. (Lightning Setup)
- You must install latest Windows IoT Core Project Template. (Download)
Lightning is a set of providers to interface with GPIO, I2C and SPI through the lightning Direct Memory Access driver. In short, it is the new driver which provides high performance against default inbox drive by accessing direct memory mapped driver. By default Windows IoT Core is configured for default inbox driver.
Basic Concept
Raspberry Pi 2 (running Windows 10 IoT Core), will communicates with Windows device via Communication Link. Windows IoT Core will takes appropriate maneuver signal from remote Windows device and generates the appropriate signal to control engine and rudder (if available). In addition, Windows IoT running on RPi2 will send back sensor data to the remote Windows device to process it and show.
Let's see which communication & sensor module to be used:
Each boat have different hardware configuration to maneuver it. Let's explore three basic configuration mode:
The source code for the project is only developed for Mode 2. With minor changes you can program for Mode 1 as well as 3 if you really understood the concept of Gateway.
Gateway (for ADC, PWM & Serial Communication)
With the release of Windows IoT build 10531, ADC and PWM are supported via external chips. That means there is no direct support for on-board pins. Even, on-board Serial Port is useless because it may be used by kernel debugger.
In this project, WiFi (ESP8266) and GPS module (uBlox Neo6mV2) uses Serial Communication (UART). PWM is going to be used for motor speed control as well as to control servo for configuration mode 3. Thus some extra components will be required to accomplish goal. Arduino Nano or Arduino Pro Mini (16MHz) will be used to provide Serial Port as well as PWM signals. It will work as gateway:
Now, Windows IoT can access to ADC, PWM and Serial devices via gateway. To access any peripheral connected to the gateway device, it just need to access gateway chip via I2C bus.
If major peripherals are connected to the gateway (Arduino), then what will be the responsibility of Raspberry Pi 2 and Windows IoT?>Raspberry Pi and Windows IoT can be called the brain. It gets data via ESP8266, process them and controls the peripheral via gateway. Arduino is limited to its memory and processing power, thus its not capable to deliver real-time application. For ex: The real power comes when you wanna use Windows IoT for video processing, sound processing, autonomous system, etc.
Let's explore gateway programming:
You don't need to modify ESP8266-01 and Gateway sketch. You just need to upload it. Once you have uploaded, it will work like charm. You just have to code for Windows IoT.
Sketches
This project is a bit complicated. Thus the code is divided into three parts:
- ESP8266 Sketch
- Gateway Sketch
- Windows IoT Sketch
Main objective of ESP8266 Sketch is to create Access Point and listen for incoming GET request. Request will be consists of arguments that must be placed into global argument buffer. Once arguments are copied, respond back with plain text which consists of data sent from Windows IoT via Gateway. Thus ESP8266 Sketch is responsible to communicate with remote device.
Gateway Sketch provides ADC, PWM and Serial service to Windows IoT on demand. It is also responsible to exchange data with ESP (using UART) as well as Windows IoT sketch via I2C.
Windows IoT Sketch is the brain. You can use it for complex processing such as autonomous guidance system. Windows IoT Sketch can get arguments that are passed by remote device to ESP8266 on demand. It can also send string to the remote device using ESP8266 via Gateway.
The following diagram will helps you to better understand how data is exchanged:
Deploy
ESP8266-01 Sketch
To flash or reprogram ESP8266-01, you need to wire-up ESP8266-01 as shwon below:
Once you are done with wiring, open Arduino IDE and follow:
Gateway Sketch (Arduino Nano)
Upload the Gateway sketch to the Arduino Nano. Gateway sketch is provided at the end of the article.
Windows IoT Sketch
Deploy 'ArduinoWiringWIoT' to your RPi2.
After successful deployment, we need to register this app as startup app. You can register as startup app in two way:
- Web management portal
- PowerShell
But due to bug in current release of Insider Preview (10.0.10556), web management portal won't works at this time and don't try to register using web management portal because RPI2 won't boot up after reboot. And finally you will have to re-flash your Windows IoT.
So let's register using PowerShell:
- Log-in to your RPi2 using PowerShell (refer this article)
- Type:
IotStartup remove
and hit enter - Find the application you have deployed to your RPi2 using:
IotStartup list
- Add your application to startup application:
IotStartup add headless <your-app-package-name>
- Now, set Windows IoT to boot in headless mode:
setbootoption headless
- Finally, you need to restart Windows IoT in order to save changes:
shutdown /r /t 0
Voila, you have just deployed all of the three sketched to your ESP, Gateway and RPi2. Now its time to wire up things. Refer the following schematic to wire-up:
At The End
Deploy the application provided for Windows Phone 8.1/10. Connect them all the go, connect Windows Phone to the ESP8266 AP, start WP Dashboard app and enjoy :)
Known Issues
Windows IoT Project : Arduino Wiring (Naming Issue)
Do not use space or any special symbol when creating Arduino Wiring project for Windows IoT. It will generate compile time error like:
Compass (HMC5883L) Jitter
HMC5883L is much sensitive to the electromagnetic waves. Thus you must need to place it as far as away from such electromagnetic emitting device like motors, communication modules, etc.
Windows Phone Application won't start
In order to run provided WP application, your phone must have built-in GPS. If your phone does not have built-in GPS, you can disable code block that retrieves the WP's location.
Conclusion
Day by day Windows IoT team is providing rich set of new features. With the current release 10.0.10556, a new driver "Direct Memory Mapped" is integrated which is far better than the Inbox driver. Performance is also significant improved over the old one. By combining other microcontrollers, we can overcome limitation of the Windows IoT or Raspberry Pi 2 as I have given concept of Gateway which serves ADC, PWM and Serial to the RPi2. In addition, such gateway can be called as co-processor because it saves a lot of time of the RPi2 by doing some task for it and interrupts the RPi2 when task completed.
Comments