Main Site Documentation

How Do I Make Bluetooth Module Discoverable?


#1

Hi,

I am a newbie to .Net Gadgeteer. I just purchased the Fez Cerberus and the Bluetooth module. I could use some help with the code so that the Bluetooth will be discoverable. I don’t have any code yet since tutorials and other documentation do not seem to exist when I follow the links from the product page here.

Anyway, if you have a few lines of code that will get me started with Bluetooth, I would appreciate it.

Cheers!


#2

A Good Starting Point is http://www.tinyclr.com/codeshare/entry/446


#3

@ andre.m and @ RoSchmi
Thank you for the resources. They have helped me get stated.

Interestingly the device does not seem to be discoverable on an iPhone 3GS. I was able to discover the device on Windows Phone 8, Windows 8 Pro (laptop), and Surface RT.

There was one little snag though, I have to place a break point on the client.EnterPairingMode(); and then step over before the device shows up. If I run the code without the break point then it is not discoverable. Here is the code below:


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.Touch;

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

namespace GadgeteerBlueTooth
{
    public partial class Program
    {
        Bluetooth bluetooth;
        Bluetooth.Client client;
        
        
        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {
            /*******************************************************************************************
            Modules added in the Program.gadgeteer designer view are used by typing 
            their name followed by a period, e.g.  button.  or  camera.
            
            Many modules generate useful events. Type +=<tab><tab> to add a handler to an event, e.g.:
                button.ButtonPressed +=<tab><tab>
            
            If you want to do something periodically, use a GT.Timer and handle its Tick event, e.g.:
                GT.Timer timer = new GT.Timer(1000); // every second (1000ms)
                timer.Tick +=<tab><tab>
                timer.Start();
            *******************************************************************************************/


            // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
            Debug.Print("Program Started");

            bluetooth = new Bluetooth(2);
            client = bluetooth.ClientMode;

            bluetooth.SetDeviceName("Gadgeteer");
            bluetooth.SetPinCode("1234");
            client.EnterPairingMode();
            
        }
    }
}

Any ideas on why I have to enter that break point and then step over it to be recognized?

Cheers!


#4

The module does not start instantly. You need it to complete the initialisation before entering pairing mode, which is what your break point is doing. That is why I have my code waiting for a button press. You could also try some arbitrary delay in ProgramStarted (but that’s not going to be reliable in my view, and not good practice) or use a single -shot timer to get a longer delay say 15+ seconds, and enter pairing mode in that.

But remember, you only need pairing mode once; once it’s paired with a device, you then just need to connect to it to have it work, assuming it has completed initialisation.

The reason it won’t connect on iPhone is that there’s no support for serial ports on iPhone; which is all this BT module offers.


#5

@ Brett - Much appreciated the information. Especially the information regarding the Bluetooth module. I have implemented a timer for the time being. Good to know about the iPhone as well.

Does Android support Bluetooth over serial ports?


#6

Android sure does; I had a serial port connection from the BT Hydra combo into my wife’s Samsung Galaxy Tab 10.1 using a standard Serial Port app from the store