I dug out a project I worked on a year ago with Bluetooth using the drivers from Eduardo Velloso, I fired up the board and everything worked great. In that year though I upgraded my computer to Windows 8 and Visual Studio 2012. So installed the SDK and ensured that NetMF 4.2 was on the machine. The I updated the Firmware and bootloader on my Fez Cerberus board then I encountered problems.
Board: Fez Cerberus
Once I got all updated and compiled my solution, I get an error in the Bluetooth.cs file that suggested I may be missing a namespace as GTI.Serial was not recognized. I appears that Serial was removed from Gadgeteer.Interfaces. So I checked the developers guide for the Bluetooth module and noticed that I can now use the designer to add Bluetooth. I set out to change over my code.
Now that my code was changed over I am getting the error: Error invoking method “Gadgeteer.Modules.GHIElectronics.Bluetooth” (check arguments to Program.BeginInvoke are correct) I have tried to work through this but it is not working.
Note: I have Bluetooth go into pairing mode only when a button is pushed but the device does not go into that mode (i.e. the red and blue leds do not alternate flashing, it only flashes blue.)
launchtimer = new GT.Timer(1000);
launchtimer.Tick += new GT.Timer.TickEventHandler(launchtimer_Tick);
bluetooth.BluetoothStateChanged += bluetooth_BluetoothStateChanged;
bluetooth.DataReceived += new Bluetooth.DataReceivedHandler(bluetooth_DataReceived);
button.ButtonPressed += new Button.ButtonEventHandler(button_ButtonPressed);
This is everything that is posted in the Output window:
A first chance exception of type ‘System.NullReferenceException’ occurred in GadgeteerBlueToothTest.exe
Error invoking method “Gadgeteer.Modules.GHIElectronics.Bluetooth” (check arguments to Program.BeginInvoke are correct)
So I tried Brett’s solution and created a brand new project. So I no longer get the first time exception or any of that but the problem remains that Bluetooth is not entering pairing mode. I had setup a button to enter pairing mode on button press and also set up a one time timer to do the same thing after 10 seconds. Nothing put it into pairing mode (red and blue led flashes).
I changed the device name in the new app form the older app and then checked Bluetooth devices on my phone and the old device name appeared (I had deleted it from the phone prior to testing).
Almost seems like the problem is the Bluetooth device, like it has been bricked or something. Is there a way to check for that?
Because you’re interfacing over serial, any issue on serial lines or even timing issues can get in the road. Ro’s code is a good step to try… my personal thought is you just need to try the simplest setup (no name changes, nothing) and see if that works.
Ok I have made some progress using Brett’s method of starting simple. I found that my phone keeps the last device name used unless I turn the Bluetooth radio off and then back on. Also this resolves the issue with going into ClientModePairing.
The remaining issue is that the data collected by Bluetooth_DataReceived only seems to be half the data I sent it.
Example of data sent:
Phone sends data as a string "RGB,XXX,XXX,XXX") where XXX == 0 -255
Gadgeteer board seems to receive half the data but does two reads for the full data, This problem did not exist previously.
I have just using Debug.Print(data); in the event handler for now. I will look @ RoSchmi's code tomorrow. In the meantime others have experienced this issue or know how to get past it that would be great.
I have confirmed that the phone app is sending the data all at one time.
Lets remember that “data received” events are NOT deterministic ways to get “full strings” over a serial connection. You always should be handling the data queuing in your own app and assemble data as you detect your own terminator.
Yes, this seems to have changed from NETMF 4.1 to 4.2, at least in the cerb family. Also the messages from the bluetooth circuit to the serial port of the mainboard in the module driver arrive in chunks so that they cannot be correctly parsed by the original driver code of Eduado Velloso and Brett. To relieve from this issue, I integrated a circular buffer in the driver, so that the Bluetooth module gets complete strings (delimiter Hex 0x0A) which then can be correctly parsed by the driver code and then are send as complete strings through the eventhandler to the application code.
I always look at serial data as a gift. If you get everything you need in an interrupt-handler method, you’ve got a great gift, if you get it in dribs and drabs, well at least it arrived. (seriously, you were lucky if your previous experiences delivered it in chunks you wanted, by design a data received event needs to just present what it has)
OK, guys. This has been great, but I’m in the same boat as everyone else seems to be when it comes to Bluetooth. Out of the box example code doesn’t work. When I finally get it to pair (by trying over and over and over) it only stays connected for about 6 seconds and the Bluetooth object never shows a connected state.
I am trying to use your driver, RoSchmi and I don’t have exactly the same configuration. I download and it compiles just fine. But I can’t really test it.
BUT… I have a Cobra II WiFi and the Bluetooth module.
I noticed that the Bluetooth_Pairing_Test is using a Cerberus (which I have ordered) and a Serial module (which I did not).
I know this is going to sound really dumb, but I thought all I needed was a Bluetooth module to do this communication. Isn’t it providing it’s own UART and serial capabilities?
I have my Windows 8 desktop configured with COM3 assigned to the Bluetooth adapter and Tera Term opened on COM3.
I figured the Bluetooth module would connect, then accept the data I was sending it, forward it on to the desktop Bluetooth adapter and Tera Term would show me the results.
In the long term, I’m trying to hook this up to my Windows phone Bluetooth to get data from the NETMF board (whichever one I end up using).
What am I missing here?
Also, I might actually be better served with NFC as the communications link. Would that be easier than Bluetooth?
@ willy -
you do not need an rs232 module to use my driver. It was only included for tests to send the messages received over bluetooth back to the PC where they came from. Delete the rs232 module in the designer and outcomment the code segements concerning rs232.
For Cobra II set: MySocketNumber = 5
Do not include the bluetooth module in the designer but connect it physically to socket 5 of the Cobra II.
The other thing to know is that often the serial port on the pc side only becomes active after you have paired, so the process should be pair them, check the device manager com port number, connect to any Bluetooth related ones and see if you get data coming back. If not, try them all before giving up.
 The latest update to WP8 doesn’t include a standard API for SPP, which is one of the things that is making this harder than it should be. There is sample code (which I will try) that claims to make it work, but so far I haven’t had any luck.)
I thought I would post a little something here, just in case it’s correct.
I am trying to hook Cerberus/BT module to a WP8 app. One of the connection properties allows for a “service class” guid to be specified.
I can’t find any reference to what the GHI BT module would be using, so I looked around and found this:
Well, I have at least established some consistency…
I thought pairing was like establishing a connection in wifi. Once the network connection was made, you were finished.
But I now believe that Bluetooth “pairing” really isn’t completed when you simply enter the PIN code. At that point the module’s red and blue lights are still going even though you’ve typed in your PIN and the phone says “connected”. The Bluetooth module doesn’t change it’s state and doesn’t fire a state change event.
But, if you launch your app and attempt to connect to the device - and quickly, too - the connected event fires and now the little guys know each other.
When that happens, the pairing seems to be complete and after that, everything seems to work as advertised.
From that point on, I can drop the connection and the Bluetooth status reflects it and then reconnect without attempting to pair again.
Wish I had known that little fact about 4 days ago.