Main Site Documentation

Bluetooth Module and Spider using NETMF 4.2


I run the code below on my Spider:

using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Shapes;
using Microsoft.SPOT.Touch;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;

namespace BlueToothEmbedded
    public partial class Program
        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
            Debug.Print("Program Started");
            bluetooth.BluetoothStateChanged += new Bluetooth.BluetoothStateChangedHandler(bluetooth_BluetoothStateChanged);
            bluetooth.DataReceived += new Bluetooth.DataReceivedHandler(bluetooth_DataReceived);
            Gadgeteer.Timer timer = new Gadgeteer.Timer(10000, Gadgeteer.Timer.BehaviorType.RunOnce);
            button.ButtonReleased += button_ButtonReleased;

        void button_ButtonReleased(Button sender, Button.ButtonState state)
            Debug.Print("Pairing mode entered");

        void bluetooth_DeviceInquired(Bluetooth sender, string macAddress, string name)
            Debug.Print("MAC: " + macAddress + "\t\tName: " + name);

        void bluetooth_DataReceived(Bluetooth sender, string data)
            Debug.Print("Data: " + data);

        void bluetooth_BluetoothStateChanged(Bluetooth sender, Bluetooth.BluetoothState btState)
            Debug.Print("State: " + btState.ToString());

        void timer_Tick(GT.Timer timer)
            if (!bluetooth.IsConnected)
                Debug.Print("Pairing mode entered");

And get the following output in the output window

The debugger now sits here until I press the button, at which point the BT module enters pairing mode

The red LED flashes alternately with the blue a couple of times then the red stops altogether so I press the button again.

I get the same behaviour as before so I press the button for a third time.

This time my phone says that I have connected but the BT module doesn’t appear to come out of pairing mode. I used “0000” as the code, which seems to have been accepted. After a few seconds my phone (which I am using just to troubleshoot the BT as I intend to write a client app that uses BT to retrieve data from the Spider) shows it’s no longer connected and the BT module is still in pairing mode (red-blue alternate flashing LEDs).
Any thoughts as to what is going on and why the BT doesn’t exit pairing mode?
Many thanks,


check this article out:

and this when you have time :slight_smile:



@ Jay Jay - Arduino, BT and Win8.1 in the same sentence…wash your mouth out with soap!!! :hand:


I don’t mind the bitter taste as long as WP8 is part of the mix :-[

we need those BLE of yours mass produced :whistle:


@ Jay Jay - and a none preview build :wink:


@ Jay Jay, thanks for the article link. However, it hasn’t helped me figure out why I can’t even pair correctly with the Gadgeteer BT module. I’ve even tried a BT dongle on my Win7 laptop but I can’t get the BT out of pairing mode.

Any other thoughts?


I’ve even looked at this code and switched it to a Spider but I get a very similar behaviour.

J. :wall:


that’s the thing, you don’t pair the device…
you need to use the WP8 code posted on the article and connect from the APP directly not through the Pairing mode of Bluetooth as you know it.

try it and it will work :slight_smile:

remember you are using Bluetooth serial which is a bit different…



I’ll keep you posted.




@ Jay Jay, should I follow the same approach for connecting to a PC or WinRT device?


I would try a shorter device name.
with the code of my driver I had no problems to pair with a PC