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:
- Read the User Manual
- Serial speed: By default, BlueSmirf is set to 115200 so you need to call Serial.begin(115200); before sending the first command.
- 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.
- Read and validate all the responses that are sent back.
- 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.
- 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).
\n,\n\ror\r\nthrough aSerial.print()? Depending on the protocol used, some serial devices require a carriage return, a linefeed, or a CR-LF pair, as an End-of-Line delimiter. – Anindo Ghosh Apr 10 '13 at 08:15