Problem with keypad subfunction when using Nano instead of Uno

Hi,

Still working on the DCC++ Throttle.
The code is heavily customized and working using an Arduino Uno.

Now I want to use an Arduino Nano and everything works except getting the loco address. (without this function the rest is useless)

I should be able to input commands using a keypad (3x4)

When “*” is pushed the display should display “Set Dcc Addr #” displayed, after that the user should enter the address using the same keypad.

Does anybody know why this piece of code doesn’t run on the Nano?
When “*” is pushed the track power is shut off (Serial.print("<0>"); does that but after that nothing new is displayed.

void getLocoAddress() {
  Serial.print("<0>");                          // track power off to DCC++ unit
  int total = 0;
  counter = 0;
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Set Dcc Addr # ");
  lcd.print(ActiveAddress + 1);
  do {
    TrigVal2 = digitalRead(Trigger2);           // read the input pin
    if (TrigVal2 == 0) break;                   // exit routine if right button pressed - ABORT new address
    key = keypad.getKey();
    if (key) {
      counter++;
      int number =  key - 48;
      total = total * 10 + number;
      lcd.setCursor(0, 1);
      if (total == 0) {                         // print multiple zeros for leading zero number
        for (int tempx = 1; tempx <= counter; tempx++) {
          lcd.print("0");
        }
      }
      else lcd.print(total);
    }
    TrigVal2 = digitalRead(Trigger2);            // read the input pin
  }
  while (counter <= 3); //  collect exactly 4 digits
  LocoAddress[ActiveAddress] = total;
  saveAddresses();
  lcd.clear();
  doMainLCD();
}

Is there something in this piece of code that a Nano can’t handle?
A total of 4 addresses are stored in the EEPROM.

EDIT:
I have added "delay(2000); to the code after "lcd.print("Set Dcc Addr # “);”
When “*” is pushed “Set Dcc Addr #” is displayed for 2 seconds so pushing the button calls the code but it doesn’t wait for input???

Please see the entire code attached.

Throttle_DCCpp_Leo.ino (14.6 KB)

Is there something in this piece of code that a Nano can't handle?

As the Nano and the Uno are essentially the same thing, with the same processor then no, code on one will run on the other. The nano has two extra analogue inputs over the Uno but that is about it.

When posting code please post all the code.

so pushing the button calls the code but it doesn't wait for input???

That is right, you have to write specific code to wait for an input. Delay just freezes the code until it is over.

That is right, you have to write specific code to wait for an input. Delay just freezes the code until it is over.

True, but in the Uno it is working correctly (or maybe better: as intended) and in the Nano it has a different behaviour.

leo_groeneveld:
True, but in the Uno it is working correctly (or maybe better: as intended) and in the Nano it has a different behaviour.

Then maybe you’ve wired something differently.

Got it!

I have commented the TrigVal lines (this was in the code when seperate push buttons were used and now it is working.

:)!