HC-06 and NRF24L01 Not working together on a Nano

Hello, the title explains most of it. I have a Nano with both a NRF24 and a HC-06 hooked up to it. The HC-06 is using SoftwareSerial. I am able to successfully use the bluetooth and the RF functionality so I am positive that they are hooked up properly. They don’t work at the same time though. When I try to use both of them, the bluetooth stops working. I narrowed it down to the line starting the RF module “radio.begin()” bluetooth works when that is commented out, and it stops working after that line runs. Anyone have insight on this?

Here is my code:

#include <SoftwareSerial.h> 
#include <RF24.h>
#include <RF24_config.h>

SoftwareSerial BT(10,9); // RX, TX
RF24 radio(7, 8); // CE, CSN 

const byte numChars = 32;
char receivedCharsBT[numChars];
boolean newDataBT = false;


void setup() {
    Serial.begin(115200);
    BT.begin(9600);
    radio.begin();                          //COMMENT OUT THIS LINE FOR BLUETOOTH TO WORK 
    Serial.println("<Arduino is ready>");
    radio.endTransaction();
    
}

void loop() { 
  recvBT();
  showNewData();
  recvBT();
  showNewData();
}

void recvBT() {
    static boolean recvInProgress = false;
    static byte ndx = 0;
    char startMarker = '<';
    char endMarker = '>';
    char rc;

    while (BT.available() > 0 && newDataBT == false) {
        rc = BT.read();
        Serial.print(rc);
        Serial.println();

        if (recvInProgress == true) {
            if (rc != endMarker) {
                receivedCharsBT[ndx] = rc;
                ndx++;
                if (ndx >= numChars) {
                    ndx = numChars - 1;
                }
            }
            else {
                receivedCharsBT[ndx] = '\0'; // terminate the string
                recvInProgress = false;
                ndx = 0;
                newDataBT = true;
            }
        }

        else if (rc == startMarker) {
            recvInProgress = true;
        }
    }
}

void showNewData() {
    if (newDataBT == true) {
        Serial.print("This just in ... ");
        Serial.println(receivedCharsBT);
        long i = atol(receivedCharsBT);
        Serial.print("As an int ");
        Serial.println(i);
        newDataBT = false;
    }
}

I have been using an android app I made on MIT app inventor to test this, find it here: Sprinkler_v2 (1).apk - Google Drive

Pin 10 is commonly used for NRF24. If so, get bluetooth off, either to hardware serial or to alternative software serial pins. If you are sure NRF is not doing this, your problem may be caused by inadequate power. You have to be pretty unlucky to have that, as NRF are very frugal.

Thanks for the reply Nick. Is there anything special about pin 10? Shouldn't the radio be using pins 7 and 8 like I designated?

I'll try moving them around later today.

Sorry, I assumed the radio was on SPI bus and CSN is conventionally on pin 10. You have it working, so clearly that is not the case, and I see CSN is accounted for on pin 8 anyway. Nonetheless, the fact that it dies when the radio is initialised does suggest it might be a power problem.

For the SPI system to work pin 10 must be set as OUTPUT.

The simple solution is just don't use pin 10 for SoftwareSerial

...R

Nick_Pyner:
Sorry, I assumed the radio was on SPI bus

Robin2:
For the SPI system to work pin 10 must be set as OUTPUT.

I don’t even know if this guy is using SPI, or if he should be, I just assumed he was and am not aware of an NRF24 that doesn’t. I think he says, no implies, the radio works if there is no Bluetooth, but there is no call for the SPI library. Maybe it is hidden in an NRF library, maybe he has software SPI, in which case I suggest he shouldn’t, and do it like everybody else.

Thanks for the help, switching the RF to pins 9 and 10 and the bluetooth to 7 and 8 fixed it. I appreciate the knowledge and quick responses :slight_smile: