SFE Bluetooth Fun

I am getting started with the bluetooth module from Sparkfun :

It is a parts that attaches to an mbed serial port, and you can talk to it in one of two modes, COMMAND or DATA. In commant mode you send AT commands to configure stuff. You then send an AT command to enter into the DATA mode. When in data mode, you are just talking over a serial port. When the data stream contains the escape sequence "+++" the device returns to COMMAND mode.

Wiring it up

it is a pretty striaght forward module :

  mbed             Bluetooth 
  ====             =========

  +3.3v ------->   VDD (9)
     26 ------->   RST (3)
  RX 27 ------->   TX (11)
  TX 28 ------->   RX (10)
    GND ------->   GND (1) 

First conenction

So the first thing to do is type AT commands at the module, and get a response. So i write a little program that spins in a while(1) lop passing stuff from the USB serial port to the bluetooth serial port. Two points I eventually realise :

  • The Bluetooth modules UART factory default is 115,200
    • I know this cos i accidentally issues AT&F and then spent 20 mins trying to talk to the module again :-(
  • The RST pin is active low... so i should do a quick reset sequence, leaving it high.

Hurrah, so I can now at least exchange AT commands...

AT
OK
ATI
1SPP - Ver: 1.2.5
OK

So, time to read the user guide

Setting Up Serial Comms

#include "mbed.h"

Serial bt(28, 27);
DigitalOut btrst(26);
Serial pc(USBTX, USBRX);

int main() {
    pc.printf("Hello Wolrd\n");

    // Bluetooth Setup
    bt.baud(9600);
    btrst = 0;
    wait(0.5);
    btrst = 1;
    
    while(1) {
    	if(pc.readable()) {
    		bt.putc(pc.getc());
    	}	
    	if(bt.readable()) {
    		pc.putc(bt.getc());
    	}
    }
}

Connect terminal to mbed USB serial port, Reset board

> Hello World!