Bluetooth, Arduino and Windows 8.1
- Posted: Nov 08, 2013 at 6:00 AM
- 16,338 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
Today's Hardware Friday continues in our Windows 8.1 Communication series, this time using Bluetooth with Arduino, courtesy of Michael Osthege...
In this sample you can learn how to establish a serial Bluetooth link between an Arduino and a Windows 8.1 app.
Building the Sample
To test this, you need an Arduino with Bluetooth capabilities (for example an Arduino Uno R3 and a JY-MCU Bluetooth module) and a Windows 8.1 device with Bluetooth capabilities. (A Bluetooth dongle will do as well.)
The sample is provided as a Visual Studio 2013 solution that includes the Windows Store app code and the Arduino code. You can open the Arduino code with another IDE as well, but Visual Studio 2013 (Preview) with the free VisualMicro extension is recommended.
This sample was inspired by and is based on the Windows Phone 8 implementation of Bluetooth/Arduino communication by Marcos Pereira. This BUILD talk by Ellick Sung and the related sample application were also helpful in porting the code to WinRT.
Set up the Arduino with a Bluetooth module, two LEDs and a potentiometer, according to the following diagram:
Communication with the Bluetooth module is accomplished using the SoftwareSerial.h library.
The Windows 8.1 app has to declare Bluetooth serial communication capabilities in Package.appxmanifest:
To deploy the Arduino code with VisualMicro, right click the Project in the Solution Explorer and select Debug\Start new instance.
When the Windows 8.1 app starts, you can establish a connection and control the LEDs, or subscribe to analog inputs as seen in the following video:
Recently, after being inspired by this video of Arduino Bluetooth communication with Windows Phone 8 by Marcos Pereira, I got myself some new devices to play with:
The thing is: I don’t have a Windows Phone 8 yet and the Windows Phone 7.8 APIs do not support this kind of Bluetooth communication.
But: I have a Surface RT and with Windows 8.1 the RFCOMM API can be used to establish a serial link to the Arduino.
Arduino and Visual Studio
It happens that my developing skills are quite limited to C# and when I had to develop some Kinect software with Processing in early 2012, I almost freaked out. Arduino code is written in C++ and the standard Arduino IDE is derived from the Processing IDE. Fortunately there’s the Visual Studio extension VisualMicro which brings a very intuitive Arduino support for VS2010-VS2013. (not available for Express versions)
You can get VisualMicro for free at http://visualmicro.codeplex.com/. They also offer a pro-version (>$20) with support for Breakpoint-Debugging.
The Arduino IDE should be installed as well and you have to tell the VisualMicro extension where to find it.
Preparing the Code
The Arduino has to be loaded with some code to send and receive Bluetooth messages. I created a Visual Studio solution with a blank Windows 8.1 app and a new Arduino sketch and added a new header file “SoftwareSerial.h” (Fig.2). The code of SoftwareSerial.h can be found here.