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 interfacing Programming

Part Number: TCA8418

Hi,

I am designed a custom PCB and I am facing a very small issue related to program if someone can help me with it. It is Arduino Code. I know it is out of your jurisdiction but I think someone can help me with it because I also found Arduino code example in other thread provided by TI guy.

I have a keypad as shown in below picture.



I am getting some different number on each key press . I don't mind if i can get a unique number of each key. The rest i can mange.
I received number like that
21 to 30 for SW1 to SW10
11 to 20 for SW11 to SW20
For SW21 to SW29 , I received pair number.
For example
SW21 >> 1 & 2
SW22 >> 2 & 3
SW23 >> 3 & 4
.
.
SW29 >> 9 & 10
SW30 >> 10 only.

I have two request if you can help me with it.

  1. Assign number in same sequence for SW1 to SW10 as for SW11 to SW20. For example, instead of 21 to SW1, it should be 1 for SW1. The sequence of SW11 to SW20 is perfect.
  2. Assign a single unique number from SW21 to SW30 instead of double number

Serial Monitor DATA

21,22,23,23,23,24,25,26,27,27,28,29,30
11,12,13,14,15,16,17,18,19,20
1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10

 

/*
 * TCA8418 Driver
 * This code is adapted from the phishman's driver for arduino, https://github.com/phishman/TCA8418
 * The difference is that it is written to be easily ported to another microcontroller
 * Author: Henry Troutman
 */

/*
 * Keyboard PCB Hookup Guide:
 * 1 -> 3.3V
 * 2 -> GND
 * 3 -> SDA
 * 4 -> SCL
 * 5 -> INT_PIN
 * 6 -> RTC_INT (ds3231)
 */

// Arduino I2C Library
#include <Wire.h>

// keyboard Constants
#define KEYBOARD_ADDRESS 0x34
#define KEYBOARD_INT_PIN 1
#define KEYBOARD_STATE_REGISTER 0x04
#define KEYBOARD_FLAG_REGISTER 0x02
#define KEYBOARD_KEY_DOWN 0x80
#define KEYBOARD_KEY_MASK 0x7F




// configuration commands (configures the 3x10 matrix as inputs with pullups, interrupts ...
// For more information look at the code in the repo linked above
const uint8_t KEYBOARD_CONFIG_COMMANDS[] = {0x1D,0x07,0x1E,0xFF,0x1F,0x03,0x01,0xB9,0x02,0x0F}; 



// Define our functions before use
void keyboard_configure(void);
void keyboard_clearFlag(void);
uint8_t keyboard_getState(void);

// 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 pullup on the pin

  // Set up a falling edge pin interrupt on pin 2  
  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) {
      // This is where we can write to a screen or handle control keys
      Serial.print(key_code&KEYBOARD_KEY_MASK); // print the keycode
      Serial.print(",");
      keyInt = false;
      keyboard_clearFlag();
    }
    delay(100); 
  }
}

void keyboard_configure(void){
  for(uint8_t i = 0;i < 9;i+=2){
    Wire.beginTransmission(KEYBOARD_ADDRESS);
    Wire.write(KEYBOARD_CONFIG_COMMANDS[i]);
    Wire.write(KEYBOARD_CONFIG_COMMANDS[i+1]);
    Wire.endTransmission(); 
  }
}
uint8_t keyboard_getState(void){
  uint8_t key;
  Wire.beginTransmission(KEYBOARD_ADDRESS);
  Wire.write(KEYBOARD_STATE_REGISTER);
  Wire.endTransmission(); 
  Wire.requestFrom(KEYBOARD_ADDRESS, 1);    // request 1 bytes 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(void){
  Wire.beginTransmission(KEYBOARD_ADDRESS);
  Wire.write(KEYBOARD_FLAG_REGISTER);
  Wire.write(0x0F);
  Wire.endTransmission(); 
}
void keyboard_ISR(void){
  keyInt = true;
}

/*
I2C Command Summary

Setup board (5x10 keypad)
write to Register, value
            0x1D, 0x1F
            0x1E, 0xFF
            0x1F, 0x03
            0x01, 0xB9

To get keys
read 1 byte from 0x04

To clear interrupt flag
write to register,value
            0x02, 0x0F
 
 */