We are working towards rejigging an old Surface 1 or 2, or any old Windows Tablet/Laptop with a touch screen, to be the UI for a remote app running on a device such as an Arduino or Windows 10 IoT-Core. We have developed a Windows 10 UWP app that programmatically sets up the UI as an XAML grid of buttons. These buttons are rounded boxes whose content is a multiline TextBlock. If disabled, these buttons can individually just be fixed textual content in the UI. The grid and button’s text is specified in a Json string which is loaded from a file present in the UWP app. A ListView box was added so that the remote app can send back text to be displayed. The intention is for the UWP app to communicate UI button presses to the remote app over various mediums such as Bluetooth, RS232, Network Sockets etc. to facilitate the download of this Json content from the remote app.Later on we will port the UWP app backwards to Windows 8.1 so it can run on the WinRT( ARM) Surface 2.
Code Repository : https://github.com/djaus2/SurfPad
Status: Bluetooth connectivity between UWP app and Arduino device implemented.
This article covers Bluetooth connectivity between the UWP UI app running on a Windows 10 Surface Book 2 and an Arduino Uno (compatible). Button presses on the UWP app are sent to the Arduino device as single (unique) character and echoed back to the app. Upon return the button’s text is looked up and displayed in the TextBlock. Special characters can initiate command actions in the remote app. One button press will get the remote app to send the grid Json configuration text to the UWP app so it can (re)configure the grid. In this manner the UWP app engenders some universality in that it can be configured for a variety of remote apps, by that app at runtime. The first part of this article covers the device to device Bluetooth Serial Port connectivity. The second part covers the Bluetooth connectivity fro a UWP app and an Arduino device.
Bluetooth Connectivity-UWP SoftwareBluetooth Connectivity-Win 10 IoT-Core Remote App (Coming)
USB Serial Connectivity
TCPIP Socket Connectivity (this)
I have previously published some seminal articles on UWP connectivity to Arduino and Windows 10 IoT-Core over Bluetooth Serial:
Bluetooth is a short range radio hardware and software protocol for exchanging data between devices. Whilst there are are a number of Bluetooth Versions implemented in hardware up to version 4.x (version 5 has been mooted) there are essential two types of Bluetooth currently available. There is the later LE (low energy) standards and the classic Bluetooth. With Classic BT, the BT hardware (either embedded in the device or added as (typically) a USB dongle) will support some generic BT profiles upon which one or a number of BT profiles. For example, the dongle as envisaged above supports Bluetooth Serial which when enabled on a device adds a virtual serial port to the device. A “classic” Bluetooth headset would have the headset server profile. An audio device would then support the support the headset client profile. A subset of profiles is:
There is also the SDP, the service discovery protocol so that connecting devices can query what services are supported.
Devices have to be paired which is generally a manual activity. One end initiates the connects (Master) by searching for and selecting devices (Slave) that are advertising their presence. There is often a numeric value taht needs to be sent for the Master to Slave at connection to validate the connection; This in earlier devices was fixed (at eg 0000 or 1234) or may be generated by the Slave with which the configurer then enters at the Master for transmission back to the Slave.
Version 1.1 of BT was the stable version that saw adoption of this standard. Except for protocols such as serial, the two end sof the communication are asymmetric. One end generates the data and the other consumes it; a client-server architecture.A headset will consume music streamed to it from a PC. In the past, PC had inbuilt capability for a number of classic protocols such as HID, A2DP, SPP and PAN. and were therefor moderately general purpose with respect to BT. When a device was paired with a PC you could easily see what profiles were supported over the connection.
Versions 2.x and 3.x were backwards compatible with 1.x but added features (profiles) as well as fixed bugs. But they were in the same camp as V1.x There was an enhancement added in V3 EDR. enhanced data rate. Whilst BT 1.x was essentially about exchanging small amounts of data at a time, continuous streaming was not an option. EDR added that capability.
Bluetooth 4.x is a substantially different protocol and architecture.:
BLE: Bluetooth Low Energy is a wireless personal area network technology. Compared to Classic Bluetooth, Bluetooth Smart is intended to provide considerably reduced power consumption and cost while maintaining a similar communication range. BLE has broad range of Profiles, such as Heart Rate Monitor, Sensor, Proximity etc. Each has a standardised set of services, which have characteristics that deliver standardised data. So if you have, for example, a BLE Heart Rate Monitor, you can develop apps for it based upon Bluetooth Sig documentation without regard to the manufacturer. A BLE device will typically implement a number of profiles starting with the BLE Generic Access Profile.
GATT/GAP: Generic Attributes/Generic Profile. The Generic Attributes define a hierarchical data structure that is exposed to connected BLE devices. GATT profiles enable extensive innovation while still maintaining full interoperability with other Bluetooth® devices. A profile describes a use case, roles and general behaviours based on the GATT functionality. Services are collections of characteristics and relationships to other services that encapsulate the behaviour of part of a device. This also includes hierarchy of services, characteristics and attributes used in the attribute server.
GATT Client and Servers: A BLE sensor would be a server as it servers up data on request or as available (on change/periodically) to clients. A desktop or phone app would be a client. GATT procedures can be considered to be split into three basic types: Discovery procedures, Client-initiated procedures and Server-initiated procedures. The GATT server stores the data transported over the ATT and accepts ATT requests, commands and confirmations from the GATT client. The GATT server sends responses to requests and sends indications and notifications asynchronously to the GATT client when specified events occur on the GATT server. GATT also specifies the format of data contained on the GATT server.
One key thing with BLE is the capability to connect devices automatically based upon advertisement. A new device advertising itself in the vicinity of a device that consumes its data type can be connected to without user intervention. For example, a mobile device passing a beacon could upload data whilst it is in range. Note that this automatic connection was not available in Windows 10 until the Creators Edition.
Note: BLE device may or may not be backwards compatible with Classic BT. If it is so compatible then the hardware radio needs to be able switch mode. A BLE sensor may not be so compatible whereas a BT LE 4.x USB dongle probably is. The incompatibility may just though be wrt which Classic protocols are supported.. My laptop, circa 2013 is backwards compatible whereas I have found my Surface Book 2 does not support Bluetooth Serial Update: (See note a end though). Windows 10 can support BT Serial (see later).
I have previously written a number of articles and developed projects for interfacing a UWP app with a a BLE senor such as the Texas Instruments SensorTag 2
BLE does not have a Virtual Serial Port service so you need to use the Classic SPP profile.
So where is this discussion headed? This article is about using BT Serial to connect the UWP app as the UI for an Arduino Sketch app). If modern computers/laptops/tablets don’t support SPP then what can be done; and how do you enable it in Windows 10.
PS: In this section I refer to a Generic Bluetooth (BT) (USB) dongle. By this I mean a classic Bluetooth device (as opposed to a BT LE device) that supports SPP, the classic Bluetooth virtual serial port. A BT dongle may though support both LE and classic modes of operation. Note that this “Generic” reference has nothing to do with the BLE GATT Generic Attribute. I have a number of BT Classic Dongles of varying ages from 2006, 2011 and 2016. They all have a versions of the Cambridge Silicon Bluetooth Radio:
The 3 BT Dongles supporting SPP, 2 of which are BLE and support backwards compatibility.
The Arduino Uno BT Shield support s BT Serial and won’t connect and pair with some of my compute systems:
Bluetooth Radios on my Laptop when the Generic BT device is enabled.
To connect to the Arduino BT Shield, the pairing has to be initiated from the Windows 10 compute device that has or will have the UWP app, you firstly need to get the Generic BT dongle inserted and running.
Make sure the device IS NOT CURENTLY CONNECTED TO ANOTHER DEVICE, It may be paired to other devices though.
From All Settings from the far right of the Toolbar (ie the bottom right corner of the screen) select Devices, then select Bluetooth & Other Devices (it should default to this), and turn Bluetooth On if not so already, The click on the + to Add a Bluetooth Device:
On the Add a Device dialog select Bluetooth:
You then get the device, or devices to pair with. I may initially show Unknown Device so wait until it determines its name. With the Arduino Shield I used you get the HC-05:
Select the device and it will prompt for a pass key. In this case I used 1234. As mentioned above, the other often used key is 0000 .
Press Connect and you are away, hopefully. It is at this point on my Surface Book 2 I get (in yellow text) “Try connecting your device again”. (See nb below)
The issue may be if you get that message is that the device is currently connected to another device so before pairing make sure it isn’t.
Back on the Bluetooth & other devices tab you should see the HC-05 paired:
You then have to check that the device has a virtual serial port and assign one if not. From the Bluetooth & other devices tab, from the Related setting list on teh right select More Bluetooth options:
The BT Com Ports settings.
The app will be initiating the connection so we don’t need Discoverability and only need the Outgoing case. If none are showing you can add ports contigent upon there being a suitable BT pairing (ie supports BT Serial). To do this click Add:
Click on Outgoing and select the device from the list. You will see the list of relevant services for the connectivity, in this case Dev B. Click OK
You will then see the assigned port, in this case COM3. You should also be able to see the COM port in Device Manager.
Next: Bluetooth Connectivity 2/2 -Software