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
SwUêó3¢Äó
3¢Äó
3¢Äó
Sc)bý
3¢Äó
ý
)©)1L
Program Started
Client Mode
Enter Pairing Mode
)©)1L

)©)1L*J,(*.)
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>
                timer.Start();
            *******************************************************************************************/


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

            
            bt.SetDeviceName("Name");
            bt.SetPinCode("0000");
            bt.SetDeviceBaud(9600);
            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;
        

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

        void bt_DataReceived(Bluetooth sender, string data)
        {
            LCD.SimpleGraphics.Clear();
            if (data == "1")
            {
                Mainboard.SetDebugLED(true);
                //oled.SimpleGraphics.Clear();
                //oled.SimpleGraphics.DisplayText("LED ON", Resources.GetFont(Resources.FontResources.NinaB), GT.Color.Green, 10, 20);
                
            }
            if (data == "2")
            {
                Mainboard.SetDebugLED(false);
                //oled.SimpleGraphics.Clear();
               // 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.Clear();
                oled.SimpleGraphics.Clear();
                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);
                }
                else
                {
                    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.

Hi,
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.
http://www.seeedstudio.com/wiki/Serial_port_bluetooth_module_(Master/Slave)
Roland

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 http://www.tinyclr.com/codeshare/entry/446 )

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!