About the Project
Now that the Windows 10 Insider Preview is available for those
that have already signed up,
the .NET framework is now available on another platform that some of us are
probably already familiar with – the Raspberry Pi 2. This new addition to the
.NET-capable platforms gives those of us already familiar with the Visual
Studio development environment a new outlet for our creativity.
Dexter Industries has created an aptly named add-on for the Raspberry Pi called the GoPiGo. The GoPiGo is a robotics kit that allows the Raspberry Pi to go! It adds two motorized wheels, a protective chassis, and a battery pack, giving the Pi the mobility of an RC car.
This project will show you how to set up one Windows 10 device to remotely control your GoPiGo over your local network. This means that you’re no longer bound by the HDMI cord connected to your monitor. Once the Raspberry Pi image has been updated on the Microsoft website, we won’t need the Ethernet cable, either, and we will be free to Go Go Go!
Some Assembly Required
There are a few things you'll need to set up before you can get started:
Set up your Windows 10 development Environment on both a PC and the Raspberry Pi 2. This can be easily done by following this guide. If you have any trouble setting up, please post in the comments below and we will try to help.
- Remember - Windows 10 is not yet a finished product, which means that there will frequently be updates, the possibility of crashes exist, and there could even be catastrophic failures leading to data loss. This means that you shouldn’t upgrade your main PC to Windows 10 if you have another option.
Fully assemble the GoPiGo. It's very simple, straight-forward, and only takes about 15-20 minutes.
What To Expect
Like we mentioned in the About section of the guide, this project sets up a remote controller that allows you to control the GoPiGo’s direction, motor speed, server motors, and LEDs.
The first thing to remember that for this project, the Raspberry Pi 2 is the server, and the device remotely controlling it is the client connecting to the RPi. The Raspberry Pi will open a StreamSocketListener to listen for a socket connection on one port. The default port is 8027, but you are free to change it to any port that you have available.
The client will connect via the IPv4 address, plus the port number that you’re using. Once connected, you will be able to send any combination of commands to the RPi2, which will in turn control the GoPiGo via an I2C connection.
That covers the bare basics, so let’s get started and set everything up.
Setting Up The Server
The GoPiGo Server is not a true headless app, but this version has a blank user interface. Because the RPi2 can load this app as the default, it will automatically allow a stream socket connection to the chosen port without any interaction from the user. As long as the device is turned on and connected to the network, it will be listening for that connection.
Once you’ve downloaded the solution from the location mentioned below, and have opened it in Visual Studio 2015, you’ll see that three projects have loaded. I’ll go over them very briefly for now, but we’ll be posting a more thorough guide in a few days.
Once you’ve loaded the solution (GoPiGoServer), you will need to make one or two changes. First, you'll need to configure the Debug options. See the images below for the settings you'll want to use. (PiWin is the name of my Pi - use yours, or the device's IP address).
A few important notes:
- In order to run a UWA on the Raspberry Pi 2, you'll need to set the target platform to ARM, and not x86 or x64 architectures. When we start using networked remote controllers, we'll be targeting other architectures, but for now, ARM is the one we want.
- The name of the Remote Machine can either be the name you gave your Raspberry Pi during set up, or the IP Address that the Raspberry Pi shows on screen when plugged into an HDMI port.
- Make sure that "Use Authentication" is NOT checked under the Remote Machine name. Visual Studio will not connect successfully to the Pi if this is checked.
Second, and optionally, you can change the port number that the GoPiGoServer connects to. In the WindowsIoTSocketServer project, open the SocketConnection.cs file. On line 16, you'll see the string variable named Port. Change the value to the desired port and save.
Then, you can either run in debug mode for temporary testing, or release mode to deploy it permanently by changing the Solution Configuration. You can go ahead and do this before moving on to the next part of the guide.
Setting Up Client
Setting up the client is just about as simple as setting up the server. For this tutorial, we’ll be using a Windows 10 desktop, but a tablet will work just as well. It has not yet been tested (or targeted for) a Windows 10 phone.
Once you’ve downloaded this solution (GoPiGoController), you’ll see that this UWA has a simple UI allowing for a connection and easy controls of the GoPiGo.
Note that in this solution, there are only two projects:
You shouldn’t need to make any changes to this solution in order to successfully run it. Simply press F5 if you want to run in debug mode and you’ll see the UI load. Once you have the server running your Pi, you’ll be able to connect. Simply enter your IPv4 local IP address from your Raspberry Pi 2. If you don’t know the IP address for your Pi, open up the Windows IoT Core Watcher and find your device listed there.
Once you’ve entered your IP address, click connect, and the status notification on the Controller UI should change to Connecting, and finally to Connected. If you receive a failing status, double check your IP address and port number. If those are both correct, place a break point on line 53 of SocketConnection.cs and take a look at the exception error message that is being thrown. This should help with any troubleshooting.
Now, you’re ready to Go!
What Do The Controls Do?
The controls are fairly simple, and I’ll quickly go through them:
- Direction Controls: Moves the GoPiGo, as you would expect. Turn left will move only the left wheel forward. Turn right does the opposite. Left Rotate will rotate the left wheel counter-clockwise and the right wheel clockwise. The reverse is true for Right Rotate.
Have fun! And remember to hit the Stop button when you’re done, otherwise, the motors will just keep on going!
Next Up
Over the next few weeks, the Windows 10 GoPiGo library will be growing, and while it grows, we'll be adding to this tutorial or posting new ones. Here are some of the things that you can look forward to:
- An in depth look at the code inside the library.
- Running the UWA in headless mode – This one is up!
- Seeing Clearly - Updating the GoPiGo library to utilize the ultrasonic sensor kit that attached to the GoPiGo
Let Us Know
If there's something else you'd like to see added to the Windows 10 GoPiGo library, please let us know. We're actively working on updates and code cleaning.
Comments