Bluetooth Woes

Looking for a little advice. I HAD it working as intended. Press a button (1), turn on the mainboard led. Press another buttin (2) turn the LED off. Worked great. I changed the baud rate with bt.SetDeviceBaud(115200) and it freaked out. When I compile and push to the device, this appears in the output window:

[quote]Using mainboard GHI Electronics FEZHydra version 1.2
Reader Thread
Program Started
Client Mode
Enter Pairing Mode

The thread ‘’ (0x3) has exited with code 0 (0x0).[/quote]

I’ve tried to set it back to 9600 manually, but nothing changes. Same garbage in.

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.Seeed;
using Gadgeteer.Modules.GHIElectronics;

namespace GadgeteerApp5
    public partial class Program
        // 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>

            // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.

            LCD.SimpleGraphics.AutoRedraw = true;
            oled.SimpleGraphics.AutoRedraw = true;
            oled.SimpleGraphics.DisplayText("Bluetooth Enabled", Resources.GetFont(Resources.FontResources.small), GT.Color.Red, 10, 10);

            Debug.Print("Program Started");

            bt.DebugPrintEnabled = true;

            bt.BluetoothStateChanged += new Bluetooth.BluetoothStateChangedHandler(bt_BluetoothStateChanged);

            Bluetooth.Client client;

            client = bt.ClientMode;

            LCD.SimpleGraphics.DisplayText("Bluetooth Waiting for Connection...", Resources.GetFont(Resources.FontResources.NinaB), GT.Color.Blue, 20, 20);
            bt.DataReceived += new Bluetooth.DataReceivedHandler(bt_DataReceived);

        void bt_DataReceived(Bluetooth sender, string data)
            if (data == "1")
                //oled.SimpleGraphics.DisplayText("LED ON", Resources.GetFont(Resources.FontResources.NinaB), GT.Color.Green, 10, 20);
            if (data == "2")
               // oled.SimpleGraphics.DisplayText("LED OFF", Resources.GetFont(Resources.FontResources.NinaB), GT.Color.Green, 10, 20);
            LCD.SimpleGraphics.DisplayText("Recieved: " + data, Resources.GetFont(Resources.FontResources.NinaB), GT.Color.Blue, 10, 10);

        void bt_BluetoothStateChanged(Bluetooth sender, Bluetooth.BluetoothState btState)
                LCD.SimpleGraphics.DisplayText("State: " + btState, Resources.GetFont(Resources.FontResources.NinaB), GT.Color.Blue, 40, 40);
                oled.SimpleGraphics.DisplayText("State: " + btState, Resources.GetFont(Resources.FontResources.small), GT.Color.Blue, 10, 10);
                if (sender.IsConnected)
                    oled.SimpleGraphics.DisplayText("Connected!", Resources.GetFont(Resources.FontResources.small), GT.Color.Green, 10, 20);
                    oled.SimpleGraphics.DisplayText("Not Connected", Resources.GetFont(Resources.FontResources.small), GT.Color.Red, 10, 20);

Anyone have an idea why I can’t get good data back into or out of my Bluetooth module? I am running 4.2.

have you tried. to repower?

I have moved modules around, I am currently using a powered Hub. I’ve tried powering it with an extender and 5v. It worked for a bit on the USB hub, but when I changed the baud, it freaked out and started printing garbage.

when I remember right, the Bluetooth module holds the once set baudrate even after powering up. Set baudrate to 115200 and then set the baudrate to the wanted baudrate e.g. standard baudrate 38400. Hope this helps.

the garbage characters is certainly a baud mismatch, so you need to get back to the correct baud rate you originally had (I didn’t have the same experience that Roland points out!).

I don’t think the driver correctly handles a change in baud rate - it sends the command to the module but then never changes the serial port (at least in Eduard V’s driver which I started using and modified for this 4.1 project )

If you use the driver with the mods I proposed (you can get that from the project) you’ll get a new constructor that will allow you to open it at the desired baud rate. That’s worked pretty reliably for me, but of course YMMV

Brett is exactly correct. Went back to step zero. Set the baud to 115,200, set the serial port 115,200, and everything works perfectly. Thanks Brett!