This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TCA8418: TCA8418

Part Number: TCA8418

Hi

I hope you are doing well.I made new boards and found the issue that was with previous version. It wasn't hardware/Software issue but keypad itself. We fabricated new keypads and that issue resolved.
Now i need your help related to a one key. I want to emulate the key pressing continues same like keyboard. For example, If i press UP key then page go continues up.
How i can do that with TCA8418? Getting one press output no issue but i want to get continued output when key long press.

Thanks


  • The TCA8418 does not have a key repeat function.

    You have to monitor key release events and implement a repeat timer in software.

  • Thanks for your reply.
    Any other IC that can support continues function. The TCA8418 is doing everything perfect except for 4 keys, i need continues press function as well. I tried to do it in programming but not able to do it. Maybe someone can help me to fix in programming otherwise, suggest me some other IC that can support complete keyboard function.
    For now by using TCA8418, i don't need all keyboard function except if arrows keys function implement somehow.
    Thanks

  • Hi

    I got an idea if you can confirm me.

    1. Key press
    2. Even occur
    3. perform function on key press continues
    4. Key release
    5. clear flag and interrupts

    Is it possible that when a key press and release two even generate?

    Thanks

  • Hi Ali,

    As Clemens mentioned, this device does not have a repeated key feature or long press feature that would mimic the example of holding the "up" key on a keyboard. This would need to be done in software. 

    As for other IC's in our portfolio, we do not offer an I2C keypad scanner with that specific function. 

    I got an idea if you can confirm me.

    1. Key press
    2. Even occur
    3. perform function on key press continues
    4. Key release
    5. clear flag and interrupts

    Is it possible that when a key press and release two even generate?

    I know that this device can generate a key event for both a key press, and key release, but unaware of functionality for point 3. 

    From a software perspective I would potentially approach this problem from a looping perspective i.e.: 

    1. Key press

    2. Event Occurs

    3. Trigger a for loop that checks for voltage on this key press event. If voltage is still LOW, then continue the looping function (i.e. if "UP" key is holding an input at a LOW voltage (key press), this keep scrolling up)

    4. Key Release

    5. Event occurs - stop the for-loop 

    6. clear flag and interrupt. 

    This might be a possible way to approach the coding problem. IF you can read into your code a voltage from one of the pins on the keypad, this might help you solve the problem with continuous key press.

    Regards,

    Tyler

  • Hi

    Yes that's what i meant for point 3.
    Can you tell me what register is responsible to generate event for both press and release with bit setting?
    Should i read the voltage of interrupt pin because this is the only pin other than I2C connected with MCU?

    Thanks
    This is the code that print event table location when any key press but only when press, not release.


    // Arduino I2C Library
    #include <Wire.h>
    
    // Keyboard Constants
    #define KEYBOARD_ADDRESS 0x34
    #define KEYBOARD_INT_PIN 1
    #define KEYBOARD_EVENT_REGISTER 0x04
    #define KEYBOARD_FLAG_REGISTER 0x02
    #define KEYBOARD_KEY_DOWN 0x80
    #define KEYBOARD_KEY_MASK 0x7F
    
    // Debounce Constants
    #define DEBOUNCE_DELAY 50 // Adjust this delay as needed
    
    // Configuration commands (configures the 3x9 matrix as inputs with pull-ups, interrupts, etc.)
    // For more information, refer to the code in the repository linked above
    const uint8_t KEYBOARD_CONFIG_COMMANDS[] = {
      0x1D, 0x07,
      0x1E, 0xFF,
      0x1F, 0x03,
      0x01, 0xB9,
      0x02, 0x1F
    };
    
    // Define our functions before use
    void keyboard_configure();
    void keyboard_clearFlag();
    uint8_t keyboard_getState();
    
    // Debounce variables
    uint8_t lastKeyCode = 0;
    unsigned long lastKeyPressTime = 0;
    
    // keyInt allows our event to ultimately be handled in the loop
    volatile bool keyInt = false;
    
    void setup() {
      Serial.begin(9600);
      Wire.begin();
      keyboard_configure();
      pinMode(KEYBOARD_INT_PIN, INPUT); // There is an external pull-up on the pin
    
      // Set up a falling edge pin interrupt on pin 1  
      attachInterrupt(digitalPinToInterrupt(KEYBOARD_INT_PIN), keyboard_ISR, FALLING); 
    }
    
    void loop() {
      if (keyInt) {
        uint8_t key_code = keyboard_getState(); // Get first keycode from FIFO
        if(key_code & KEYBOARD_KEY_DOWN) 
        {
    
          Serial.print(key_code & KEYBOARD_KEY_MASK);
          Serial.println(",");
        }
    
        keyboard_clearFlag();
        keyInt = false;
      }
    
      delay(10);
    }
    
    // WRITING I2C SLAVE
    void keyboard_configure() {
      for (uint8_t i = 0; i < 7; i += 2) {
        Wire.beginTransmission(KEYBOARD_ADDRESS);
        Wire.write(KEYBOARD_CONFIG_COMMANDS[i]);
        Wire.write(KEYBOARD_CONFIG_COMMANDS[i + 1]);
        Wire.endTransmission();
      }
    }
    
    // READING I2C SLAVE
    uint8_t keyboard_getState() {
      uint8_t key;
      Wire.beginTransmission(KEYBOARD_ADDRESS);
      Wire.write(KEYBOARD_EVENT_REGISTER);
      Wire.endTransmission();
      Wire.requestFrom(KEYBOARD_ADDRESS, 1); // request 1 byte from slave device 0x34
      while (Wire.available()) {
        // Slave may send less than requested
        key = Wire.read(); // Receive a byte as character
      }
      return key;
    }
    
    void keyboard_clearFlag() {
      Wire.beginTransmission(KEYBOARD_ADDRESS);
      Wire.write(KEYBOARD_FLAG_REGISTER); // Interrupt Status Register
      Wire.write(0x1F);
      Wire.endTransmission();
    }
    
    void keyboard_ISR() {
      keyInt = true;
    }

  • Hi Ali,

    On page 16 of the datasheet, there is a section describing how to handle key events from the FIFO. 

    In points 2 and 3 of the explanation, you can see that the number of events currently in the FIFO is stored in the KEY_LCK_EC register 0x03. 

    In order to parse through each event, read the KEY_EVENT_A (0x04) register. The 7th bit signifies if the key was released (0) or pressed (1). Bits 6 - 0 describe which key was pressed based off the key event table. 

    Reading the interrupt voltage might be problematic since the interrupt is set only when there are events in the FIFO. Once he FIFO has been completely read, the interrupt pin with de-assert. 

    With our application that we are trying to accomplish, holding down a key on the TCA8418 only registers a single event. This is why I was suggesting reading the voltage of the pin directly since this will give an indicator outside of the TCA8418 that would tell you that a key is being held. 

    You might be able to tell if a key is held by approaching the software by something like this:

    1. Read KEY_EVENT_A (0x04)

    2. Read bit 7 of the data - check to see if key release (0) or key press (1)

    3. wait (time)

    4. If key press = 1, then re-read KEY_EVENT_A to see if another key event that is a key release has come into the FIFO

    5. If no key event shows a release, then we know that the button is being held. Provide continuous functionality until a read of KEY_EVENT_A register shows that the held key reads a release event. 

    Regards,

    Tyler

  • Hi 

    Yes, I did the same and it worked.
    Thanks for all your help.
    Now it is working as a continuous key function.