I'm having trouble interfacing a 4x4 keypad

I’m trying to interface a 4x4 keypad to my arduino which is connected to cayenne. I interfaced it so that i can type in password when i enter my home. presence inside home is detected using a pressure sensor. When pressure reading is high it alerts an alarm to enter the password but when control enters the loop of keypad commands the Dashboard gets disconnected and cant control any other functions. Is there a way i can do this?any help would be valuable. Thanks.

That’s because if you make a loop without cayenne.run inside, Cayenne dashboard will disconnect.

i tried giving in inside the void loop function where cayenne.run is, but wasnt working. i’llgive a try again

Are you using customKeypad.waitForKey() ?

typical customKey.getKey()

Library?

Keypad.h

This was the code i used , the program runs but serial monitor shows nothing and dashboard disconnects. Keypad is working. Don’t know what’s the problem.:worried:

void loop()
{
customKey = customKeypad.getKey();
if (customKey) // makes sure a key is actually pressed, equal to (customKey != NO_KEY)
{
Data[data_count] = customKey; // store char into data array
data_count++; // increment data array by 1 to store new char, also keep track of the number of chars entered
}
if(data_count == 3) // if the array index is equal to the number of expected chars, compare data to master
{
if(!strcmp(Data, raj)||(Data, ram)||(Data,ravi)){ // equal to (strcmp(Data, Master) == 0)
Serial.print(“OK”);
Serial.println(Data);
}
else
{
Serial.println(“Bad”);
Serial.print(Data);
}
u+=1;
if(u==3)
{
while(data_count !=0)
{ // This can be used for any array size,
Data[data_count–] = 0; //clear array for new data
}
u=0;
}
delay(1000);
}
Cayenne.run();
}

If you look into the library the getKey Function is this:
char Keypad::getKey() { single_key = true; if (getKeys() && key[0].stateChanged && (key[0].kstate==PRESSED)) return key[0].kchar; single_key = false; return NO_KEY; }

And then if you search for stateChange Function this appears:
// Report if the user changed the state of any key. for (byte i=0; i<LIST_MAX; i++) { if (key[i].stateChanged) anyActivity = true; }

So this is basic a loop that breaks when a key is pressed, then it won’t let arrive to Cayenne.run until a key is pressed. Hope you understood me :grin: . However, there is a way to run Cayenne.run , but you need a Arduino Due, because it can make differents activities at the same time. (PD: I think it’s that, maybe I’m wrong).

I changed the code to this , still no connection :confused:
void loop()
{
Cayenne.run();
if(pad())
{
digitalWrite(led_pin,HIGH);
delay(1000);
digitalWrite(led_pin,LOW);
}
}
boolean pad()
{
Serial.println(“dsda”);
while(time_Diff<5000)
{
Cayenne.run(); //Make sure to stay in contact with the Cayenne Server
stop_time = millis();
time_Diff = stop_time - start_time;
customKey = customKeypad.getKey();
if (customKey) // makes sure a key is actually pressed, equal to (customKey != NO_KEY)
{
Data[data_count] = customKey; // store char into data array
data_count++; // increment data array by 1 to store new char, also keep track of the number of chars entered
}
if(data_count == 3) // if the array index is equal to the number of expected chars, compare data to master
{
if(!strcmp(Data, raj)||(Data, ram)||(Data,ravi)){ // equal to (strcmp(Data, Master) == 0)
Serial.print(“OK”);
return true;
}
else
{
Serial.println(“Bad”);
u+=1;
return false;
}
if(u==3)
{
while(data_count !=0)
{
Data[data_count–] = 0; //clear array for new data
}
u=0;
}
delay(500);
}
}}

No, no, the thing is when you do getKey() the sketch enters in getKey loop (which is inside the library) and It doesn’t break until a key is pressed. I think if you search for getKey function inside the library you can modify the for loop and put Cayenne.run inside the for, but make a backup of the library first.

oook, ithink you mean editing the CPP file :smile:

Yes Keypad.cpp