Generic Serial Bluetooth with Win 10 IoT-Core RPI2

About this project

Further

This project is discussed in detail in embedded101.com:

“Win 10 IoT-Core: Bluetooth Universal Windows Serial App”

About

This project is a Universal Windows App that connects an IoT-Core device such as a Raspberry PI 2 to an embedded Bluetooth device over the Bluetooth Serial Profile using a genetic Bluetooth USB dongle.generic serial bluetooth with win 10 iot core rpi2

Background

.Bluetooth supports peer to peer networking over a short range. Unlike a Wi-Fi network, Bluetooth connectivity is one to one. Two devices can connect and interact. For example, two devices may connect in a symmetric manner using the serial profile and pas raw data between them. Generally though, Bluetooth connectivity is asymmetric with one end generating a specific data format to be consumed at the other end. For example a mobile phone can implement the A2DP (Advanced Audio Distribution Profile) Profile and stream audio to a head set that implements the HSP (Headset) Profile OBEX (Object Exchange) is a symmetric connection between two devices as they exchange data between them.

The Microsoft IOT-Core Bluetooth Sample project uses the GATT (Generic Attribute Profile Profile). This provides profile discovery and description services for the Bluetooth Low Energy protocol. With this protocol simple low power devices can be connected at one end generating data to be consumed by a complex processor.

This is a far simpler project than the Microsoft sample. It is only concerned with the more generic SPP (Serial Port Profile) which is based upon the RFCOMM profile. It was developed with a very old USB Bluetooth dongle and so should work with any Bluetooth dongle.

The IoT App

This app is a simple Bluetooth Serial Universal Windows (Windows 10) test app. It starts by enumerating (as a list) all devices Bluetooth paired to the device where the app is running. One is selected by double clicking which initiates connection. Text to send is entered in a Textbox and sent when a button is pressed. The app automatically receives any text sent to it ( and displays it). Hence when the endpoint (as above) simply echoes the text its received, the sent text should reappear in the reception box on the UW app.

For testing an Arduino Uno with a Bluetooth adapter is used. It has a simple shield that just echoes back any characters its receives over the Bluetooth connection:

The Shield Setup:

// A serial loop back app
// Past setup
// Initiated by connected system
// Note can be used with Bluetooth where the RxTx of the BT device
// are connected to the TxRx of the Arduino board.
// Need to disconnect BT adapter for programming though.
void setup() {
     // My adapter is set to this BAUD 115200
     // This is the Arduino to BT adapter port rate
     // Set when the BT adapter is in command mode.
     // Its NOT the BT rate which you can't set.
     Serial.begin(115200);
     delay(333);
     while (!Serial)
         ;
     delay(1000);
     Serial.println("The quick brown fox jumps over the lazy dog!");
}

The Shield Loop:

void loop() {
     char ch = Serial.read();
     while ( 255 == (byte) ch)
     {
          ch = Serial.read();
     }
     Serial.print(ch);
}

Pairing

Bluetooth is a peer to peer scenario. Before they can connect over Bluetooth they must be paired. This is not done within the app. Pairing with a passkey can be problematic between embedded devices as they are often headless and may not support popups (as IoT-Core does not). There is a IoT-Core web portal for doing this as well as a command line utility on the device that can be run over an SSH shell. The most recent version of the OS web portal  supports passkey pairing which was missing around the time of Windows 10 RTM. “Win 10 IoT-Core: Bluetooth Universal Windows Serial App” discusses pairing in this context in detail.

Starting the project

The app project is created using in Visual Studio 2015 using the  Universal Windows app template:

New Project–>Visual C#->Windows->Blank App (Universal Windows)

Creating the App UI

The UI is implemented in XAML

Create the UI as per the layout as above (or similar):

The UI is quite straight forward and is created as follows:

  • All text elements are TextBlocks except the SendText which is a TextBox
  • SendText accepts CarriageReturn (ie is Multiline)
  • The Recvd text has WrapText enabled (ie is Multiline)
  • UI elements are organised in rows using a StackPanel set to horizontal orientation
  • These StackPanels are then stacked with a StackPanel set to vertical orientation, along with the ListBox.

You may prefer to layout the UI using Relative StackPanels or use Grid rows and columns etc.

For more detail: Generic Serial Bluetooth with Win 10 IoT-Core RPI2


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

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