1
votes

I am trying to achieve that my arduino-built device connects automatically to a device after it is switched on. The board is an Arduino Mini Pro and the bluetooth module is the Bluetooth Mate Silver (RN42). The devices are already paired, the bluetooth module is in slave mode, the remote device (in this case a normal laptop) is discoverable. I am using the SoftwareSerial library provided with the Arduino software.

Here is my setup:

void setup()
{
  Serial.begin(9600);  // Begin the serial monitor at 9600bps

  // bluetooth

  // set baud rate to 9600 
  bluetooth.begin(9600);  
  // start command mode
  bluetooth.print("$$$");
  // reply delay
  delay(100);
  // set to slave mode
  bluetooth.println("SM,0");
  // reply delay
  delay(100);
  // set device pin to 0403
  bluetooth.println("SP,0403");
  // reply delay
  delay(100);
  // connect to pixelsense
  bluetooth.println("C," + remoteMAC); // remoteMAC is a string with the mac address
  // reply delay
  delay(2500);
  // leave command mode
  bluetooth.println("---");
  // reply delay
  delay(100);
}

I read the command set of the RN42 and I think the commands are correct. I can connect to Arduino via bluetooth but the other direction isn't working. I also tried using the master mode or storing the remote mac in the flash instead of using a string. From the documentation it should be possible to initiate connections from the RN42, but I haven't quite found out how this works in details. Can anyone provide any help to solve my issue?

EDIT: The device does not seem to enter command mode at all. At least the flash lights don't indicate that. Is there anything wrong with the commands so that the command mode cannot be accessed?

4

4 Answers

1
votes

After nearly a week, I came across a solution. Actually it seems to be important that there is any program that accepts a bluetooth connection. I tried it the whole time with the Windows 7 Bluetooth dialog menu entry "Receive a file" but that did not work. So I used a third party program that listens for incoming connections and that actually worked. Basically everything I did was fine except for the missing connection listener.

Sometimes if I upload new code to the Arduino there is the problem that the connection cannot be established. This can be solved by removing and readding the bluetooth device.

The code for the RN42 Bluetooth Client above works. The library SoftwareSerial provided with the Arduino software is used.

0
votes

I think you may need to put some delay after bluetooth.begin(9600), to let set its baudrate and then issue print command.

0
votes

You can enter into the command mode only in 60s after the module is powered on. You can see if the timer is still counting using the status LED(if it blink 2 per second). Sorry for my bad english.

0
votes

On startup the RN-42 needs 500ms before it can enter command mode try 'delay(500);' before 'bluetooth.begin(115200);' and that should get you there. Also CTS should be tied low

as can be seen on page 45 of the document found at the link below.

https://cdn.sparkfun.com/assets/1/e/e/5/d/5217b297757b7fd3748b4567.pdf

PG 45

"3.3 INTERFACING TO A MICROPROCESSOR Roving Networks Bluetooth devices can connect to 3.3-V (only) microprocessors using the UART interface. When interfacing with a microprocessor, use the following guidelines: • The Bluetooth device power, ground, RX, and TX signals must be connected and CTS should be held low or tied to RTS. • The Bluetooth device can go into command mode 500 ms after booting. • The microprocessor should send $$$ with no carriage return or line feed to enter command mode. 3.3.0.1 HOW DO I KNOW THE MODULE IS READY FOR COMMAND MODE? 500 ms after rebooting, the module is ready for command mode. You send $$$with no carriage return. 3.3.0.2 WHICH HARD SIGNALS SHOULD I CONNECT? You should connect power, ground, RX, and TX. CTS should be low or you can connect or tie it to RTS."