Two nights ago, I showed you how to control a Roomba from C# over Bluetooth. If you have not read that article, you will need to do that first because that article shows you how to configure your Roomba to work over Bluetooth using the RooTooth – Bluetooth Wireless Roomba Connection from SparkFun.com. Shortly after posting that article, a very close friend called me to talk about it. Having absolutely no programming background at all, my friend asked if I would extend the app a little further for him by adding some buttons that allowed him to steer his Roomba directly from the app and not just by sending commands from a drop down list. Being the good friend that I am, I did just that, but also took it one step further. I decided to also add support for the Xbox 360 controller. I sent him the updated application last night and I now want to share the upgraded version with all of you. One thing you will need to keep in mind is that this version was compiled specifically for 64-bit Windows and will not run on 32-bit Windows. But, I will show you how to compile it for 32-bit Windows if you aren’t running 64-bit Windows. Let’s begin.
As mentioned above, the first thing you will need to do is to follow the instructions from my previous article that explains how to setup your Roomba and PC to communicate with each other over Bluetooth. Next, you will need to go to http://www.slimdx.org/download.php and download the version that suits your operating system (32-bit or 64-bit). SlimDX is a free, open source framework that enables developers to easily build DirectX applications using .NET. Since we will be working with the Xbox 360 controller, we could have gotten the necessary pieces for that from the Microsoft XNA Framework. But, XNA is way too much for what we will be doing here. If you are running 64-bit Windows, I have already included the 64-bit version of SlimDX in the ZIP file listed at the end of this article.
If you are running 32-bit Windows and plan on using the project ZIP file I’m including here, you will need to open the project solution with Visual Studio, click on Project > Properties, click the Build tab, and change the Platform target to “x86″. Then, you will need to replace the SlimDX.dll file in the bin > Debug folder with the 32-bit version you downloaded from http://www.slimdx.org/download.php. Once you have the project setup for your operating system, you are ready to run the app. Before you do, make sure you have your Rootooth connected to your Roomba as explained in the last article and make sure you take note of which serial port your computer is using to talk with your Roomba.
When you run the app, you will need to choose the serial port your computer is using to talk with your Roomba and click the “Open Port” button. If the app was able to successfully connect with your Roomba, you will hear your Roomba play a series of tones and then all of the buttons on the form will become enabled. Once you have a successful connection with your Roomba, you can click and hold on any of the buttons on the form to perform those actions. Once you release your mouse button, the Roomba will stop. That means, the Roomba will only move if you’re holding your mouse button down on one of the buttons. Here is what the updated version of the app looks like:
For those of you that want to drive your Roomba using an Xbox 360 controller, the first thing you will need to do is get a controller that has a wire with a USB connection at the end. This article does not address working with wireless Xbox 360 controllers. I’ll do that in another article. For now, you can get a wired controller from Amazon for about $20. Once you have a wired Xbox 360 controller, all you have to do is plug it into your computer and connect the app to your Roomba as explained above. Once you have a connection with your Roomba, you can steer it using the joysticks on your Xbox 360 controller. Push the left joystick forward to move forward and push the right joystick left & right to turn the Roomba left and right. Since the left joystick also controls speed, you will need to also be pushing it forward when turning the Roomba left and right.
Here is a quick video of everything in action.
Download: 64-bit RoombaSharpWithXboxController.zip (0.98MB)