Two MPR121 capacity touch sensors with Ardiuno

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
fatpandaclub
 
Posts: 1
Joined: Mon Jul 25, 2016 9:15 am

Two MPR121 capacity touch sensors with Ardiuno

Post by fatpandaclub »

Hi!
I'm trying to get two capacity sensors to work with an Arduino Uno. I'm using the Adafruit library, with the Sparkfun capacity sensors, which I've understood to be identical to the Adafruit ones, except for a single 3.3V pin, instead of the 3V + Vin pins.

I can get a single sensor to work perfectly, however, I can't get my code to see the second one.
As soon as I connect the ADD(R) pin on my second capacity sensor to anything, neither sensor works. When the ADD(R) pin on the second one is not connected, the first capacity sensor works fine, but the second one doesn't.
I've attached a Fritzing sketch of the setup I have, with the ADD pin connected to 3.3V, which should give the second sensor the 0x5B address. I've also tried connecting it pin to the SDA and SCL, for 0x5C and 0x5D respectively.

My code is below

Code: Select all

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

Adafruit_MPR121 cap1 = Adafruit_MPR121();
Adafruit_MPR121 cap2 = Adafruit_MPR121();

void setup() {
  while (!Serial);        // needed to keep leonardo/micro from starting too fast!

  Serial.begin(9600);
  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
  Serial.println( "looking for 0x5A" );
  if (!cap1.begin(0x5A)) {
      Serial.println("MPR121 0x5A not found, check wiring?");
      while (1);
  }
  Serial.println("MPR121 0x5A found!");

  
  Serial.println( "looking for 0x5B" );
  if (!cap2.begin(0x5B)) {
      Serial.println("MPR121 0x5B not found, check wiring?");
      while (1);
  }
  Serial.println("MPR121 0x5B found!");
  

}

void loop() {
  Serial.prinln("In loop");
}
Any help would be greatly appreciated :)
Attachments
Screen Shot 2016-07-25 at 15.23.18.png
Screen Shot 2016-07-25 at 15.23.18.png (250.95 KiB) Viewed 495 times

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Two MPR121 capacity touch sensors with Ardiuno

Post by adafruit_support_rick »

This forum is for Adafruit products. You should contact SparkFun for support.

User avatar
pranjalborah777
 
Posts: 3
Joined: Tue Aug 06, 2019 9:25 am

Re: Two MPR121 capacity touch sensors with Ardiuno

Post by pranjalborah777 »

I have 3 Adafruit MPR121. I connect them on common wires e.g. all 5volts together, all ground together, all SCL together and all SDA together. In the Adafruit MPR121 example code I added 3 caps. But only 1 is detected 0x5A. Not the rest 0x5B and 0x5A. How can do this. Consider this as an urgent.

User avatar
pranjalborah777
 
Posts: 3
Joined: Tue Aug 06, 2019 9:25 am

Re: Two MPR121 capacity touch sensors with Ardiuno

Post by pranjalborah777 »

Finally got the solution.
For using one MPR121, ADD (address pin of MPR121) pin is not connected to any other pin. Which means it is connected to the ground.
For using two or more (multiple) MPR121s,
ADD pin (of 1st MPR121) not connected to any other pin. This will have address 0x5A (Similar to that of single MPR121)
ADD pin (of 2nd MPR121) connected to Arduino 3.3V. This will have address 0x5B.
ADD pin (of 3rd MPR121) connected to SDA pin of MPR121 itself. This will have address 0x5C.
ADD pin (of 4th MPR121) connected to SCL pin of MPR121 itself. This will have address 0x5D.

Now join all 5V pins (of all the MPR121s) and connect it to 5V of Arduino. Similarly, join all Ground pins (of all the MPR121s) to Arduino Ground, join all SDA pins (of all the MPR121s) to A4 of Arduino UNO (or SDA pin 20 of Arduino MEGA) and join all SCL pins (of all the MPR121s) to A5 of Arduino UNO (or SCL 21 pin of Arduino MEGA). All MPR121s will have 4 pins connected to Arduino, except for the one using 0x0B address which will have ADD pin connected to 3.3V.

Code: I used three MP121s. This code is available in the internet. Simplest version with one MPR121 is available in examples of Arduino. (If example does not show up, try adding the library and check. Or check how to add examples from Arduino library)

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


Adafruit_MPR121 cap1 = Adafruit_MPR121();
Adafruit_MPR121 cap2 = Adafruit_MPR121();
Adafruit_MPR121 cap3 = Adafruit_MPR121();

uint16_t lasttouched1 = 0;
uint16_t currtouched1 = 0;

uint16_t lasttouched2 = 0;
uint16_t currtouched2 = 0;

uint16_t lasttouched3 = 0;
uint16_t currtouched3 = 0;

void setup() {
Serial.begin(9600);
if (!cap1.begin(0x5A)) {
Serial.println("MPR121 A not found, check wiring?");
while (1);
}
Serial.println("MPR121 A found!");

if (!cap2.begin(0x5B)) {
Serial.println("MPR121 B not found, check wiring?");
while (1);
}
Serial.println("MPR121 B found!");

if (!cap3.begin(0x5C)) {
Serial.println("MPR121 C not found, check wiring?");
while (1);
}
Serial.println("MPR121 C found!");
}

void loop() {
currtouched1 = cap1.touched();
currtouched2 = cap2.touched();
currtouched3 = cap3.touched();

//For A----------------------------------------------------------
for (uint8_t i=0; i<12; i++) {
if ((currtouched1 & _BV(i)) && !(lasttouched1 & _BV(i)) ) {
Serial.print(i); Serial.println(" touched of A");
}

if (!(currtouched1 & _BV(i)) && (lasttouched1 & _BV(i)) ) {
Serial.print(i); Serial.println(" released o A");
}


//For B----------------------------------------------------------
if ((currtouched2 & _BV(i)) && !(lasttouched2 & _BV(i)) ) {
Serial.print(i); Serial.println(" touched of B");
}

if (!(currtouched2 & _BV(i)) && (lasttouched2 & _BV(i)) ) {
Serial.print(i); Serial.println(" released of B");
}


//For C----------------------------------------------------------
if ((currtouched3 & _BV(i)) && !(lasttouched3 & _BV(i)) ) {
Serial.print(i); Serial.println(" touched of C");
}

if (!(currtouched3 & _BV(i)) && (lasttouched3 & _BV(i)) ) {
Serial.print(i); Serial.println(" released of C");
}
}

lasttouched1 = currtouched1;
lasttouched2 = currtouched2;
lasttouched3 = currtouched3;
return;
}

Have fun. Its a good day. Enjoy it :-)
With regards,
http://ppborah.com/

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

Return to “Other Arduino products from Adafruit”