11 Replies Latest reply on Jan 27, 2015 2:02 PM by CMata_Intel

    Intel Galileo keypad

    @L3X

      Hi, i have an Intel Galileo board and i want to connect to it a keypad(4x4)http://lh5.ggpht.com/EEKnuK0xyMfkE1ORVZ4UMWQlOmJ5kczgQ_PnQeXxU2IHs5hPNAuzTKKs-d2XRNJDYiPM1kXjE_Fz7IY=s576. First, i tried to connect my keypad to 8 digital pins from board and show in serial monitor which button was pressed. But when i open serial monitor I received values even if i have no pressed any button. Then I tried to connect keypad to my analog pins...I don't receive anything in serial monitor. Seems like is a problem with library. Please Help

       

       

      This is the code that i used for keypad connected to analog pins

       

      #include <Keypad.h>
      // #include <LiquidCrystal.h> // load the library of LCD

      // LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // initialize the library with the numbers of the interface pins

      const byte ROWS = 4; // Four rows
      const byte COLS = 4; // Four columns
      // Define the Keymap
      char keys[ROWS][COLS] = {
        {'1','2','3','A'},
        {'4','5','6','B'},
        {'7','8','9','C'},
        {'*','0','#','D'},
      };
      // Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
      byte rowPins[ROWS] = { A0, A1, A2, A3 };
      // Connect keypad COL0, COL1 and COL2 to these Arduino pins.
      byte colPins[COLS] = { A4, A5, A6, A7 };
      // Create the Keypad
      Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

      void setup()
      {
        // lcd.begin(16, 2);
        // lcd.setCursor(0, 0);
        Serial.begin(9600);
      }



      void loop()
      {
        char key = kpd.getKey();
        if(key) // Check for a valid key.
        {
        switch (key)
        {
        case '1':
        Serial.println("KEY 1");
        //lcd.clear();
        //lcd.println("tasta [1]");
        break;
        case '2':
        Serial.println("KEY 2");
        //lcd.clear();
        //lcd.println("tasta [1]");
        break;
        case '3':
        Serial.println("KEY 3");
        //lcd.clear();
        //lcd.println("tasta [1]");
        break;
        case '4':
        Serial.println("KEY 4");
        //lcd.clear();
        //lcd.println("tasta [1]");
        break;
        case '5':
        Serial.println("KEY 5");
        //lcd.clear();
        //lcd.println("tasta [1]");
        break;
        case '6':
        Serial.println("KEY 6");
        //lcd.clear();
        //lcd.println("tasta [1]");
        break;
        case '7':
        Serial.println("KEY 7");
        //lcd.clear();
        //lcd.println("tasta [1]");
        break;
        case '8':
        Serial.println("KEY 8");
        //lcd.clear();
        //lcd.println("tasta [1]");
        break;
        case '9':
        Serial.println("KEY 9");
        //lcd.clear();
        //lcd.println("tasta [1]");
        break;
        case '0':
        Serial.println("KEY 0");
        //lcd.clear();
        //lcd.println("tasta [1]");
        break;
        case '*':
        Serial.println("KEY *");
        //lcd.clear();
        //lcd.println("tasta [1]");
        break;
        case '#':
        Serial.println("KEY #");
        //lcd.clear();
        //lcd.println("tasta [1]");
        break;
        case 'A':
        Serial.println("KEY A");
        //lcd.clear();
        //lcd.println("tasta [1]");
        break;
        case 'B':
        Serial.println("KEY B");
        //lcd.clear();
        //lcd.println("tasta [1]");
        break;
        case 'C':
        Serial.println("KEY C");
        //lcd.clear();
        //lcd.println("tasta [1]");
        break;
        case 'D':
        Serial.println("KEY D");
        //lcd.clear();
        //lcd.println("tasta [1]");
        break;
        }
        }
      }

        • 1. Re: Intel Galileo keypad
          CMata_Intel

          Hi @L3X

           

          From where did you get the library? Maybe the library was made only for Arduino and AVR architectures but not for the Galileo.

          Have you tried to use this example Digital Read Serial, the keyboard that you are using seems that sends data in 8 pins, you could read the pins as HIGH and LOW and define what it's going on in the keyboard.

          Use the example and use more pins as inputs in order to see the interactions in the keyboard with the the Serial Monitor

           

          Regards;

          CMata

          • 2. Re: Intel Galileo keypad
            RGee

            Your message reminded me that I bought a little matrix keypad (for $1.49) similar to your picture and had not tried to hook it up yet. Mine is 4 X 3 having no letters, but my guess is that these are very similar, so my experiences may help.

             

            Bottom line is that I hooked it up to my Galileo Gen 1 with no difficulty.

             

            I went here Arduino Playground - Keypad Library and downloaded that library. Unzipped the file to the usual library folder.

             

            With my keypad and connector facing me (as it would be if you were using it) - row 1 is the leftmost pin, or pin 1. So pins 1,2,3,4 are the rows and pins 5,6,7 (5,6,7,8 in your case) are the columns. Of course, you should verify this with a meter or other continuity test, but this is a common layout  for a  membrane keyboard.

             

            In order, starting with pin 1 on the keyboard connector, I hooked up to the Gal Gen 1 starting at digital IO bit 2. So, the rows are IO 2-5 and the columns 6-8 (yours would be 6-9 in this example).

             

            Then I loaded the HelloKeypad.ino script and changed  the row and col info as:

             

            byte rowPins[ROWS] = {2,3,4,5}; //connect to the row pinouts of the keypad

            byte colPins[COLS] = {6,7,8}; //connect to the column pinouts of the keypad

             

            The character arrays were fine as is for my keypad, but you would add the "A"-"D" col:

             

            char keys[ROWS][COLS] = {

              {'1','2','3'},

              {'4','5','6'},

              {'7','8','9'},

              {'*','0','#'}

             

            Everything compiles and runs fine! No changes needed to be made to the library at all. It definitely works, although it is a tad sluggish. I played with the setDebounceTime() and HoldTime() functions, but they did not make much difference. Still it works ok, depending on your application and it is a lot easier than writing your own scankey routines.

             

            Not sure why you would connect it to analog pins - unless yours is very different than it looks, it should go on digital lines.

             

            Let me know if this works for you.

            • 3. Re: Intel Galileo keypad
              @L3X

              I have tried with the same library, with pins conected in the same way, but doesn't work. The same story, serial monitor provide me random values even if i have no press any button from keypad.

              • 4. Re: Intel Galileo keypad
                @L3X

                i have tried, but i don't know if i implemented very well...i put the first pin(row 1) on digital pin 2 and 5th pin(column 1) on digital pin 6. I assume that when i press button 1 from keypad both pins(2 and 6) will be HIGH. no ?.  Please tell me if my implementation is good.

                 

                 

                int pushButton = 2;

                int pushButton2 = 6;

                 

                // the setup routine runs once when you press reset:

                void setup() {

                  // initialize serial communication at 9600 bits per second:

                  Serial.begin(9600);

                  // make the pushbutton's pin an input:

                  pinMode(pushButton, INPUT);

                  pinMode(pushButton2, INPUT);                   

                }

                 

                // the loop routine runs over and over again forever:

                void loop() {

                  // read the input pin:

                  int buttonState = digitalRead(pushButton);

                  int buttonState2= digitalRead(pushButton2);

                  // print out the state of the button:

                  if(buttonState==HIGH && buttonState2==HIGH){

                  Serial.println("tasta1");}

                  delay(1);        // delay in between reads for stability

                }

                • 5. Re: Intel Galileo keypad
                  RGee

                  @L3X wrote:

                   

                  i have tried, but i don't know if i implemented very well...i put the first pin(row 1) on digital pin 2 and 5th pin(column 1) on digital pin 6. I assume that when i press button 1 from keypad both pins(2 and 6) will be HIGH. no ?.  Please tell me if my implementation is good.

                   

                   

                  int pushButton = 2;

                  int pushButton2 = 6;

                   

                  // the setup routine runs once when you press reset:

                  void setup() {

                    // initialize serial communication at 9600 bits per second:

                    Serial.begin(9600);

                    // make the pushbutton's pin an input:

                    pinMode(pushButton, INPUT);

                    pinMode(pushButton2, INPUT);                 

                  }

                   

                  // the loop routine runs over and over again forever:

                  void loop() {

                    // read the input pin:

                    int buttonState = digitalRead(pushButton);

                    int buttonState2= digitalRead(pushButton2);

                    // print out the state of the button:

                    if(buttonState==HIGH && buttonState2==HIGH){

                    Serial.println("tasta1");}

                    delay(1);        // delay in between reads for stability

                  }

                  I'm not sure I am understanding what you are trying to do. I thought that you wanted to install and use a keyboard library, but your code here is attempting to raw read the switch closures. Also, it looks like you are setting both bits to input and expecting them to go high when the key is pressed - I don't now how that could work.

                   

                  There is a ton of info on such topics, but take a look at this article and code Interfacing hex keypad to arduino.Full circuit diagram, theory and program and see if it clarifies the situation for you - they have done a good job of explaining the situation and include the code. I would also suggest that first you use a meter to check that your keypad is working the way you think.

                  • 6. Re: Intel Galileo keypad
                    @L3X

                    Unfortunately, still doesn't work ... i have tried a lots of tutorials, but i have the same problem. Keypad seems to provide "pressed buttons" to serial monitor even if i don't press anything.... still unsolved

                    • 7. Re: Intel Galileo keypad
                      RGee

                      @L3X wrote:

                       

                      Unfortunately, still doesn't work ... i have tried a lots of tutorials, but i have the same problem. Keypad seems to provide "pressed buttons" to serial monitor even if i don't press anything.... still unsolved

                      I hope you don't give up.  If you want, try these few lines of code and let me know what happens - I think you will see what is going on...you should only see a message on the monitor when a single key is pressed.

                       

                      int pushButton = 2;
                      int pushButton2 = 6;
                      int buttonState2;

                       

                      void setup() {
                        Serial.begin(9600);
                        pinMode(pushButton, OUTPUT);
                        pinMode(pushButton2, INPUT); 
                      }
                      void loop() {
                        digitalWrite(pushButton2,HIGH);
                        digitalWrite(pushButton,LOW);
                       
                        if ( (buttonState2= digitalRead(pushButton2) )==LOW ){
                          Serial.println("Button pressed");
                          digitalWrite(pushButton,HIGH);
                          digitalWrite(pushButton2,HIGH);
                          delay(100);

                        }
                      }
                       

                      • 8. Re: Intel Galileo keypad
                        @L3X

                        No...doesn't work... Serial Monitor is filled with "Button pressed" even if i don't press anything ...   but, for now, i would like to connect my keypad to 1 analog pin. Hope that i'll choose the correct resistor for that.

                        • 9. Re: Intel Galileo keypad
                          RGee

                          @L3X wrote:

                           

                          No...doesn't work... Serial Monitor is filled with "Button pressed" even if i don't press anything ...   but, for now, i would like to connect my keypad to 1 analog pin. Hope that i'll choose the correct resistor for that.

                           

                          I wonder if your keypad is working. Sorry I couldn't help and good luck.

                          • 10. Re: Intel Galileo keypad
                            @L3X

                            Yes it's working ...tested on Arduino Uno... anyway, thank you for support

                            • 11. Re: Intel Galileo keypad
                              CMata_Intel

                              Hi @L3X

                               

                              Maybe the problem is related to noise in the inputs; have you tried to use pull_up resistors?

                               

                              CMata