Arduino Pro Mini & nRF24L01+ -- Enabling Radio kills input pins

So, I have stripped things down to the barest to troubleshoot. Here is what I have:

Arduino Pro Mini:
Pin (RAW) = +5V (Scavenged wall plug USB charger (2A))
Pin (VCC) = Pin VCC on NRF24L01
Pin GND = GND & Pin GND on NRF24L01
D9 = Pin CE on NRF24L01
D10 = Pin CS on NRF24L01
D11 = Pin MOSI on NRF24L01
D12 = Pin MISO on NRF24L01
D13 = Pin SCK on NRF24L01
D8 = 20K Resistor connected to GND & Switch connected to VCC
D2 = 20K Resistor connected to GND & Switch connected to VCC

I originally had this set up on D8 only. Got the below described crazy results, so I thought “Maybe the RF24 code is messing with D8.” So, I connected the same on D2. SAME RESULTS.

CODE:

#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"

RF24 radio(9,10);  // CE-Pin, CS-Pin

const byte addresses[][7] = {"Master","Slave"};
const int master = 0;
const int slave = 1;
const int myRole = master;
const int otherRole = slave;

const int switchOnePin = 2;     // pin the switch is connected to
const int switchTwoPin = 8;     // pin the switch is connected to
int switchOneState = 0;         // current state of the switch
int switchTwoState = 0;         // current state of the switch

void setup() {
  // Setup Serial
      Serial.begin(9600);
      printf_begin();
      printf("\n\rRF24-Test\n\r");
  // Setup and configure rf radio
    //radio.begin();                          // Start up the radio
    //radio.setAutoAck(1);                    // Ensure autoACK is enabled
    //radio.setRetries(15,15);                // Max delay between retries & number of re                                                                                            tries
    //radio.openReadingPipe(1,addresses[otherRole]);
    //radio.openWritingPipe(addresses[myRole]);
    //radio.startListening();
    //radio.stopListening();
    //radio.end();
  // Set Modes of Pins
    pinMode(switchOnePin, INPUT);
    pinMode(switchTwoPin, INPUT);
}

void loop(void){
  switchOneState = digitalRead(switchOnePin);
  switchTwoState = digitalRead(switchTwoPin);
  printf("\n\rswitchOneState: %d\n\r",switchOneState);
  printf("\n\rswitchTwoState: %d\n\r",switchTwoState);
  delay(500);
}

Running the code as it is WORKS PERFECTLY. Setting either switch to on or off changes the value of the variable between 0 and 1 respectively. See the expected output on the serial connection as you change the switch states.

The moment I uncomment the “radio.begin();” line (and any other radio lines, but only need to uncomment that first line), both switch states start at 1 upon boot and never change regardless of the actual switch states.

In other words, if I enable the radio, it is as if both D8 and D2 become OUTPUTs and are hard coded to HIGH.

I have tried the other pins too (D3-D7) and get the same result.

Has anyone successfully gotten a NRF24L01+ to work on a Arduino Pro Mini or is it incompatible with the APM?

Or, more importantly, does anyone have a clue what is going on or how to fix it?

Any and all help is GREATLY appreciated. I’m going nuts here.

Thank you.

~Robert

Moderator: added [code]...[/code] tags

Are you using the low or high powered module?
If u have a regulated 5V supply, why are u connecting it to the RAW pin? - why not to VCC?

Firstly, AFAIK the NRF24L01 runs at 3.3V.
You appear to be feeding it 5V.
You should connect it to the 3.3V pin.

Another thought.
Try using a define statement for the input pins.

I re-read my post 20 times trying to think of any info I wasn't giving and sure enough, I missed something.

I am using the 3.3V 8MHz Pro Mini. Sorry I didn't mention that.

As such, basically everything is 3.3V

Does that change anything?

RE: "Try using a define statement for the input pins."

#define - Arduino Reference states:

"In general, the const keyword is preferred for defining constants and should be used instead of #define."

Am I missing some function of "#define" that would fix this issue? Reading that page, it doesn't sound like it.

But, please correct me. This is driving me nuts.

What fork of the code are you using? There is a thread similar to this I just replied to, I put a fork of the code I used any many issues went away. There are serious buggy RF24 drivers out there.

Check out my blog project here, I am having issues as well but am having a lot of success with one way communications and pro minis (5V).

http://www.element14.com/community/groups/arduino/blog/2015/06/11/an-arduinoraspberry-pi-based-wireless-light-harness?et=blogs.comment.created#comment-62094

Daddio:
I re-read my post 20 times trying to think of any info I wasn't giving and sure enough, I missed something.

I am using the 3.3V 8MHz Pro Mini. Sorry I didn't mention that.

As such, basically everything is 3.3V

Does that change anything?

It means your original connections may be ok.
Can you measure the voltage across VCC and GND and post result.

Daddio:
RE: "Try using a define statement for the input pins."

#define - Arduino Reference states:

"In general, the const keyword is preferred for defining constants and should be used instead of #define."

Am I missing some function of "#define" that would fix this issue? Reading that page, it doesn't sound like it.

But, please correct me. This is driving me nuts.

Well if u look at the examples, define is used for a pin whereas const is used for a number.

aisc:
Are you using the low or high powered module?

You did not answer this question.

In your code you have :
const int myRole = master;
const int otherRole = slave;

master and slave are not integers.

Either change the names to numbers or change the type.

What NRF24 library are you using?

@aisc: "master" and "slave" are indeed integers in the posted code.

const int master = 0;
const int slave = 1;
const int myRole = master;
const int otherRole = slave;

Were those first 2 lines always there? then my apologies - I must have had blinkers on.

I am using the TMRh20 (https://github.com/TMRh20/RF24) fork of the NRF24L01 library. Downloaded last Friday.

I am thinking that this is a physical issue with my arduino. I have a second one that is soldered into another project, but I loaded this code (changing the pins so that it used a switch existing in the other project) and it worked whether or not the radio was being instantiated.

I have a replacement arduino on order. It should arrive Wednesday. We’ll see if that fixes the issue. I’ll keep you updated.

Meanwhile, thank you all for responding. I’ve got a pretty good head on my shoulders, but I always found that a second set of eyes can make all the difference. You guys rock for helping people out and it is much appreciated.

Your use of addresses seems odd with using a 2D char array values("master" and "slave" as pipe addresses).
Are you sure you can do that?
In the examples they are in hexadecimal like...

const uint64_t pipes[2] = { 0xABCDABCD71LL, 0x544d52687CLL };

So, the issue WAS a bad arduino. What a very strange symptom. Enable SPI and pins become Outputs set to High.

Simply replacing the Arduino Pro Mini with the new one resolved the issue.

Frostline: In the main project I am doing this for, I have followed your advice and moved to the "pipes" method of declaring the address. TY

My main project works! I built an alarm system for my Mother-In-Law. Her home alarm didn't monitor the Garage Door. It is a proprietary company alarm, so rather than try to interface with it, I simply created a bed side main unit housed in a small treasure chest wooden box (looks nice). The sensor is on the garage door (of course). And, she simply clicks the switch at night to turn it on before going to sleep.

She is very happy with it. Thank you all for your time and help. It is VERY much appreciated.

Warmest Regards,
Robert