Hello!,
I am working on a project that requires 80 inputs. The switches are standard rocker switches. There will be instances where most of them will be ON at the same time. I am using a Mega 2560 for this project. The Mega is powered using an ethernet board with POE. I have the switches wired up as the following:
Row(arduino pin) 22-----[Diode|>]-----Switch -----[Diode|>]-----Column 23 arduino pin
Row(arduino pin) |--Switch -----[Diode|>]-----Column 25 arduino pin
Row(arduino pin) |--Switch -----[Diode|>]-----Column 27 arduino pin
Row(arduino pin) |--Switch -----[Diode|>]-----Column 29 arduino pin
Row(arduino pin) |--Switch -----[Diode|>]-----Column 31 arduino pin
Row(arduino pin) |--Switch -----[Diode|>]-----Column 33 arduino pin
Row(arduino pin) |--Switch -----[Diode|>]-----Column 35 arduino pin
Row(arduino pin) |--Switch -----[Diode|>]-----Column 37 arduino pin
Row(arduino pin) |--Switch -----[Diode|>]-----Column 37 arduino pin
The commons are tied together at each switch after the diode. Each output has a diode between the switch and the column.
When I turn on the switch at row 22 column 23 (switch 22/23 from now on) it indicates ON, the switch at row 22 column 25 (switch 22/25 from now on) will indicate(oscillate actually) ON and OFF. If i turn ON both switches, they will both indicate they are ON. If I turn OFF switch 22/23, 22/25 will indicate it's ON. I have diodes for every switch and every row base which leads me to believe the "ghosting" is maybe from the code.
Here is the code:
//Input matrix
int intRows = 9;
int intCols = 9;
int InputRowPins[9]={22,24,26,28,30,32,34,36,38}; //,40,42,44,46,48,50,52}; //array of pins used as output for rows of keypad
int InputColPins[9]={23,25,27,29,31,33,35,37,39}; //,41,43,45,47,49,51,53}; //array of pins used as input for columns of keypad
int InputStat[81]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; //array of pins used as input for columnss of keypad
//--------------------------------------------------------------------Check input matrix ----------------------------------------------//
void CheckInputs(int rowPins[],int colPins[],int keyStat[], int totRows, int totCols){
//theRowPins = the array of pins for the rows
//theColPins = the array of pins for the cols
//totROWS = the total of rows
//totCOLS = the total of columns
//theKeyStat = the saved status of the keys
//thInputStatusID = the ID of this set of inputs. helps distinguish what input set we are using. Not used. maybe i will, maybe i wont. Who knows? i sure dont, right now.
//Checks the input matrix for changes
// Re-intialize the row pins. Allows sharing these pins with other hardware.
for (byte r=0; r<totRows; r++) {
pinMode(rowPins[r],INPUT_PULLUP);
}
//Array position for status changes
int theInt = 0;
//loop through the columns and rows
for (byte c=0; c<totCols; c++) {
pinMode(colPins[c],OUTPUT);
digitalWrite(colPins[c], LOW); // Begin column pulse output.
for (byte r=0; r<totRows; r++) {
// keypress is active low so invert to high.
boolean theVal = !digitalRead(rowPins[r]);
//Serial.println(String(theVal));
//check if keys have changed status
if(keyStat[theInt]!=theVal){
//update key status
keyStat[theInt]=theVal;
//send info to server
//cmd,group,id,value
//sendToServer2("IN",theGroupID+"|"+String(theInt)+"|"+String(theVal));
//sendToServer2("IN","0|"+String(theInt)+"|"+String(theVal));
sendToServer2("IN",String(theInt)+"|"+String(theVal));
}
//Increase the array position
theInt+=1;
}
// Set pin to high impedance input. Effectively ends column pulse.
digitalWrite(colPins[c],HIGH);
pinMode(colPins[c],INPUT);
}
}// end function
I can't find the issue, whether it is with the wiring or the code. Any help would be greatly appreciated!
Thanks,
Jon