Combining Sketches. Is the NRF library interfering?

I'm trying to combine both my coop/radio code and the password/security system code and things are going weird. I can't move onto the next screen. Things go better when I plug into a power source that's not my computer, but even then I can only get to the Coop Door Is screen and it won't go back to the main menu either. Its almost like the Arduino doesn't recognize the keypad anymore... (the keypad works though, I verified it). I've tried combining it many times to see if I maybe missed a line of code of something, I even tried having the Coop Door code and the Enter password code activated only by their button (# or *), but that didn't work either.

Here's a map of my screen layout

Coop Door Is (display the door's State)
Main Menu *^
#v
Enter Password~~ If password is correct v ~~ If password incorrect go to Main Menu

To Disarm v * To Arm v

Disarm the System Arm the system ( I haven't gotten my pir
sensor yet, so that part
will have to be
implemented later)
~PIN LAYOUT~

The Keypad pins-

Row pins = 3, 5, 6, 7

Column pins = 8, 9, 10

LCD pins-
A0 - RS
A1 - E
A2 - D4
A3 - D5
A4 - D6
A5 - D7

The rest of the pins are attached to the the 5v pins and ground as necessary.

nRF Pins-
13 - SCK
12 - MISC
11 - MOSI
2 - CE
4 - CS

PS I have to post my code on a different post, because all three sketches (Radio/Coop, Password/ Security, and my combo code reach the character limit.

My Combo Code

#include <Wire.h>
#include <LiquidCrystal.h>
#include <Keypad.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>

#define Password_Length 5
int pressCnt = 0;
char Data[Password_Length];
char Master[Password_Length] = "1234";
byte data_count = 0, master_count = 0;
bool Pass_is_good;

unsigned long startMillis;
unsigned long currentMillis;
const unsigned long ScreenRefresh = 5000;

boolean RefreshDone = false;

boolean DoorIsOpen = false;
boolean DoorIsClosed = false;

enum MODES
{
  MAINMENUMODE,
  SECURITYMODE,
  SECURITYMODETWO,
  COOPMODE
};
MODES mode = MAINMENUMODE;

int msg[1];
RF24 radio(2, 4);
const uint64_t pipes[2] = {
  0xF0F0F0F000LL, 0xF0F0F0F0FFLL
};

const byte ROWS = 4;
const byte COLS = 4;


char keys[ROWS][COLS] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};
byte rowPins[ROWS] = {3, 5, 6, 7};
byte colPins[COLS] = {8, 9, 10};

Keypad myKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);

void setup() {
  radio.begin();
  radio.setDataRate(RF24_250KBPS);
  radio.setChannel(100);
  radio.setRetries(15, 15);
  radio.openWritingPipe(pipes[0]);
  radio.openReadingPipe(1, pipes[1]);
  radio.setPALevel(RF24_PA_MAX);
  radio.startListening();

  startMillis = millis();
  mode = MAINMENUMODE;
  lcd.begin(16, 2);
  MainMenu();
  Serial.begin(9600);
}

void loop() {
  char myKey = myKeypad.getKey();

   if (mode == SECURITYMODE && myKey == '*') {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("  Invalid Key  ");
    delay (2000);
    SecurityScreen();
  }
  else if (mode == SECURITYMODETWO && myKey == '*'){
    ArmedScreen();
  }
  else if (mode == SECURITYMODETWO && myKey == '#'){
    DisarmScreen();
  }

//PASSWORD CODE
  if (myKey == '#' && mode == MAINMENUMODE) {
    mode = SECURITYMODE;
    pressCnt = 0;
    SecurityScreen();
  }

  if (mode == SECURITYMODE) {
    if (myKey >= '0' && myKey <= '9') {
      Data[pressCnt] = myKey;
      lcd.setCursor(pressCnt, 1);
      lcd.print('*');
      pressCnt++;
    }
  }
  if (pressCnt == Password_Length - 1) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Password Is ");

    if (!strcmp(Data, Master)) {
      lcd.print("Good");
      delay(1000);
      clearData();
      SecurityScreenTWO();
    }
    else {
      lcd.print("Bad");
      delay(1000);
      clearData();
      MainMenu();
    }
  }
  
// RADIO CODE
  if (radio.available()) {
    bool done = false;
    while (!done) {
      done = radio.read(msg, 1);

      if (msg[0] == 111) {
        DoorIsOpen = true;
        DoorIsClosed = false;
      }

        if (msg[0] == 112) {
        DoorIsClosed = true;
        DoorIsOpen = false;
      }
    }
  }

// COOP CODE  
  if (myKey == '*' && mode == MAINMENUMODE) {
    currentMillis = millis();
    mode = COOPMODE;
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("The Coop Door Is");
    CoopDoorIs();
  }
if (mode == COOPMODE) {
    if (currentMillis - startMillis >= ScreenRefresh) {
      CoopDoorIs();
      startMillis = currentMillis;  //save the time that it was refreshed
      RefreshDone = true;
    }
  }
  if (RefreshDone == true) {
    ClearScreen();
    RefreshDone = false;
  }
}



void clearData() {
  while (data_count != 0){
    Data[data_count--] = 0;
  }
  pressCnt = 0;
  return;
}

void ClearScreen ()
{
  lcd.clear();
  MainMenu();
}

void MainMenu() {
  mode = MAINMENUMODE;
  lcd.setCursor(0, 0);
  lcd.print("* For Coop");
  lcd.setCursor(0, 1);
  lcd.print("# For Security");
}

void CoopDoorIs() {
  if (DoorIsOpen == true && DoorIsClosed == false) {
    lcd.setCursor(0, 1);
    lcd.print("Open");
  }
  else if (DoorIsClosed == true && DoorIsOpen == false    ) {
    lcd.setCursor(0, 1);
    lcd.print("Closed");
  }
}

void SecurityScreen() {
  mode = SECURITYMODE;
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(" Enter Password");
}

void SecurityScreenTWO() {
  mode = SECURITYMODETWO;
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("* To Arm");
  lcd.setCursor(0, 1);
  lcd.print("# To Disarm");
}

void ArmedScreen(){
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Security System");
  lcd.setCursor(0, 1);
  lcd.print("    Is ARMED    ");
}

void DisarmScreen (){
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Security System Is");
  lcd.setCursor(0, 1);
  lcd.print("    Disarmed    ");
}

My Radio/Coop Code

#include <Password.h>
#include <Keypad.h>
#include <LiquidCrystal.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>

unsigned long startMillis;
unsigned long currentMillis;
const unsigned long ScreenRefresh = 5000;

boolean ScreenTwo = false;
boolean RefreshDone = false;

boolean DoorIsOpen = false;
boolean DoorIsClosed = false;

//Radio
int msg[1];
RF24 radio(2, 4);
const uint64_t pipes[2] = {
  0xF0F0F0F000LL, 0xF0F0F0F0FFLL
};

//LCD
LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);

//Keypad
const byte ROWS = 4;
const byte COLS = 3;

char keys[ROWS][COLS] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};
byte rowPins[ROWS] = {3, 5, 6, 7};
byte colPins[COLS] = {8, 9, 10};

Keypad myKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup() {
  radio.begin();
  radio.setDataRate(RF24_250KBPS);
  radio.setChannel(100);
  radio.setRetries(15, 15);
  radio.openWritingPipe(pipes[0]);
  radio.openReadingPipe(1, pipes[1]);
  radio.setPALevel(RF24_PA_MAX);
  radio.startListening();

  startMillis = millis();

  //Screen 1
  lcd.begin(16, 2);
  MainMenu();
  Serial.begin(9600);
}

void loop() {
  //Timing
  currentMillis = millis();

  //Keypad
  char myKey = myKeypad.getKey();


  //Radio Code
  if (radio.available()) {
    bool done = false;
    while (!done) {
      done = radio.read(msg, 1);

      if (msg[0] == 111) {
        DoorIsOpen = true;
        DoorIsClosed = false;
      }

        if (msg[0] == 112) {
        DoorIsClosed = true;
        DoorIsOpen = false;
      }
    }
  }

  // Screen 2
  if (myKey == '*' ) {
    currentMillis = millis();
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("The Coop Door Is");
    ScreenTwo = true;
    CoopDoorIs();
  }

  if (ScreenTwo == HIGH) {
    if (currentMillis - startMillis >= ScreenRefresh) {
      CoopDoorIs();
      startMillis = currentMillis;  //save the time that it was refreshed
      RefreshDone = true;
    }
  }

  if (RefreshDone == true) {
    ClearScreen();
    RefreshDone = false;
  }
}

void CoopDoorIs() {
  if (DoorIsOpen == true && DoorIsClosed == false) {
    lcd.setCursor(0, 1);
    lcd.print("Open");
  }
  else if (DoorIsClosed == true && DoorIsOpen == false    ) {
    lcd.setCursor(0, 1);
    lcd.print("Closed");
  }
}

void MainMenu () {
  lcd.setCursor(0, 0);
  lcd.print("* for Coop");
  lcd.setCursor(0, 1);
  lcd.print("# for Security");
}

void ClearScreen ()
{
  ScreenTwo = false;
  lcd.clear();
  MainMenu();
}

And My Password/Security Code

#include <Wire.h>
#include <LiquidCrystal.h>
#include <Keypad.h>

int pressCnt = 0;

#define Password_Length 5
char Data[Password_Length];
char Master[Password_Length] = "1234";
byte data_count = 0, master_count = 0;
bool Pass_is_good;

enum MODES
{
  MAINMENUMODE,
  SECURITYMODE,
  SECURITYMODETWO,
  COOPMODES
};
const byte ROWS = 4;
const byte COLS = 4;
MODES mode = MAINMENUMODE;

char keys[ROWS][COLS] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};
byte rowPins[ROWS] = {3, 5, 6, 7};
byte colPins[COLS] = {8, 9, 10};

Keypad myKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);

void setup() {
  lcd.begin(16, 2);
  MainMenu();
  Serial.begin(9600);
}

void loop() {
  char myKey = myKeypad.getKey();

  if (myKey == '#') {
    mode = SECURITYMODE;
    pressCnt = 0;
    SecurityScreen();
  }

  
   if (mode == SECURITYMODE && myKey == '*') {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("  Invalid Key  ");
    delay (2000);
    SecurityScreen();
  }
  else if (mode == SECURITYMODETWO && myKey == '*'){
    ArmedScreen();
  }
  else if (mode == SECURITYMODETWO && myKey == '#'){
    DisarmScreen();
  }
 

  if (mode == SECURITYMODE) {
    if (myKey >= '0' && myKey <= '9') {
      Data[pressCnt] = myKey;
      lcd.setCursor(pressCnt, 1);
      lcd.print('*');
      pressCnt++;
    }
  }
  
  if (pressCnt == Password_Length - 1) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Password Is ");

    if (!strcmp(Data, Master)) {
      lcd.print("Good");
      delay(1000);
      clearData();
      SecurityScreenTWO();
    }
    else {
      lcd.print("Bad");
      delay(1000);
      clearData();
      MainMenu();
    }
  }
}

void clearData() {
  while (data_count != 0)
  {
    Data[data_count--] = 0;
  }
  
pressCnt = 0;
  return;
}


void MainMenu() {
  mode = MAINMENUMODE;
  lcd.setCursor(0, 0);
  lcd.print("* for Coop");
  lcd.setCursor(0, 1);
  lcd.print("# for Security");
}

void SecurityScreen() {
  mode = SECURITYMODE;
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(" Enter Password");
}

void SecurityScreenTWO() {
  mode = SECURITYMODETWO;
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("* To Arm");
  lcd.setCursor(0, 1);
  lcd.print("# To Disarm");
}

void ArmedScreen(){
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Security System");
  lcd.setCursor(0, 1);
  lcd.print("    Is ARMED    ");
}

void DisarmScreen (){
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Security System Is");
  lcd.setCursor(0, 1);
  lcd.print("    Disarmed    ");
}

Thanks for all the Help!

I brush my sketches. Combing is too scratchy.

I'm sorry, I don't understand.

The subject is...

OMG I feel so stupid! Thanks for catching that!

You could have done a lot worse!
Luckily it’s the weekend, everyone’s a bit goofy.
(Too much spare time)

I totally agree!

Other thread; start at Password Library and Creating a Variable Integer - #44 by Watson221 - Programming Questions - Arduino Forum

As I stated in a reply to that, radio.read does not return anything. And the code there does not compile in IDE 1.8.5.

Watson221:
I
The Keypad pins-

Row pins = 3, 5, 6, 7

Column pins = 8, 9, 10

I presume the keyboard pins are INPUT

Assuming you are using an Atmega 328 then pin 10 MUST be OUTPUT for the Arduino to act as SPI master.

...R

Never thought of that :frowning:

@Watson221 please don´t cross post threads.

It's not cross post in my opinion.

Robin2:
I presume the keyboard pins are INPUT

Assuming you are using an Atmega 328 then pin 10 MUST be OUTPUT for the Arduino to act as SPI master.

So if I understand correctly I need to set pin 10 as an OUTPUT? If I were to do that what would connect to pin 10? Wouldn't that mess with the keypad, the only pins I have left are pins 1 and 2. ?

PS Sorry for the late response but our internet has been on the fritz! A bird decided to make a house on our internet antenna and leave half-way through!

Watson221:
So if I understand correctly I need to set pin 10 as an OUTPUT? If I were to do that what would connect to pin 10? Wouldn't that mess with the keypad, the only pins I have left are pins 1 and 2. ?

I don't know what other limitations you have for rearranging the allocation of pins but if you want to use an nRF24 then pin 10 must be an OUTPUT.

...R

When I use the radio code without any of the password code it works fine, even without me declaring pin 10 as an output. The problem I have is with the password portion of my code.
Can I use pins 1 and 2 as digital pins instead of tx and rx pins, as in can I just plug in the wire from pin 10 into pins 1 or 2 without messing with my arduino?

Sorry, pins 1 and 0 are open not 2 and 1.

After some debugging I found that my key pad won't register the entire column #, 9,6, and 3. Instead it just displays the key on the other side of the keypad, *.7,4, and 1 respectfully.

Using this as a guide~

I disabled all of my serial code and moved the 3rd column pin from pin 10 to pin 1. AND EVERYTHING WORKS! Except for the screen after the press * to arm or # to disarm page, but thats only because I took that code out just to make sure it wasn't interfering.

That's my code as of now.

#include <Keypad.h>
#include <LiquidCrystal.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>

int pressCnt = 0;

#define Password_Length 5
char Data[Password_Length];
char Master[Password_Length] = "1234";
byte data_count = 0, master_count = 0;
bool Pass_is_good;

enum MODES
{
  MAINMENUMODE,
  SECURITYMODE,
  SECURITYMODETWO,
  COOPMODE
};

MODES mode = MAINMENUMODE;

unsigned long startMillis;
unsigned long currentMillis;
const unsigned long ScreenRefresh = 5000;
boolean RefreshDone = false;

boolean DoorIsOpen = false;
boolean DoorIsClosed = false;

int msg[1];
RF24 radio(2, 4);
const uint64_t pipes[2] = {
  0xF0F0F0F000LL, 0xF0F0F0F0FFLL
};

LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);

const byte ROWS = 4;
const byte COLS = 3;

char keys[ROWS][COLS] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};
byte rowPins[ROWS] = {3, 5, 6, 7};
byte colPins[COLS] = {8, 9, 1};

Keypad myKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup() {
  pinMode(10, OUTPUT);
  
  radio.begin();
  radio.setDataRate(RF24_250KBPS);
  radio.setChannel(100);
  radio.setRetries(15, 15);
  radio.openWritingPipe(pipes[0]);
  radio.openReadingPipe(1, pipes[1]);
  radio.setPALevel(RF24_PA_MAX);
  radio.startListening();

  startMillis = millis();

  //Screen 1
  lcd.begin(16, 2);
  MainMenu();

}

void loop() {
  currentMillis = millis();
  char myKey = myKeypad.getKey();


  if (radio.available()) {
    radio.read(msg, 1);

    if (msg[0] == 111) {
      DoorIsOpen = true;
      DoorIsClosed = false;
    }

    if (msg[0] == 112) {
      DoorIsClosed = true;
      DoorIsOpen = false;
    }
  }

  if (myKey == '*' ) {
    mode = COOPMODE;
    currentMillis = millis();
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("The Coop Door Is");
    CoopDoorIs();
  }

  if (mode == COOPMODE) {
    if (currentMillis - startMillis >= ScreenRefresh) {
      CoopDoorIs();
      startMillis = currentMillis;  //save the time that it was refreshed
      RefreshDone = true;
    }
  }

  if (RefreshDone == true) {
    ClearScreen();
    RefreshDone = false;
  }

  if (myKey == '#') {
    mode = SECURITYMODE;
    pressCnt = 0;
    SecurityScreen();
  }

  if (mode == SECURITYMODE && myKey == '*') {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("  Invalid Key  ");
    delay (2000);
    SecurityScreen();
  }
  else if (mode == SECURITYMODETWO && myKey == '*') {
    ArmedScreen();
  }
  else if (mode == SECURITYMODETWO && myKey == '#') {
    DisarmScreen();
  }

  if (mode == SECURITYMODE) {
    if (myKey >= '0' && myKey <= '9') {
      Data[pressCnt] = myKey;
      lcd.setCursor(pressCnt, 1);
      lcd.print('*');
      pressCnt++;
    }
  }
  if (pressCnt == Password_Length - 1) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Password Is ");

    if (!strcmp(Data, Master)) {
      lcd.print("Good");
      delay(1000);
      clearData();
      SecurityScreenTWO();
    }
    else {
      lcd.print("Bad");
      delay(1000);
      clearData();
      MainMenu();
    }
  }
}


void clearData() {
  while (data_count != 0)
  {
    Data[data_count--] = 0;
  }

  pressCnt = 0;
  return;
}

void MainMenu () {
  mode = MAINMENUMODE;
  lcd.setCursor(0, 0);
  lcd.print("* for Coop");
  lcd.setCursor(0, 1);
  lcd.print("# for Security");
}

void CoopDoorIs() {
  if (DoorIsOpen == true && DoorIsClosed == false) {
    lcd.setCursor(0, 1);
    lcd.print("Open");
  }
  else if (DoorIsClosed == true && DoorIsOpen == false    ) {
    lcd.setCursor(0, 1);
    lcd.print("Closed");
  }
}

void SecurityScreen() {
  mode = SECURITYMODE;
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(" Enter Password");
}

void SecurityScreenTWO() {
  mode = SECURITYMODETWO;
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("* To Arm");
  lcd.setCursor(0, 1);
  lcd.print("# To Disarm");
}

void ArmedScreen() {
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Security System");
  lcd.setCursor(0, 1);
  lcd.print("    Is ARMED    ");
}

void DisarmScreen () {
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Security System Is");
  lcd.setCursor(0, 1);
  lcd.print("    Disarmed    ");
}

void ClearScreen ()
{
  delay(1500);
  lcd.clear();
  MainMenu();
}

Watson221:
So if I understand correctly I need to set pin 10 as an OUTPUT? If I were to do that what would connect to pin 10?

So hardware SPI will take control of pin 10 (through 13). If you are using it for some other peripheral, you’ve got yourself an issue.

FYI pins zero and one are designated for use with hardware Serial. Using either for anything else can be troublesome.