Windows 8 Store App controlling a NETMF Gadgeteer Robot
- Posted: Sep 21, 2012 at 6:00 AM
- 6,803 Views
- 1 Comment
Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
For this week's Hardware Friday post I tried to find something that fit this week's Visual Studio Launch theme, but couldn't find anything that really fit.
I DID find this post from the .Net Micro Framework team, On-going VS Express Support, which notes the VS 2012 support for the .Net Micro Framework is coming...
We are in the final stages of version 4.3 of NETMF with release in the near future. This release will work with Visual Studio Express 2012 for Windows Desktop. In addition, we are in the planning stages for .NET Gadgeteer version 4.3 and this version will also support that Express edition. We don’t have a firm release target for that at this time.
In the meantime, VS 2010 and VS2012 co-exist nicely and the language specific Express editions are still available.
... but I couldn't leave today's post at that. So since the Visual Studio Launch was pretty focused on Windows 8, how about we highlight a Windows 8 hardware related project from the one and only Pete Brown?
At several recent events (VSLive Redmond, thatConference, the Heartland Developer Conference and more), I've had a neat little .NET Micro Framework robot with me. The remote control for the robot is a Windows 8 tablet running a simple Modern UI/Windows Store app I wrote in C#/XAML. The example shows both how you can use C# skills to build robots, and also how flexible the new Windows Store app model is when it comes to communicating with remote devices.
Pete covers the complete project in his post, from the parts, with links to where you can purchase them;
Although they're out there, it's rare to find a robot as a complete kit. Typically you need to assemble one from a number of different parts. Here are the parts I used.
Optional LCD Character display
Wireless Hub / Router
Hooking everything together;
Assemble the chassis. I did the chassis assembly with my two kids; it's pretty easy, although some parts do get a little fiddly (the motor mounts in-particular). Leave the top off for now so you can get to the bottom deck.
Then, connect both motors to the positive and negative motor connections on the motor module. I kept the motor module on the bottom deck to make that easier. Because I didn't reverse the wires on the two motor connections, but the motors are on opposite sides, they have to be reversed in code. Positive voltage in one goes forward, while on the other goes backwards.
Attach the 9v battery connector (without battery) to the motor modules power input...
Coding the robot;
Now, let's get to the code.
The onboard robot code is a .net Gadgeteer project, created in Visual Studio 2010. NETMF doesn't currently support Visual Studio 2012, but you can install VS2010 side by side with VS2012.
First, I used the WiFly module source code from Stefan Thoolen's great .NET Micro Framework Toolbox project on CodePlex. This project currently doesn't have support for being a socket server, only a client. For that reason, I had to make the Windows 8 app the server. The downside to this is the IP address for the Windows 8 device is hard-coded into the robot, which is opposite of what you would normally do.
The code is simple, all contained in the Program.cs file. Explanation after the listing.
To building the Windows 8 Windows Store app;
Windows 8 App
When I first saw the networking support available to Windows 8 apps, I was pretty psyched. I did a lot of networking work in Silverlight, including some sockets (shudder). What we have in Windows 8 is not only a lot simpler, but it also does not have the port and protocol restrictions Silverlight has because WinRT apps weren't designed to be run in a web browser on the public Internet.
Here's the UI. It's very simple: just four boxes sized and positioned for touch.
As Pete notes, the Windows Store App is... um... minimal... at this point.
But the key to this isn't the UI, it's the code and the connection.
Can a Windows 8 Windows Store app .NET Gadgeteer? Oh yeah, and Pete makes it look easy (as these things do in hindsight now that he's done all the work...