Tutorial 2
Using a Bluetooth slave serial adapter


This project consists of a Bluetooth slave serial adapter attached to COM4 on the Fez Panda II. A simple C# program reads 1 byte from the serial port and writes it to the output. In other words, it acts as a wireless loopback.

On the laptop, a USB Bluetooth creates a virtual serial port (COM14) when it pairs with the slave adapter. Using putty, a terminal session is established to COM14. When characters are typed in putty, they are transmitted by the USB adapter to the slave adapter on the Panda II where the C# program echoes the characters back onto putty.

The Bluetooth slave serial adapter was purchased from MIB Instruments (Hong Kong) through ebay.com.au for USD13.00. Just search for "Arduino Bluetooth Module Slave Wireless Serial Board".



FEZ Panda II with the Bluetooth slave serial adapter:

USB Bluetooth adapter for the laptop:



The C# program is shown below:

/*
 * Simple comms test for bluetooth slave serial adapter. Bytes received by adapter are
 * echoed back to to sender. PC requires a USB-Bluetooth adapter which creates a 
 * virtual COM port when it pairs with a slave adapter. Wiring:
 * Orange D31 TXD
 * Purple D33 RXD
 * Black Gnd
 * Red 3.3V
 */
using System;
using System.IO.Ports;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.Hardware;
using GHIElectronics.NETMF.FEZ;

namespace BluetoothTest
{
    public class Program
    {
        static SerialPort UART;
        static bool isRunning = true;

        public static void Main()
        {
            byte[] buffer = new byte[16];

            UART = new SerialPort("COM4", 57600);   //adapter must be set to 56700
            UART.Open();

            while (isRunning)
            {
                    int blen = UART.Read(buffer, 0, 1); //read 1 byte from COM4
                    UART.Write(buffer, 0, blen);        //write byte to COM4
            }
            UART.Close();
            Debug.Print("COM port closed.");
        }
    }
}




Bluetooth Slave AT command set

The AT commands below can be used with the module but only with software version Linvor v1.5. You must enter commands in Notepad, then cut-paste onto putty session. Normal typing does NOT work! If changing baud rate, close putty immediately after change, and reopen with new rate. Commands must be in UPCASE, no ENTER required at EOL.
 AT+VERSION Returns the software version of the module
 OKlinvorV1.5

 AT+BAUDx Sets the baud rate of the module
 The command AT+BAUD8 sets the baud rate to 115200
 1 >> 1200
 2 >> 2400
 3 >> 4800
 4 >> 9600 (Default)
 5 >> 19200
 6 >> 38400
 7 >> 57600
 8 >> 115200
 9 >> 230400
 OK115200
 
 AT+NAMEOpenPilot Sets the name of the module
 Any name can be specified up to 20 characters
 OKsetname

 AT+PINxxxx Sets the pairing password of the device Any 4 digit number can be used, the default
 pincode is 1234
 OKsetPIN
 
 AT+PN Sets the parity of the module
 AT+PN >> No parity check
 OK None