Main Site Documentation

Bluetooth Module and Spider using NETMF 4.2


#1

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.SetDeviceName("Gadgeteer001");
            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;
            timer.Start();
        }

        void button_ButtonReleased(Button sender, Button.ButtonState state)
        {
            Debug.Print("Pairing mode entered");
            bluetooth.ClientMode.EnterPairingMode();
        }

        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);
            //sender.ClientMode.SendLine(data);
        }

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

        void timer_Tick(GT.Timer timer)
        {
            if (!bluetooth.IsConnected)
            {
                bluetooth.ClientMode.EnterPairingMode();
                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,
Jason.


#2

check this article out:
http://developer.nokia.com/community/wiki/Windows_Phone_8_communicating_with_Arduino_using_Bluetooth

and this when you have time :slight_smile:

Cheers,
jay.


#3

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


#4

lol,
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:


#5

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


#6

@ 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?


#7

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

https://www.ghielectronics.com/community/codeshare/entry/763

J. :wall:


#8

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…

cheers,
Jay,


#9

I’ll keep you posted.

Thanks,

J.


#10

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


#11

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