Membrane Keypads (HCPROJ0001/HCPROJ0003/HCPROJ0004)

Soldering accessories, project boxes, keypads, battery holders etc.
Post Reply
admin
Site Admin
Posts: 866
Joined: Sun Aug 05, 2012 4:02 pm

Membrane Keypads (HCPROJ0001/HCPROJ0003/HCPROJ0004)

Post by admin » Thu Jun 27, 2013 6:38 pm

Image
Image
Image

Description:

Our range of ultra-thin self adhesive membrane matrix keypads, ideal for panel mounting. Flexible cable allows for discrete routing behind the keypad. Keypads are currently supplied in 3x4, 4x4, and 4x5 arrangements.

- 8-pin 2.54mm pitch connector
- Cable Length: 8cm
- Self-adhesive back provides easy mounting
- 3x4 Dimensions: 69.2 x 76.9 x 0.8mm
- 4x4 Dimensions: 160 x 60 x 0.8 mm
- 4x5 Dimensions: 75 x 85 x 0.8 mm


Pinouts:


3x4 Keypad:

Image

Pin 1..........Row 1
Pin 2.........Row 2
Pin 3.........Row 3
Pin 4.........Row 4
Pin 5.........Col 1
Pin 6.........Col 2
Pin 7.........Col 3


4x4 Keypad:

Image

Pin 1..........Row 1
Pin 2.........Row 2
Pin 3.........Row 3
Pin 4.........Row 4
Pin 5.........Col 1
Pin 6.........Col 2
Pin 7.........Col 3
Pin 8.........Col 4



4x5 Keypad:

Image

Pin 1..........Col 1
Pin 2.........Col 2
Pin 3.........Col 3
Pin 4.........Col 4
Pin 5.........Row 5
Pin 6.........Row 4
Pin 7.........Row 3
Pin 8.........Row 2
Pin 9.........Row 1




Libraries, example code, and diagrams are provided as an additional free service by Hobby Components and are not sold as part of this product. We do no provide any guarantees or warranties as to their accuracy or fitness for purpose.

Descriptions and diagrams on this page are copyright Hobby Components Ltd and may not be reproduced without permission.

wajrak
Posts: 2
Joined: Wed Jun 26, 2013 4:57 pm

Re: YwRobot Serial I2C LCD 1602 Module (HCARDU0023)

Post by wajrak » Thu Jun 27, 2013 6:38 pm

This post is related to 4x5 Membrane Keypad. If Mr. Admin reads this, please move it to new topic as I can not create one on my own.

If you are new to Arduino/Electronics and you bought this keyboard because layout looked like something you might need, here is few tips and some code that might save you some head scratching:
  • Wiring - normaly people google "membrane keyboard wiring" but there is not much info to be found. There is too many sorts of membrane keyboards with different plugs and wiring patterns... Bright side is, almost all of them works in the same way and you can not damage keyboard by applying "try and error" method. Lest focus on this particular keyboard.

    Image
    Uploaded with ImageShack.us

    Simple math applies here, we have 5 rows and 4 columns if you have a look on plug you will notice 5 pins with black markers, those are our rows. Most left one is row 1 and the most right is column 1. Lets have a look on wiring photo.

    Image

    Uploaded with ImageShack.us
    I know its not very clear to read but I don't have time to create a schematic for wiring. The left white jump wire is connected to digital pin no. 30 on my Arduino mega. Right jump wire is connected to digital pin 34. Ok, lets see some code.
  • Code - Here we go:
    /* @file MultiKey.ino
    || @version 1.0
    || @author Mark Stanley
    || @contact mstanley@technologist.com
    ||
    || @description
    || | The latest version, 3.0, of the keypad library supports up to 10
    || | active keys all being pressed at the same time. This sketch is an
    || | example of how you can get multiple key presses from a keypad or
    || | keyboard.
    || #
    */
    #include <Wire.h>
    #include <LCD.h>
    #include <LiquidCrystal_I2C.h>

    #define I2C_ADDR 0x27 // <<----- Add your address here. Find it from I2C Scanner
    #define BACKLIGHT_PIN     3
    #define En_pin  2
    #define Rw_pin  1
    #define Rs_pin  0
    #define D4_pin  4
    #define D5_pin  5
    #define D6_pin  6
    #define D7_pin  7

    int n = 1;

    LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

    #include <Keypad.h>

    const byte ROWS = 5; //four rows
    const byte COLS = 4; //three columns
    char keys[ROWS][COLS] = {
      {'A','B','#','*'},
      {'1','2','3', 'C'},
      {'4','5','6', 'D'},
      {'7','8','9', 'E'},
      {'L','0','R' , 'R'}
    };
    byte rowPins[ROWS] = {34, 35, 36, 37, 38}; //connect to the row pinouts of the keypad
    byte colPins[COLS] = {30, 31, 32, 33}; //connect to the column pinouts of the keypad

    Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );



    void setup() {
      Serial.begin(9600);
      kpd.setDebounceTime(1);
      
      lcd.begin (16,2); // <<----- My LCD was 16x2

        
      // Switch on the backlight
      lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
      lcd.setBacklight(HIGH);
      lcd.home (); // go home
      
        lcd.print("Wajrak");
    }

    unsigned long loopCount = 0;
    unsigned long startTime = millis();
    String msg = "";



    void loop() {

      loopCount++;
      if ( (millis()-startTime)>1000 ) {
          Serial.println(loopCount);
          startTime = millis();
          loopCount = 0;
      }

      // Fills kpd.key[ ] array with up-to 10 active keys.
      // Returns true if there are ANY active keys.
      if (kpd.getKeys())
      {
        for (int i=0; i<LIST_MAX; i++) // Scan the whole key list.
        {
          if ( kpd.key.stateChanged ) // Only find keys that have changed state.
          {
            switch (kpd.key.kstate) { // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
                case PRESSED:
                    msg = " PRESSED.";
                    break;
                case HOLD:
                    msg = " HOLD.";
                    break;
                case RELEASED:
                    msg = " RELEASED.";
                    break;
                case IDLE:
                    msg = " IDLE.";
            }
            Serial.print("Key ");
            Serial.print(kpd.key.kchar);
            Serial.println(msg);
          }
        }
      }
      
      // Backlight on/off every 3 seconds
      lcd.setCursor (0,1); // go to start of 2nd line
      lcd.print(n++,DEC);
      //lcd.setBacklight(LOW); // Backlight off
      delay(1000);
      lcd.setBacklight(HIGH); // Backlight on
      //delay(3000);
    }  // End loop


    This code supports lcd display and keyboard, I did not hat time to remove lcd code, but it will work for you even if you don't have lcd connected to Arduino. To run this code you will require keyboard library from here http://playground.arduino.cc/code/Keypad

    Here's top tip:
    Image

    Uploaded with ImageShack.us
    This is your keyboard and you would normally design your keys array in code like this:
    const byte ROWS = 5; //four rows
    const byte COLS = 4; //three columns
    char keys[ROWS][COLS] = {
      {'F1','F2','#','*'},
      {'1','2','3', 'Up'},
      {'4','5','6', 'Down'},
      {'7','8','9', 'Esc'},
      {'Left','0','Right' , 'Ent'}
    };


    But sadly Keyboard class can not cope with more than one character per key at the moment, which means your "F1", "F2", "Ent" etc.... would return 1 instead of value that you assigned to the key. Simple workaround:

    const byte ROWS = 5; //four rows
    const byte COLS = 4; //three columns
    char keys[ROWS][COLS] = {
      {'A','B','#','*'},
      {'1','2','3', 'C'},
      {'4','5','6', 'D'},
      {'7','8','9', 'E'},
      {'L','0','R' , 'R'}
    };



I think that's about it and I covered the basics, if you have any questions, don't hesitate to ask.

Post Reply

Return to “Project / Soldering”