MPR121 Capacitive Touch Sensor - False Detection

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
spagboi
 
Posts: 8
Joined: Mon Mar 13, 2023 10:31 pm

MPR121 Capacitive Touch Sensor - False Detection

Post by spagboi »

Hello,

I am using an Arduino Leonardo and 12-Key Capacitive Touch Sensor Breakout MPR121 connected using a STEMMA QT.

When running the MPR121test sketch from the Adafruit MPR121 library, I am seeing that all inputs are being triggered roughly every 2 seconds. The trigger light on the MPR121 does not come on during these.

Code: Select all

23:03:32.822 -> Adafruit MPR121 Capacitive Touch sensor test
23:03:32.878 -> MPR121 found!
23:03:33.854 -> 0 touched
23:03:33.854 -> 1 touched
23:03:33.854 -> 2 touched
23:03:33.854 -> 3 touched
23:03:33.854 -> 4 touched
23:03:33.854 -> 5 touched
23:03:33.854 -> 6 touched
23:03:33.854 -> 7 touched
23:03:33.854 -> 8 touched
23:03:33.854 -> 9 touched
23:03:33.854 -> 10 touched
23:03:33.854 -> 11 touched
23:03:33.854 -> 0 released
23:03:33.854 -> 1 released
23:03:33.854 -> 2 released
23:03:33.854 -> 3 released
23:03:33.854 -> 4 released
23:03:33.854 -> 5 released
23:03:33.854 -> 6 released
23:03:33.854 -> 7 released
23:03:33.854 -> 8 released
23:03:33.854 -> 9 released
23:03:33.854 -> 10 released
23:03:33.854 -> 11 released
23:03:33.901 -> 0 touched
23:03:33.901 -> 1 touched
23:03:33.901 -> 2 touched
23:03:33.901 -> 3 touched
23:03:33.901 -> 4 touched
23:03:33.901 -> 5 touched
23:03:33.901 -> 6 touched
23:03:33.901 -> 7 touched
23:03:33.901 -> 8 touched
23:03:33.901 -> 9 touched
23:03:33.901 -> 10 touched
23:03:33.901 -> 11 touched
23:03:33.901 -> 0 released
23:03:33.901 -> 1 released
23:03:33.901 -> 2 released
23:03:33.901 -> 3 released
23:03:33.901 -> 4 released
23:03:33.901 -> 5 released
23:03:33.901 -> 6 released
23:03:33.901 -> 7 released
23:03:33.901 -> 8 released
23:03:33.901 -> 9 released
23:03:33.901 -> 10 released
23:03:33.901 -> 11 released
23:03:34.135 -> 0 touched
23:03:34.135 -> 1 touched
23:03:34.135 -> 2 touched
23:03:34.135 -> 3 touched
23:03:34.135 -> 4 touched
23:03:34.135 -> 5 touched
23:03:34.135 -> 6 touched
23:03:34.135 -> 7 touched
23:03:34.135 -> 8 touched
23:03:34.135 -> 9 touched
23:03:34.135 -> 10 touched
23:03:34.135 -> 11 touched
23:03:34.135 -> 0 released
23:03:34.135 -> 1 released
23:03:34.135 -> 2 released
23:03:34.135 -> 3 released
23:03:34.135 -> 4 released
23:03:34.135 -> 5 released
23:03:34.135 -> 6 released
23:03:34.135 -> 7 released
23:03:34.135 -> 8 released
23:03:34.135 -> 9 released
23:03:34.135 -> 10 released
Otherwise, the board is correctly detecting real touches.

This is the MPR121test code:

Code: Select all

*********************************************************
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);
}
Please help!

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: MPR121 Capacitive Touch Sensor - False Detection

Post by mikeysklar »

Can you show a photo of your soldering and wiring between the Leonardo and MPR121.

Do you have any other controller you can use? Leonardos have some i2c compatibility issues.

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”