# 3x4 KEYPAD MPR121 is not stable when used with ESP32

**URL:** <https://forum.arduino.cc/t/3x4-keypad-mpr121-is-not-stable-when-used-with-esp32/1280835>\
**Category:** General Electronics\
**Created:** [July 12, 2024, 6:18am UTC](https://forum.arduino.cc/t/3x4-keypad-mpr121-is-not-stable-when-used-with-esp32/1280835 "2024-07-12T06:18:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hoidbhe161691](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hoidbhe161691/32/1084456_2.png) [@hoidbhe161691](https://forum.arduino.cc/u/hoidbhe161691)\
**Post date:** [July 12, 2024, 6:18am UTC](https://forum.arduino.cc/t/3x4-keypad-mpr121-is-not-stable-when-used-with-esp32/1280835/1 "2024-07-12T06:18:46Z")

</div>

Hello,  
I have problems with the 3x4 keyboard with MPR121 capacitive touch. When i upload example code of Adafruit for MPR121, every things is very ok. But after a period of time, that code and that circuit board, my ESP32 did not accept the keyboard anymore.  
`Adafruit MPR121 Capacitive Touch sensor test MPR121 not found, check wiring?`  
This was the 7th keyboard I bought. The first 2 of the shops I saw the shop's instructions, I connected the Keypad's VCC to 5V of ESP32. But when I saw the Datasheet of MPR121, I found that the IC was only working at 3.3V, so I bought the replacement keyboard and used the same code and connected as above but still encountered the old situation.  
Is there any idea about the above unstable situation?

My board:

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/1/f/a/1fad55710bcdcfd9e732cc196a21e104b63a3bd7.jpeg)

My keypad:

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/3/0/0/300316d33b9c69ecbef626e006fb77b94ed0e4d4.jpeg)

My IDE: Arduino IDE 2.3.2

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/6/5/c/65c6fb7eea57438e38fdaa62960245cbfa620c03.png)

Wiring diagram:  
ESP32 - KEYPAD  
3.3V - VCC  
GPIO22 - SCL  
GPIO21 - SDA  
GND - GND

Code i used:

```arduino
/ *********************************************************
This is a library for the MPR121 12-channel Capacitive touch sensor

Designed specifically to work with the MPR121 Breakout in the Adafruit shop 
  ----> https://www.adafruit.com/products/

These sensors use I2C communicate, at least 2 pins are required 
to interface

Adafruit invests time and resources providing this open source code, 
please support Adafruit and open-source hardware by purchasing 
products from Adafruit!

Written by Limor Fried/Ladyada for Adafruit Industries.  
BSD license, all text above must be included in any redistribution
********************************************************** /

#include <Wire.h>
#include "Adafruit_MPR121.h"

#ifndef _BV
#define _BV(bit) (1 << (bit)) 
#endif

// You can have up to 4 on one i2c bus but one is enough for testing!
Adafruit_MPR121 cap = Adafruit_MPR121();

// Keeps track of the last pins touched
// so we know when buttons are 'released'
uint16_t lasttouched = 0;
uint16_t currtouched = 0;

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

  while (!Serial) { // needed to keep leonardo/micro from starting too fast!
    delay(10);
  }
  
  Serial.println("Adafruit MPR121 Capacitive Touch sensor test"); 
  
  // Default address is 0x5A, if tied to 3.3V its 0x5B
  // If tied to SDA its 0x5C and if SCL then 0x5D
  if (!cap.begin(0x5A)) {
    Serial.println("MPR121 not found, check wiring?");
    while (1);
  }
  Serial.println("MPR121 found!");
}

void loop() {
  // Get the currently touched pads
  currtouched = cap.touched();
  
  for (uint8_t i=0; i<12; i++) {
    // it if *is* touched and *wasnt* touched before, alert!
    if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) {
      Serial.print(i); Serial.println(" touched");
    }
    // if it *was* touched and now *isnt*, alert!
    if (!(currtouched & _BV(i)) && (lasttouched & _BV(i)) ) {
      Serial.print(i); Serial.println(" released");
    }
  }

  // reset our state
  lasttouched = currtouched;

  // comment out this line for detailed data from the sensor!
  return;
  
  // debugging info, what
  Serial.print("\t\t\t\t\t\t\t\t\t\t\t\t\t 0x"); Serial.println(cap.touched(), HEX);
  Serial.print("Filt: ");
  for (uint8_t i=0; i<12; i++) {
    Serial.print(cap.filteredData(i)); Serial.print("\t");
  }
  Serial.println();
  Serial.print("Base: ");
  for (uint8_t i=0; i<12; i++) {
    Serial.print(cap.baselineData(i)); Serial.print("\t");
  }
  Serial.println();
  
  // put a delay so it isn't overwhelming
  delay(100);
}

```

---

<div class="post-metadata">

**Author:** ![PaulRB](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paulrb/32/216330_2.png) [@PaulRB](https://forum.arduino.cc/u/PaulRB)\
**Post date:** [July 12, 2024, 7:18am UTC](https://forum.arduino.cc/t/3x4-keypad-mpr121-is-not-stable-when-used-with-esp32/1280835/2 "2024-07-12T07:18:51Z")

</div>

Have you tried adding pull-up-resistors to the SDA & SCL lines? 3K3 should be good.

Does the i2c scanner sketch find the keypad?

---

<div class="post-metadata">

**Author:** ![hoidbhe161691](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hoidbhe161691/32/1084456_2.png) [@hoidbhe161691](https://forum.arduino.cc/u/hoidbhe161691)\
**Post date:** [July 12, 2024, 2:46pm UTC](https://forum.arduino.cc/t/3x4-keypad-mpr121-is-not-stable-when-used-with-esp32/1280835/3 "2024-07-12T14:46:48Z")

</div>

i have been adding pull-up-resistors when i connect vcc to 5v. After i read datasheet, it show that pull-up-resistors has been integrated into the KEYPAD so i dont use in 3.3v connect

---

<div class="post-metadata">

**Author:** ![PaulRB](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paulrb/32/216330_2.png) [@PaulRB](https://forum.arduino.cc/u/PaulRB)\
**Post date:** [July 12, 2024, 6:29pm UTC](https://forum.arduino.cc/t/3x4-keypad-mpr121-is-not-stable-when-used-with-esp32/1280835/4 "2024-07-12T18:29:28Z")

</div>

And the i2c scanner sketch?

You should find it somewhere in the examples menu of the IDE, I think.

---

<div class="post-metadata">

**Author:** ![hoidbhe161691](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hoidbhe161691/32/1084456_2.png) [@hoidbhe161691](https://forum.arduino.cc/u/hoidbhe161691)\
**Post date:** [July 13, 2024, 5:40am UTC](https://forum.arduino.cc/t/3x4-keypad-mpr121-is-not-stable-when-used-with-esp32/1280835/5 "2024-07-13T05:40:18Z")

</div>

Of course I2C still works normally because I can still use the output with both Arduino and ESP32 before, the problem here is after a while (2-3 days), the keyboard cannot be used anymore ( or unstable use) although I have followed the manufacturer's instructions. (I welded the wires to make sure the plug is not loose)

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [January 9, 2025, 5:41am UTC](https://forum.arduino.cc/t/3x4-keypad-mpr121-is-not-stable-when-used-with-esp32/1280835/6 "2025-01-09T05:41:13Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
