nrF24L01 interfering with 12 key Keypad

I have a 12 Key keypad wired to a nano as well as a nRF24l01 module.

Both work fine by themselves even when both are connected.

I put the 2 codes together and nothing!

When I comment out the radio.stopListening() and radio.write(), as noted in the code, it works.

What can i do to get it to work and what might be the problem?

Below is the code and attached is an image of the connection.

/*
* Arduino Wireless Keypad Communication 

* 
* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Keypad.h>

RF24 radio(7, 8); // CE, CSN
const byte addresses[][6] = {"00001", "00002"};

const byte ROWS = 4; // Four rows
const byte COLS = 3; // Three columns
// Define the Keymap
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'#','0','*'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 2, 3,4, 5 };
// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 6, 9, 10 }; 

// Create the Keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

int nPush = 99; // arbitrary number not in range to know nothing pushed
#define ledpin A0
void setup() {
    Serial.begin(9600);

  
  radio.begin();
  radio.openWritingPipe(addresses[1]); // 00001
  radio.setPALevel(RF24_PA_MIN);
  radio.stopListening();   ///-------------------------- commented out works
}
void loop() {

 
 char key = kpd.getKey();
  if(key)  // Check for a valid key.
  {
    switch (key)
    {
      case '*':
        digitalWrite(ledpin, LOW);
        break;
      case '#':
        digitalWrite(ledpin, HIGH);
        break;
      default:
        Serial.println(key);
        nPush = int(key)- 48 ;//  adjust numbers 0-9
    }
  }
   
   
    if(nPush != 99){
        Serial.println(nPush);
        radio.write(&nPush, sizeof(nPush));   //--------------commented out works
        delay(200);
        nPush = 99;
       
  
    }
 
}

You seem to be using pin 10 as one of your keypad inputs. When you use SPI pin 10 MUST be set as OUTPUT so you will need to use a different pin for your keypad.

...R

Robin2:
You seem to be using pin 10 as one of your keypad inputs.
...R

I used pins 1-6 and 9, no joy.

I used Analog pins A1-A7, no joy.

artistinfla:
I used pins 1-6 and 9, no joy.

I used Analog pins A1-A7, no joy.

Post the revised program.

Did you include the line?

pinMode(10, OUTPUT);

…R

Robin2:
Post the revised program.

Did you include the line?

pinMode(10, OUTPUT);

…R

I did.

It runs for one keypress then nothing.

when I comment out the 2 lines it works fine like before.

I used pin 0 since my breadboard pin 1 is a bit loose.

i had 6 input i=pins with pull-up resistors and when I checked for that it worked fine.

I wanted to transmit more than just 6, so I thought this would work easy enough.

Guess again, lol

/*
* Arduino Wireless Keypad Communication 

* 
* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Keypad.h>

RF24 radio(7, 8); // CE, CSN
const byte addresses[][6] = {"00001", "00002"};

const byte ROWS = 4; // Four rows
const byte COLS = 3; // Three columns
// Define the Keymap
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'#','0','*'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 0,2, 3,4 };
// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 5, 6, 9 }; 

// Create the Keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

int nPush = 99; // arbitrary number not in range to know nothing pushed
#define ledpin A0
void setup() {
    Serial.begin(9600);

  pinMode(10, OUTPUT);
  radio.begin();
  radio.openWritingPipe(addresses[1]); // 00001
  radio.setPALevel(RF24_PA_MIN);
 radio.stopListening();   ///------------------------------------------------ commented out works
}
void loop() {

 
 char key = kpd.getKey();
  if(key)  // Check for a valid key.
  {
    switch (key)
    {
      case '*':
        digitalWrite(ledpin, LOW);
        break;
      case '#':
        digitalWrite(ledpin, HIGH);
        break;
      default:
        Serial.println(key);
        nPush = int(key)- 48 ;//  adjust numbers 0-9
    }
  }
   
   
    if(nPush != 99){
        Serial.println(nPush);
        radio.write(&nPush, sizeof(nPush));   //--------------------------------commented out works
        delay(200);
        nPush = 99;
       
  
    }
 
}

You also seem to be using Pin 0 for your keypad. Pins 0 and 1 are dedicated for Serial, don't use them for anything else.

You say that the code "works" when you comment out two lines of code. But presumably you just mean that the keypad works. Are there any lines you can comment out that gets the wireless to work, even if the keypad does not?

If I understand you correctly you say that both the keypad and the wireless work fine with two separate programs even when both devices are connected (and presumably with the exact same connections). Post the two programs that demonstrate that.

...R

quote author=Robin2 link=msg=3834064 date=1533713853]
You also seem to be using Pin 0 for your keypad. Pins 0 and 1 are dedicated for Serial, don’t use them for anything else.

…R
[/quote]

correct on all accounts. I used analog pins A1 - A7 and the same thing. One button press is detected then it stops working.

There must be something in the Keypad library that is causing the program to halt when SPI is used or at least when the nRF24 is involved.

I decided to go with a resistor network on the keypad and use one analog pin to read the voltage as shown in the attached image.

This works fine

Thank you again for your help.

4x3_KeypadLayout.jpg

Pins A6 and A7 are analog input only. They don't work as digital I/O pins.

groundFungus:
Pins A6 and A7 are analog input only. They don’t work as digital I/O pins.

Thank you.

It seems like a waste of pins using the library when one analog in will do the job>

Again, thank you for all your help

Mark

groundFungus:
Pins A6 and A7 are analog input only. They don't work as digital I/O pins.

Where is a good reference for the pins, which are input only, etc.

I was reading https://www.arduino.cc/en/Tutorial/AnalogInputPins and it does not mention A6 A7 are input only.

Thanks