Building a small running bot with Windows 10 on a Raspberry Pi 2

I won a Raspberry Pi B+ from a Microsoft event, so I took some time to learn about the Pi to understand more about all the fuzz around IoT. The experience I had is very fun and excited. I study and work mainly on software engineering, so hacking the virtual world is much more familiar to me that hacking those hardware and devices in the real world. However, Raspberry Pi turned out to be the perfect device for me to learn more about this IoT area by providing a bridge between high level programming language (such as Python) and all the “complicated” GPIO and I2C stuffs. In other words, you can write Python instead of C++ or Assembly to communicate with so many electrical boards and devices. There are many interesting and easy to follow tutorials on Adafruit that I strongly recommend you to take a look and give it a try.

With the introduction of Windows 10 on Raspberry Pi 2, the small computing box becomes even more interesting to me. The Pi can now run Universal Windows apps and communicate with devices such as Xbox controller. Therefore, I have decided to buy a new Pi 2 and give Windows 10 IoT a try with a new project: a running robot that is remotely controlled with a Xbox Controller.

Setting up Windows 10

Previously, setting up Windows 10 IoT on the Pi 2 is not easy and required several steps with Powershell. I followed the steps in a great blog post of Scott Hanselman (which is quite similar to the old tutorial from Microsoft, plus some useful warning and notices here and there): http://www.hanselman.com/blog/SettingUpWindows10ForIoTOnYourRaspberryPi2.aspx.
However, it gets much easier now with the new Dashboard on your PC for installation and a Windows Device Portal (basically a web portal) on the PI for management.
You can download the Dashboard from this page: http://ms-iot.github.io/content/en-US/GetStarted.htm. The setting up steps using the Dashboard are very straight forward.

After having installed Windows 10 and booted up the Pi 2, and setup the Network (you might have to plug in a mouse and keyboard if you want to use Wi-Fi), you can open the Windows Device Portal on a web browser to access many useful management features (read more here http://ms-iot.github.io/content/en-US/win10/tools/DevicePortal.htm). Most of the stuffs that need to be done using PowerShell can now be accessed in this Portal. It is great for headless mode, but is a bit sad that you cannot get the same amount of functionality directly on the Pi UI itself.

Note:
– You can change your password with the Portal, so remember to do that!
– Although fiddling with PowerShell commands might not be necessary anymore, I still leave a link here for future reference: http://ms-iot.github.io/content/win10/tools/CommandLineUtils.htm.

Wiring the Pi

I bought a small toy bug that provide 2 motors, a place to put battery a basic frame.
Toybug

Then I follow this tutorials for all the wiring to the 2 motors.
http://computers.tutsplus.com/tutorials/controlling-dc-motors-using-python-with-a-raspberry-pi–cms-20051

It turned out that tying every component into that bug (with the red cap removed) did not look as nice as I imagined. You can still see a bit of the white base of the toy bug.
BugWithComponents

But it works (read more below for code, sorry) :), although all the components tend to fall out every time the bug move.

I later on upgraded the bug with Lego that looks much much better. You can see that there are 2 batteries, one for the Pi 2 and a pack of 4 AA batteries for the motors. I think it looks awesome.
BugLego

I will update the post with a new video on this robot when I have some more free time.

Coding and debugging

The code is open-source on my GitHub: https://github.com/nguyenquyhy/RoboPi2. Initially I used a custom Xbox controller class to access HID devices. However, with the introduction of the Gamepad API that is very easy to use, I rewrote parts of the code to utilize that.

Note:
As of the current build 10586, you will notice that msvsmon is not started by default as in previous builds. It is actually expected as Visual Studio can launch msvsmon automatically if you set Authentication Mode (in Debug section of Project Settings in Visual Studio) as Universal (unencrypted protocol). You can actually start msvsmon manually in the Debugging section of the web portal, and then seems to be able to use None Authentication Mode in Visual Studio to connect (you will have to set the port, usually 8116, in this case). However, if you use the latter way right after installing Windows, you might find some problems with missing DLLs; it seems that you have to use Universal (unencrypted protocol) at least once, so that Visual Studio can deploy necessary files to the Pi.

Many other interesting projects

Microsoft has posted a ton of interesting open-source project on this IoT platform. You can have a look at them here: https://microsoft.hackster.io.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.