Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The readings are unstable on the Uno R4 board. #46

Open
eMUQI opened this issue Jul 11, 2023 · 3 comments
Open

The readings are unstable on the Uno R4 board. #46

eMUQI opened this issue Jul 11, 2023 · 3 comments

Comments

@eMUQI
Copy link

eMUQI commented Jul 11, 2023

Has anyone tried using this library on the Uno R4 board? I attempted to use the code below, but the data obtained was very unstable and the serial monitor kept printing 1. Although there was a response when pressing the button, it cannot be used for practical applications on the R4 board.

// Include the Keypad library
#include <Keypad.h>

// Define the number of rows and columns in the keypad
const byte ROWS = 4;
const byte COLS = 4;

// Define the keys on the keypad
char keys[ROWS][COLS] = {
  { '1', '2', '3', 'A' },
  { '4', '5', '6', 'B' },
  { '7', '8', '9', 'C' },
  { '*', '0', '#', 'D' }
};

// Define the pins connected to the rows and columns of the keypad

byte rowPins[ROWS] = { 9, 8, 7, 6 };
byte colPins[COLS] = { 5, 4, 3, 2 };



//Create an object of keypad
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

void setup() {
  Serial.begin(9600);
}

void loop() {
  char key = keypad.getKey();  // Read the key

  // If a key is pressed, print the key on the serial monitor
  if (key) {
    Serial.print("Key Pressed : ");
    Serial.println(key);
  }
}

image

@nyk-yeon
Copy link

nyk-yeon commented Jul 28, 2023

I also had this problem, and when I implemented and tested the scanKeys() function of the library directly in main.c, the problem disappeared.

However, when we added #include <Keypad.h>, the same problem occurred, and it is confirmed that the problem occurred in the macro part of the header below.
`
Keypad.h

// bperrybap - Thanks for a well reasoned argument and the following macro(s).
// See http://arduino.cc/forum/index.php/topic,142041.msg1069480.html#msg1069480
#ifndef INPUT_PULLUP
#warning "Using pinMode() INPUT_PULLUP AVR emulation"
#define INPUT_PULLUP 0x2
// #define pinMode(_pin, _mode) _mypinMode(_pin, _mode) <<--- UNO R4 error
#define _mypinMode(_pin, _mode)
do {
if(_mode == INPUT_PULLUP)
pinMode(_pin, INPUT);
digitalWrite(_pin, 1);
if(_mode != INPUT_PULLUP)
pinMode(_pin, _mode);
}while(0)
#endif

`
When I modified it as above, it worked normally.
The above macro is not working properly on UNO R4, and it seems to interfere with pull-up functionality.

+If the error still occurs, you need to comment out the entire macro.

@M4c3j
Copy link

M4c3j commented Sep 21, 2023

Hello,

I have the same issue with Giga but there was some helpfull info:
Change Keypad.h:
#ifndef INPUT_PULLUP
to:
#if ! (defined(INPUT_PULLUP) || (ARDUINO_API_VERSION >= 10000))
It works for me.

@paulwitschey
Copy link

paulwitschey commented May 5, 2024

I also had this problem, and when I implemented and tested the scanKeys() function of the library directly in main.c, the problem disappeared.

However, when we added #include <Keypad.h>, the same problem occurred, and it is confirmed that the problem occurred in the macro part of the header below. ` Keypad.h

// bperrybap - Thanks for a well reasoned argument and the following macro(s). // See http://arduino.cc/forum/index.php/topic,142041.msg1069480.html#msg1069480 #ifndef INPUT_PULLUP #warning "Using pinMode() INPUT_PULLUP AVR emulation" #define INPUT_PULLUP 0x2 // #define pinMode(_pin, _mode) _mypinMode(_pin, _mode) <<--- UNO R4 error #define _mypinMode(_pin, _mode) do { if(_mode == INPUT_PULLUP) pinMode(_pin, INPUT); digitalWrite(_pin, 1); if(_mode != INPUT_PULLUP) pinMode(_pin, _mode); }while(0) #endif

` When I modified it as above, it worked normally. The above macro is not working properly on UNO R4, and it seems to interfere with pull-up functionality.

+If the error still occurs, you need to comment out the entire macro.

Thanks @nyk-yeon, this solved the problem I had with the R4 Wifi. Its suprising that a year after you identified the bug/solution the libraries haven't been updated or fixed. This issue is still plaging users of that keypad as of May 5, 2024.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants