Elastic Sheep

Because elasticdog was already taken

Elastic Sheep header image 2

Serial Bluetooth module – Master/Slave connection

May 20th, 2011 · 16 Comments · Uncategorized

I have soldered a second serial Bluetooth module. I am now going to test them in a master/slave configuration.

The test boards

The first test board is the one already used for my slave test with a Teensy 2 as USB to serial adapter and power supply. This board will be the master one.

The second test board is powered by a USB connector and a 3.3V regulator. A serial connection is establish with my laptop through a Prolific PL2303 adapter. This board will be the slave one.

Slave module configuration

The slave module is powered up in command mode. Cu does not seem to work correctly anymore with the PL2303 so I use screen instead:

$>screen /dev/cu.serial 38400
AT+ADDR?
+ADDR:11:3:252002
OK
AT+UART?
+UART:9600,0,0
OK
AT+ROLE?
+ROLE:0
OK

Role=0 is for the slave mode. I keep the default 9600 baud UART speed.

The module Bluetooth address will be useful to establish the connection from the master module.

Master module configuration

The master module is powered up in command mode. The role is changed to 1 for master. The UART baudrate is set to the same as the slave module.

$>sudo cu –s 38400 –l /dev/cu.usbmodemXXXX
AT+UART?
+UART:115200,0,0
OK
AT+UART=9600,0,0
OK
AT+UART?
+UART:9600,0,0
OK
AT+ROLE?
+ROLE:0
OK
AT+ROLE=1
+ROLE:1
OK
AT+ROLE?
+ROLE:1
OK

To establish an automatic connection to a slave module, the master module must know the slave address. This is configured with the AT+BIND command with CMODE=0 (Use a predefined address).

AT+CMODE?
+CMOD:0
OK
AT+BIND=11,3,252002
OK
AT+BIND?
+BIND:11:3:252002
OK

With CMODE=1, the master can connect to any device in its transmission range, so it is a much less secure configuration.

Master/Slave automatic connection

Now that the two modules are setup, I power up them in automatic mode (PIO11 = 0).

On each module, the red leds connected to PIO8 blinks quickly. After less than 2 seconds, the green led connected to PIO9 is shining on both modules indicating that they are now paired and connected, ready to transmit data.

I connect a terminal to the serial port of each module with their respective adapter to test the communication:

The first window displays the connection to the master BT module. The second window displays the connection to the slave BT module.

The connection is successful at 9600 bauds. I also successfully tested the communication at 115200 bauds.

Tags: ···

16 Comments so far ↓

  • argon

    Great article!!! do you know how to use the spp feature of this device. I want to use it to connect to a Motorola Droid 2.

  • The Chief Sheep

    Hi Argon,
    The module acts as a SPP device.
    You should be able to pair it with your Android handset. Then you may require a specific application to exchange data between the device and the phone.
    BR
    Mathieu

  • Rolf

    Great Info!!! Now I´m trying to connect two bluetooth slave devices with 0ne master. How could I add the adress of the third device to get an automatic conection?? thanks in advance. Best regards.

  • Bpp

    Is there a way to put this BT module in sleep or any other low power state?

  • Jacob

    I’d like to ask the same question as Rolf. Is there a way to connect 2 Slaves to 1 Master? Rolf, do you solved this? Or can anyone give me some tips?
    Thanks in advance.

  • KK

    I have the same question as Jakob and Rolf, is there any way to connect more than one slave with the master?
    Best Regards

  • The Chief Sheep

    Hi KK,
    From what I have gathered, the SPP protocol is restricted to one master-slave couple.
    To use multiple slaves, you would need a multi-instance SPP implementation in your master module.
    The Bluetooth module I have been using don’t support this mode.
    BR,
    Mathieu

  • AlferSoft Blog » Protoboard adapter for cheap Bluetooth module

    [...] # 1 and 2) and any character you send will be echoed. This fantastic page Elasticsheep.com gives detailed instructions on how to test the module. Download schematics, Eagle CAD library and PDF and feel free modify and [...]

  • Generic 3.3v BT Module BoB « Light as a Feather

    [...] Master to Slave Connection Howto [...]

  • Digilee

    Do you have a place that you have gathered information for this project into one place or path? I am interested in using something very similar to add an external custom keyboard to an android cell phone. The keyboard is to provide single button functionality for an elderly person.

  • Digilee

    Never mind, I’m asleep. I looked further and found the path.

  • Peter Bierman

    I think the ‘cu’ command doesn’t work with the PL2303 because the driver comes up with hardware handshaking turned on. (And the repurposed nokia PL2303 serial cables I’ve played with don’t bring out the CTS/DTR pins.) Terminal software like screen and ZTerm turn off the hardware handshaking mode.

  • Stan Green

    I have this somewhat working. However, I can only issue one command with the exception of I can send RESET then one more command. The command will work, but starts returning OK in an endless loop. If the command was for data, it returns the data endlessly. What would cause this to happen?

    Thanks,
    Stan

  • Stan Green

    Found the answer to my own question. It is on the Serial Bluetooth module slave test page of this site. The trick is to use Ctrl+C to stop the loop.

  • Jay

    Hii….i want command for receiving the data….
    I have bluetooth module with serial port(0683)

  • The Chief Sheep

    Hi Jay,
    What are you trying to do?
    BR
    Mathieu

Leave a Comment