Multiple bluesmirf silver (RN-42) pairings to one arduino micro?

Hi!

I’m in the late stages of my exam work project and have hit a minor speed bump. I’m developing a simple diagnostics tool to help nurses determine if a patient is anorexic or not. As a small overview I’ll explain how it is supposed to work, and then what’s wrong.

The patient has a rotary encoder connected to an arduino micro. With the encoder the patient controls the x axis position of two dots on a projector, as to specify the width of a specific body part on the patient. When the patient is satisfied with the position she or he tell the nurse to log it, and they continue to the next body part. The “logging” is done with a simple PCB pushbutton connected to a second arduino micro connected to a pc (with Bluetooth), telling it that this is the position to save. Now move onto the next body part measurement.

Now to my problem: The first arduino micro (encoder micro) and second arduino micro (pushbutton micro) are supposed to be connected to a THIRD arduino. That is supposed to be connected to the pc. The third arduino is for now, an Uno as we are waiting on an order of yet another micro. But what I intend to do is attach TWO bluesmirf silver to the “pc Uno” which are supposed to each pair with the encoder micro and the pushbutton micro. I have one bluesmirf silver attached to each micro arduino. I’ve been testing a lot and I have managed to connect TWO micros through BT slivers and transmit data that is being read and processed.

I have been goggling and also searching through this forum but I can’t really make out if I can make two BT pairings to one arduino, be that Uno or micro. I have been doing my own testing by attaching two BT silvers to each of my two arduino micros. Only to have all four bt silvers being lit up by the green light, indicating that they are connected, but only ONE of the pairing seem to be able to transmit and receive data.

So is it possible to have two BT pairing to one arduino micro/Uno?

I’ll add my latest test code snippet. That is for one micro trying to pair twice with another micro.

Master code

#include <SoftwareSerial.h> 

char inData[100];      //to read data packet
int index;
int inInt = 0;
boolean started = false;
boolean ended = false;

int LED_RED = 6;
int LED_YELLOW = 5;

int bluetoothT = 7;  // TX-O pin of Bluesmirf silver, Arduino D7
int bluetoothR = 8;  // RX-I pin of Bluesmirf silver, Arduino D8
int bluetoothTx = 9;  // TX-O pin of Bluesmirf silver, Arduino D9
int bluetoothRx = 10;  // RX-I pin of Bluesmirf silver, Arduino D10

SoftwareSerial BT(bluetoothTx, bluetoothRx);
SoftwareSerial BT2(bluetoothT, bluetoothR);

void setup() {
  pinMode(LED_YELLOW, OUTPUT);
  pinMode(LED_RED, OUTPUT);
  pinMode(bluetoothTx, INPUT);
  pinMode(bluetoothRx, OUTPUT);
  pinMode(bluetoothT, INPUT);
  pinMode(bluetoothR, OUTPUT);

  delay(5000);

  BT.begin(115200);
  BT.print("$$");
  delay(100); // Wait for CMD to come back
  BT.println("SM,1");
  delay(100);
  BT.println("C,0006667699A6"); // 000666643C3D // 0006667699A6
  delay(100);
  BT.println("---");
  delay(100);
  BT.print("$$");
  delay(100);
  BT.println("U,9600,N");  // Temporarily Change the baudrate to 9600 (until a reboot is done)
  delay(100); // Wait for Ack
  BT.begin(9600);

  BT2.begin(115200);
  BT2.print("$$");
  delay(100);
  BT2.println("SM,1");
  delay(100);
  BT2.println("C,00066676B302");
  delay(100);
  BT2.println("---");
  delay(100);
  BT2.print("$$");
  delay(100);
  BT2.println("U,9600,N");
  delay(100); // Wait for Ack
  BT2.begin(9600);
}

void loop() {
  
  while (BT.available() > 0) {
    BTavailable();
  } 
  BTfinised();
  
  while (BT2.available() > 0) {
    BT2available();
  }
  BT2finised();
}

void BTavailable() {
    char aChar = BT.read();
    if(aChar == '<') {
      started = true;
      index = 0;
      inData[index] = '\0';
    } else if(aChar == '>') {
      ended = true;
    } else if(started) {
      inData[index] = aChar;
      index++;
      inData[index] = '\0';
    }  
  }


void BT2available() {
    char aChar = BT2.read();
    if(aChar == '<') {
      started = true;
      index = 0;
      inData[index] = '\0';
    } else if(aChar == '>') {
      ended = true;
    } else if(started) {
      inData[index] = aChar;
      index++;
      inData[index] = '\0';
    }  
  }


void BTfinised() {
  if(started && ended) {
    inInt = atoi(inData);   // Convert the string to an integer
    if (inInt == 1) {
      digitalWrite(LED_RED, HIGH);
    } else {
      digitalWrite(LED_RED, LOW);
    }
    started = false;        // Get ready for the next time
    ended = false;
    index = 0;
    inData[index] = '\0';
  }
}

void BT2finised() {
  if(started && ended) {
    inInt = atoi(inData);   // Convert the string to an integer
    if (inInt == 1) {
      digitalWrite(LED_YELLOW, HIGH);
    } else {
      digitalWrite(LED_YELLOW, LOW);
    }
    started = false;        // Get ready for the next time
    ended = false;
    index = 0;
    inData[index] = '\0';
  }
}

Slave code

#include <SoftwareSerial.h> 

int value_BT = 0;

int ledPin = 11;
int buttonPin = 12;
int buttonState = 0;

int bluetoothT = 7;  // TX-O pin of Bluesmirf silver, Arduino D7
int bluetoothR = 8;
int bluetoothTx = 9;  // TX-O pin of Bluesmirf silver, Arduino D9
int bluetoothRx = 10;  // RX-I pin of Bluesmirf silver, Arduino D10

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
SoftwareSerial BT2(bluetoothT, bluetoothR);

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(bluetoothTx, INPUT);
  pinMode(bluetoothRx, OUTPUT);
  pinMode(bluetoothT, INPUT);
  pinMode(bluetoothR, OUTPUT);
  
  delay(1000);
  
  bluetooth.begin(115200);
  BT2.begin(115200);
  bluetooth.print("$$");
  BT2.print("$$");
  delay(100); // Wait for CMD to come back
  bluetooth.println("SM,0");
  BT2.println("SM,0");  
  delay(100);
  bluetooth.println("---");
  BT2.println("---");
  delay(100);
  bluetooth.print("$$");
  BT2.print("$$");
  delay(100);
  bluetooth.println("U,9600,N");  // Temporarily Change the baudrate to 9600 (until a reboot is done)
  BT2.println("U,9600,N");
  delay(100); // Wait for Ack
  bluetooth.begin(9600);
  BT2.begin(9600);
}

void loop() {

  buttonState = digitalRead(buttonPin);

  if (buttonState == LOW) {     // When I press the pushbutton the buttonPin is value 0
    value_BT = 1;
    digitalWrite(ledPin, HIGH);
  } else {                      // Ergo NOT pressed
    value_BT = 0;
    digitalWrite(ledPin, LOW);
  }
    bluetooth.print("<");
    bluetooth.print(value_BT);
    bluetooth.print(">");
    BT2.print("<");
    BT2.print(value_BT);
    BT2.print(">");
}

I almost forgot to add! All four bluetooth silvers are of model RN-42.

Any help is appreciated! And I apologise in advance for any misspellings.

  • Paul D.