Electronic – arduino – How to create a serial bridge using two Bluetooth dongles

arduinobluetoothhardwareserialsoftware

I own two of the SparkFun BlueSmirf bluetooth modules and I would like to connect them to eachother – one as the master, and one as the slave. It is easy to pair these together using a PC with Putty as the master, but some of the commands for the module require a carriage return to send a command.

How can I pair these bluetooth modules between two Arduinos without using a PC to send the carriage command signal from putty while the device is being configured?

I have thoroughly looked over the datasheet and command sheet for the module itself, but it does not include information of how to get past this problem.

Best Answer

I explain the way to do it on this blog post or in great details on this Instructables. For now, here is the basic code that you can put on the master device and the slave device.

//Master code
void setup() {
  Serial.begin(115200);
  Serial.print("$$$");
  delay(100);
  Serial.println("SM,1");  delay(100);
  Serial.println("C,000666123ABC");
  delay(100);
  Serial.println("---");
}

//Slave code
void setup() {
  Serial.begin(115200);
  Serial.print("$$$");
  delay(100);
  Serial.println("SM,0");
  delay(100);
  Serial.println("---");
}

And some tips before you go further with Bluesmirf:

  1. Read the User Manual
  2. Serial speed: By default, BlueSmirf is set to 115200 so you need to call Serial.begin(115200); before sending the first command.
  3. The "$$$" command is the only one that is not followed by a carriage return. Why? To complicate things of course. Use print() for the "$$$" command and println() for all other commands.
  4. Read and validate all the responses that are sent back.
  5. Wait 100ms delay after each command you send and before trying to read the response. This will give Bluesmirf the time to process the command.
  6. Don't forget to exit the command mode (using “---”). Some commands are not effective until you have exited the command mode (e.g. MS command).