I am trying to setup a RN-42 Bluetooth Mate Silver connected to an Ardunio Uno Rev3 to act as a Bluetooth host (my controller) communicating to another RN-42 Bluetooth Mate Silver connected to an Ardunio Mega 2560 (my main project board has the slave connection).
The problem that I have is that I have not figured out how to send data between the two RN-42s once the connection is established. Each Arduino is able to get its RN-42 into CMD mode, but sending data after the connection is established has not happened yet.
I get a green status light on both Bluetooth Mate Silver modules, but the host response to my connection command (see host code below) never gets beyond “TRYING”.
Both Bluetooth Mate Silver modules are connects to their respective Arduino boards as follows:
// Bluetooth Mate —> Arduino
// -------------- -------
// CTS-I -----------> No connection
// VCC -----------> 5V
// GND -----------> GND
// TX-O -----------> D2
// RX-I -----------> D3
// RTS-O -----------> No connection
The below slave code is running on the Arduino Mega. (All of my code was created using examples found online–staring with SparkFun’s guide.)
#include <SoftwareSerial.h>
int bluetoothTx = 2; // TX-O pin of bluetooth mate, Arduino D2
int bluetoothRx = 3; // RX-I pin of bluetooth mate, Arduino D3
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx); // RX, TX
void setup()
{
Serial.begin(9600); // Begin the serial monitor at 9600bps
bluetooth.begin(115200); // The Bluetooth Mate defaults to 115200bps
delay(400); // Short delay, wait for the Mate to send back CMD
bluetooth.print("$$"); // Enter command mode
delay(100); // Short delay, wait for the Mate to send back CMD
bluetooth.println("U,9600,N"); // Temporarily Change the baudrate to 9600, no parity
// 115200 can be too fast at times for NewSoftSerial to relay the data reliably
Serial.println("U,9600,N");
delay(100); // Short delay, wait for the Mate to send back CMD
bluetooth.begin(9600); // Start bluetooth serial at 9600
delay(400); // Short delay, wait for the Mate to send back CMD
bluetooth.print("$$");
delay(100);
bluetooth.println("SM,0");
delay(100);
Serial.println("Setup complete. Looping...");
bluetooth.println("+");
}
void loop()
{
char control_cmd = 'X';
if(bluetooth.available()) // If the bluetooth sent any characters
{
Serial.println("bluetooth.available");
// Send any characters the bluetooth prints to the serial monitor
control_cmd=(char)bluetooth.read();
Serial.println((char)control_cmd);
}
}
The below code is running on the Arduino Uno host (my project’s controller that will be interfaced with a joystick once I get the bluetooth working).
#include <SoftwareSerial.h>
int bluetoothTx = 2; // TX-O pin of bluetooth mate, Arduino D2
int bluetoothRx = 3; // RX-I pin of bluetooth mate, Arduino D3
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx); // RX, TX
void setup()
{
Serial.begin(9600); // Begin the serial monitor at 9600bps
Serial.println("Serial Port to PC is ready");
bluetooth.begin(115200); // The Bluetooth Mate defaults to 115200bps
delay(400); // Short delay, wait for the Mate to send back CMD
bluetooth.print("$$"); // Enter command mode
delay(100); // Short delay, wait for the Mate to send back CMD
bluetooth.println("U,9600,N"); // Temporarily Change the baudrate to 9600, no parity
// 115200 can be too fast at times for NewSoftSerial to relay the data reliably
delay(100); // Short delay, wait for the Mate to send back CMD
bluetooth.begin(9600); // Start bluetooth serial at 9600
delay(400); // Short delay, wait for the Mate to send back CMD
bluetooth.print("$$");
delay(100);
bluetooth.println("SM,1"); delay(100);
delay(100);
bluetooth.println("C,0006564306CD"); // Connect to SaberTooth
// delay(1000);
// bluetooth.println("---");
// delay(100);
}
void loop()
{
if(bluetooth.available()) // If the bluetooth sent any characters
{
// Send any characters the bluetooth prints to the serial monitor
Serial.print((char)bluetooth.read());
}
if(Serial.available()) // If stuff was typed in the serial monitor
{
// Send any characters the Serial monitor prints to the bluetooth
bluetooth.print((char)Serial.read());
}
}
I have been running Serial Monitor on the host (Arduino Uno) which is where I see the message “TRYING”, but no follow up “failure” or “connected”.
Has anyone successfully done anything similar and see what I might be doing wrong? Thanks.