I tried to use this library for the Adafruit Keypad 4x4 (ID: 3844), however, I am not able to make it work with Arduino Giga when Arduino.h is included in the sketch.
I have to manually include in the the Sketch because I'm using Platformio and dealing with .cpp files, but the result is the same if I use Arduino IDE without including explicitly Arduino.h.
Further details are provided below.
I'm using the code from one of the examples of the library:
#include "Adafruit_Keypad.h"
// define your specific keypad here via PID
// define your pins here
// can ignore ones that don't apply
#define R1 2
#define R2 3
#define R3 4
#define R4 5
#define C1 8
#define C2 9
#define C3 10
#define C4 11
const byte ROWS = 4; // rows
const byte COLS = 4; // columns
// define the symbols on the buttons of the keypads
char keys[ROWS][COLS] = {{'1', '2', '3', 'A'}, {'4', '5', '6', 'B'}, {'7', '8', '9', 'C'}, {'*', '0', '#', 'D'}};
byte rowPins[ROWS] = {R1, R2, R3, R4}; // connect to the row pinouts of the keypad
byte colPins[COLS] = {C1, C2, C3, C4}; // connect to the column pinouts of the keypad
// initialize an instance of class NewKeypad
Adafruit_Keypad customKeypad = Adafruit_Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
Serial.begin(115200);
delay(1000);
Serial.print("TEST KEYPAD\n");
customKeypad.begin();
}
void loop() {
// put your main code here, to run repeatedly:
customKeypad.tick();
while (customKeypad.available()) {
keypadEvent e = customKeypad.read();
Serial.print((char)e.bit.KEY);
if (e.bit.EVENT == KEY_JUST_PRESSED)
Serial.println(" pressed");
else if (e.bit.EVENT == KEY_JUST_RELEASED)
Serial.println(" released");
}
delay(10);
}
This works just fine, both on Arduino Giga and Arduino Mega.
However, if I add:
#include <Arduino.h>
at the top of the sketch, functionality breaks on Arduino Giga, whereas it continues to operate seamlessly on Arduino Mega.
In order to find the issue, I added the following lines:
I found out that when customKeypad.begin is called, the private variables _numCols and _numRows are set to 0, rather than 4 and 4.
In my main sketch, which I won't post here due to its size, I encounter a similar issue. In this scenario, the variables _numCols and _numRows have exceptionally large values, causing the subsequent malloc operation to fail, ultimately leading to a crash on the Arduino.
Based on my observations, it seems that the memory allocated for the private variables is being overwritten, causing the library to read random values instead of the intended initialization values for the instance but I have no idea why this should happen.
I also opened a thread on the Adafruit Forum where you can find additional info if you want to have a look.
I would appreciate it if you could verify this and fix this issue.
Hello,
I tried to use this library for the Adafruit Keypad 4x4 (ID: 3844), however, I am not able to make it work with Arduino Giga when Arduino.h is included in the sketch.
I have to manually include in the the Sketch because I'm using Platformio and dealing with .cpp files, but the result is the same if I use Arduino IDE without including explicitly Arduino.h. Further details are provided below.
I'm using the code from one of the examples of the library:
This works just fine, both on Arduino Giga and Arduino Mega. However, if I add:
#include <Arduino.h>
at the top of the sketch, functionality breaks on Arduino Giga, whereas it continues to operate seamlessly on Arduino Mega.
In order to find the issue, I added the following lines:
I found out that when customKeypad.begin is called, the private variables _numCols and _numRows are set to 0, rather than 4 and 4.
In my main sketch, which I won't post here due to its size, I encounter a similar issue. In this scenario, the variables _numCols and _numRows have exceptionally large values, causing the subsequent malloc operation to fail, ultimately leading to a crash on the Arduino.
Based on my observations, it seems that the memory allocated for the private variables is being overwritten, causing the library to read random values instead of the intended initialization values for the instance but I have no idea why this should happen.
I also opened a thread on the Adafruit Forum where you can find additional info if you want to have a look.
I would appreciate it if you could verify this and fix this issue.