# Read a character string from I2C keyboard

**URL:** <https://forum.arduino.cc/t/read-a-character-string-from-i2c-keyboard/1011365>\
**Category:** Programming\
**Created:** [July 11, 2022, 8:53am UTC](https://forum.arduino.cc/t/read-a-character-string-from-i2c-keyboard/1011365 "2022-07-11T08:53:56Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![GolamMostafa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/golammostafa/32/239011_2.png) [@GolamMostafa](https://forum.arduino.cc/u/GolamMostafa)\
**Post date:** [July 11, 2022, 2:18pm UTC](https://forum.arduino.cc/t/read-a-character-string-from-i2c-keyboard/1011365/12 "2022-07-11T14:18:17Z")

</div>

The requestFrom(slaveAddress, 4) method always reads number of bytes (4) requested at default 100 kbit/sec. Entry from the Keyboard is not that much fast; so the Serial Monitor will show validFirstCharater and FFs or anyValue for the last three characters.

Try sketch of post #5 @J-M-L.

After the above, try the following one:

```cpp
#define CARDKB_ADDR 0x5F //Define the I2C address of CardKB.
#include <Wire.h>
char myData[5] = {0};
int i = 0;

void setup()
{
  Wire.begin();
  Serial.begin(9600);
}

void loop()
{
  while (Wire.requestFrom(CARDKB_ADDR, 1) == 0)
  {
    ; //wait
  }
  myData[i] = Wire.read();
  i++;
  if (i == 4)
  {
    myData[i] = '\0';
    i = 0;
    Serial.println(myData);
  }
}

```

---

_[View the full topic](https://forum.arduino.cc/t/read-a-character-string-from-i2c-keyboard/1011365)._
