Arduino to Arduino by Bluetooth

Hello!

I’ve got this HM-10 bluetooth module. I’ve pulled up putty and at the AT kommand “AT” i get “OK” so in some regards it works. But now I want to get two of them to talk to each other, and I’m having some problems.

To accomplish this I use SoftwareSerial library, and really just copy pasted the example code. I stuffed up somewhere, because it does not work. I’ll post my code and maybe someone could spot it:

Node 1, sending data:

#include <SoftwareSerial.h>

// 10 - Goes to HM-10 module pin marked "TX"
// 11 - Goes to HM-10 module pin marked "RX"
SoftwareSerial BTSerial(10, 11); // RX | TX

void setup() 
{
  // Setting up serial com with pc
  Serial.begin(9600);

  // Setting up serial with HM-10 module
  BTSerial.begin(9600);

  // Init complete
  Serial.println("Init done!");
}

void loop()
{
  // Outputting something so I know it's doing _something_
  Serial.println("Writing data...");

  // Write simple data to the HM-module
  BTSerial.write("FOO");

  // Sleeping for 1s before going at it again...
  delay(1000);
}

Node 2, receiving data:

#include <SoftwareSerial.h>

// 10 - Goes to HM-10 module pin marked "TX"
// 11 - Goes to HM-10 module pin marked "RX"
SoftwareSerial BTSerial(10, 11); // RX | TX

void setup() 
{
  // Setting up serial com with pc
  Serial.begin(9600);

  // Setting up serial with HM-10 module
  BTSerial.begin(9600);
  BTSerial.listen();

  // Init complete
  Serial.println("Init done!");
}

void loop()
{
  // Checking if there is data on the HM-module, ifso output it
  if(BTSerial.available()) 
  { 
    Serial.println("GOT DATA!");
    Serial.println(BTSerial.read());
  }
}

“GOT DATA” never appears :’(. These are two Arduino UNO. The LEDs on the bluetooth module is blinking steady. Anyone got an idea?

Okey, I got them working!

I had to put one in "central" mode, in the sense that I have to have one "master" and rest "slave". It works in my project since I'm making a hub that works with a API and communicates to the other nodes/slaves.

I achieved this by writing "AT+ROLE1" to the "master" device.

But now I got another problem... (thats development for ya'll). While working, how do I send AT commands? Before connected I could use BTSerial.write("AT..."), but when connected making the mcu write "AT..." only outputs the command over the wire! Haha!
So; while connected I cant sleep because I cant send AT commands as the device is connect and would write the command over the wire instead of the executing it.

Any clue?