BT Shield 2.2 on Fez Panda II

Hi
I just recieved my Itead Bluetooth Shield V2.2…

Ive switched it to DAT mode.
Ive set the jumpers like this: http://home.comcast.net/~tomhorsley/hardware/arduino/cmd-bluetooth-jumpers.png
Ive stacked it ontop of my Panda, and connected the USB to the panda…

I now get a green light in PWR, and a fast blinking light in Status on the BT Shield…
I then tried parring the devices from my computer, with the default 1234 password, and it installs 2 new BT COM ports (COM4 and COM5)…

But now what? I tryed connecting with tera term to device, but i cant write anything`? is that normal?
I also tryed setting it in AT Mode, using this guide: http://home.comcast.net/~tomhorsley/hardware/arduino/datasheet.html
But still no luck with teraterm…

How would i go about using this? Anyone have some steps i could follow? or maybe a demonstration of some sort.

I doubt anyone here is familiar with your itead bluetooth board so some links and info on what pins it uses will be helpful.

@ Gus - I was just thinking maybe someone knew this board…
But this is what i got:
Datasheet on BT Shield: ftp://imall.iteadstudio.com/IM120417010_BT_Shield_v2.2/DS_IM120417010_BTShield.pdf
Datasheet on the used BT Module: ftp://imall.iteadstudio.com/IM120417010_BT_Shield_v2.2/DS_BluetoothHC05.pdf

Looks like they built the board so you can wire tx and rx pins. Those need to be on pins D0 and D1 where uart pins are

This is where I just love gadgeteer :slight_smile:

@ Gus - yeah thats done. Tx to d0 and Rx to d1…
But still not able to type in teraterm. Or putty for that matter…
Any ideas? Or maybe a shield that would work better/more used?

Ohh yes. Really thinking about buying a new fez…
Not sure wich though…

I really do not know. I never used it.

I don’t have direct experience with HC05, but they’re simple.

First up, you need to tell us how you have established that you have comms to the BT module. Have you been able to issue commands to it and receive responses from it? This is purely in the Netmf space - if you can’t get any kind of response from the device, you’re probably suffering from uart dyslexia and need to connect TX/RX the other way around.

Then, once you establish that you can talk to the module, then you can get it paired to a PC. Then, you should be able to type from the terminal connected to the LOWEST COM port on your PC and then have it appear on the UART on your Fez.

@ Brett - That helped alot, i got contact via the Panda and im able to send AT commands and det responds…
Ive set it up as a slave, and paired it with the PC.
Still cant seem to get a connection through TeraTerm or Putty where im able to send commands…

But i tried writing a simple console program that would send a string and on the panda i should read and write it in debug…
But as soon as i run the console app, i get connected, and it sends, but in panda debug i get:

Recieved Data:
    #### Exception System.Exception - CLR_E_WRONG_TYPE (3) ####
    #### Message: 
    #### System.Text.UTF8Encoding::GetChars [IP: 0000] ####
    #### FEZ_Panda_II_Application2.Program::BTport_DataReceived [IP: 0034] ####
    #### System.IO.Ports.SerialPort::DataEventHandler [IP: 0012] ####
A first chance exception of type 'System.Exception' occurred in mscorlib.dll
An unhandled exception of type 'System.Exception' occurred in mscorlib.dll

This is the reader on the Panda:

static SerialPort BTport;
        public static void Main()
        {
            // Blink board LED

            OutputPort led = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, true);

            BTport = new SerialPort("COM1", 38400, Parity.None, 8, StopBits.One);
            BTport.Handshake = Handshake.None;

            BTport.Open();

            BTport.DataReceived += new SerialDataReceivedEventHandler(BTport_DataReceived);

            //startSlave();
            Thread.Sleep(-1); 
            
        }

        public static void BTport_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            // Check if Chars are received
            if (e.EventType == SerialData.Chars)
            {
                // Create new buffer
                byte[] ReadBuffer = new byte[BTport.BytesToRead];

                // Read bytes from buffer
                BTport.Read(ReadBuffer, 0, ReadBuffer.Length);

                // Encode to string
                Debug.Print("Recieved Data:");
                Debug.Print(new String(Encoding.UTF8.GetChars(ReadBuffer)));
            }
        }

And here is the console app that sends:

static void Main(string[] args)
        {
            SerialPort BTserial = new SerialPort("COM5", 38400, Parity.None, 8, StopBits.One);
            BTserial.Handshake = Handshake.None;

            BTserial.Open();
            if (BTserial != null && BTserial.IsOpen)
            {
                Console.Write("Conn Open!");
                byte[] DataToSend = Encoding.UTF8.GetBytes("Hello World!");
                BTserial.Write(DataToSend, 0, DataToSend.Length);
            }
            BTserial.Close();
        }

Baud rate on BT is some kind of “ignoreable” setting. I say that because it’s mostly about the baud rate that you need to talk to the BT module at each end (so on the PC, to your BT module on motherboard or USB module; for the Fez end, it’s the baud rate the module needs to accept commands), it’s more a function of the signal strength that dictates the actual rate you can get bits between the two end points.

So your code is failing on this line:

Debug.Print(new String(Encoding.UTF8.GetChars(ReadBuffer)));

Fix that error. GetChars returns an array of Chars not a string. You will need to use ToString() in there somewhere.

Did you look at the contents of ReadBuffer in the debugger?

@ Brett - I tryed setting the read and encoding up another way:


static SerialPort BTport;
        
        public static void Main()
        {
            // Blink board LED
            
            OutputPort led = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, true);

            BTport = new SerialPort("COM1", 38400, Parity.None, 8, StopBits.One);
            BTport.Handshake = Handshake.None;

            BTport.Open();

            BTport.DataReceived += new SerialDataReceivedEventHandler(BTport_DataReceived);

            //startSlave();
            Thread.Sleep(-1); 
            
        }

        public static void BTport_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            // Check if Chars are received
            if (e.EventType == SerialData.Chars)
            {
                Encoding utf8 = Encoding.UTF8;

                // Create new buffer
                byte[] ReadBuffer = new byte[BTport.BytesToRead];

                // Read bytes from buffer
                BTport.Read(ReadBuffer, 0, ReadBuffer.Length);
                BTport.DiscardInBuffer();
                BTport.Flush();

                // Encode to string
                string data = bytesToString(ReadBuffer);

                Debug.Print("Recieved Data:");
                Debug.Print(data);

                ReadBuffer = null;
                data = null;
            }
        }

        public static string bytesToString(byte[] bytes)
        {
            string s = "";
            for (int i = 0; i < bytes.Length; ++i)
            {
                s += (char)bytes[i];
            }
            return s;
        }

Now i dont get an error. but this string i recieve is not what i sended :slight_smile:
I get:

Recieved Data:
€ðøøüø€øÿøÀ€ø€ø

Hi,
did you compare the contents of your byte[] Array DataToSend of your sender with the byte[] Array ReadBuffer you received with the debugger or only the encoded strings?
Regards
Roland

Good thinking…
I see a problem there… I tryed sending “1234”
I send a 4 byte array with values of:
49 - 50 - 51 - 52

But on the fez i get a 9 byte array with a mix of 128 and 248…

Any ideas?

Hi,
I`d try to discard the contents of the input buffer of your BT module (in Main). Perhaps there is some junk in it, which you get with the first read. Or try to send a second message, perhaps the second is o.k.
Roland

I just tried:
BTport.DiscardInBuffer();
BTport.Flush();
just after i open the port.

Still same message i get…
And when i then tried sending a second message, somthing really weird happend.
It reacts like it received 2 messages, and posting 1 half of the garbled data in one, and then the other half in the other…

I’dont know. Perhaps check the sent and received data in hex or binary to see whether thera are any correlations. Doublecheck the serial port parameters or play around for some hours. I’m off for today.
Roland

I found the error!
I guess it was stupid just to expect the default settings in the manual for the bluetooth shield would be right.
Cause i just testede with an AT command to check the baudrate, and it was only 9600 :slight_smile:
Changed it code, and all works perfect :slight_smile:

Thanks for alle help! :slight_smile:

great to hear. yes I was going to say garbled characters sounds like a baud rate mismatch.