0

MPR121 Sketch Won't Run
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

MPR121 Sketch Won't Run

by Nginerd on Mon Jun 26, 2017 10:50 pm

I'm using the MPR121 12 channel breakout board for arduino and attempting to run the example MPR121test sketch. I'm able to compile and upload the sketch, however the output in the serial monitor never gets passed " Adafruit MPR121 Capacitive Touch sensor test". Upon examining the code, it seems that regardless of whether the arduino is wired properly to the mpr121, I should at least get "MPR121 not found...". I'm primarily trying to use this on an Arduino nano (tried 3 different boards actually), however I've also tried this sketch with an Arduino mega. I've also tried uploading from both a Mac and a PC, thinking that maybe the library was somehow corrupted on my mac. Any ideas what might be happening?

Nginerd
 
Posts: 7
Joined: Wed Apr 26, 2017 7:40 pm

Re: MPR121 Sketch Won't Run

by franklin97355 on Tue Jun 27, 2017 12:30 am

Try removing the
Code: Select all | TOGGLE FULL SIZE
  while (!Serial);        // needed to keep leonardo/micro from starting too fast!
line and see what you get.

franklin97355
 
Posts: 21091
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: MPR121 Sketch Won't Run

by Nginerd on Tue Jun 27, 2017 3:15 pm

Tried this morning before I left for work, but same results. I'm not surprised though since the serial print that works comes after that line. Any other ideas?

Nginerd
 
Posts: 7
Joined: Wed Apr 26, 2017 7:40 pm

Re: MPR121 Sketch Won't Run

by franklin97355 on Tue Jun 27, 2017 3:33 pm

Could you post a picture of your board, its soldering and the connections to your processor?

franklin97355
 
Posts: 21091
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: MPR121 Sketch Won't Run

by Nginerd on Tue Jun 27, 2017 4:01 pm

I can do that when I get home, but I fail to see how that's relevant. The code should run on the micro without anything attached, at least to the point where the serial monitor reports "MPR121 not found". The code seems to freeze at this statement:
Code: Select all | TOGGLE FULL SIZE
 if (!cap.begin(0x5A)) {

As I stated originally, I've reproduced this behavior on a mega and three different nano boards, two of which were not connected to anything except the USB cable. Ok, I just realized something interesting and very puzzling. I'm at work so I had to download the library to grab sections of code for this post, and (unless I'm losing my mind) I just realized that it's different than the example code I have on my home PC. Specifically, on my home PC, the section of code that you suggested I remove includes a delay of 10 ms like this...
Code: Select all | TOGGLE FULL SIZE
  while (!Serial){
    delay(10);        // needed to keep leonardo/micro from starting too fast!
  }

However, the code I just downloaded contains only the "while" statement, as in the code below. What the...?!
Code: Select all | TOGGLE FULL SIZE
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
  if (!cap.begin(0x5A)) {
    Serial.println("MPR121 not found, check wiring?");
    while (1);
  }
  Serial.println("MPR121 found!");
}

Nginerd
 
Posts: 7
Joined: Wed Apr 26, 2017 7:40 pm

Re: MPR121 Sketch Won't Run

by franklin97355 on Tue Jun 27, 2017 4:10 pm

Both those should do the same thing but one would wait a bit longer and then loop.

franklin97355
 
Posts: 21091
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: MPR121 Sketch Won't Run

by Nginerd on Tue Jun 27, 2017 4:32 pm

Yes, I understand they are fundamentally the same, my point is why are they different in the first place. I didn't modify the example code that I downloaded at home, so there must be different versions. And if there are different versions, then is it possible I'm working with a version that has a bug or something?

Nginerd
 
Posts: 7
Joined: Wed Apr 26, 2017 7:40 pm

Re: MPR121 Sketch Won't Run

by Nginerd on Tue Jun 27, 2017 10:10 pm

OK, I broke out the DSO and I think I figured out what's going on. First, my assertion that the code should execute regardless of successful i2c communication was incorrect, although I'm not sure how the "MPR121 not found..." part of the code ever gets executed if you must have successful communication for anything to work. Second, I either had the clock and data lines backwards or the board was underpowered because I was using the 5v pin from the nano to power the mpr121. Anyway, everything working now, thanks for your help!

Nginerd
 
Posts: 7
Joined: Wed Apr 26, 2017 7:40 pm

Re: MPR121 Sketch Won't Run

by adafruit_support_carter on Wed Jun 28, 2017 10:32 am

FWIW, here are the lines of code that matter:
https://github.com/adafruit/Adafruit_MP ... 1.cpp#L108
https://github.com/adafruit/Adafruit_MP ... 1.cpp#L116

If I2C comms work, but do not get expected results, you will see the "not found" message. However, if I2C comms do not work at all (not connected, wired wrong, no power, etc.) then code execution will block at the lines above.

As a result, in your case, it was blocking in .begin()

adafruit_support_carter
 
Posts: 12977
Joined: Tue Nov 29, 2016 2:45 pm

Re: MPR121 Sketch Won't Run

by Jimbee on Fri Aug 16, 2019 12:29 pm

Hi,
I just purchased and received both your CAP1188 and MPR121 cap sensor boards. I started out with the CAP1188 sensor using I2C and MetroM4 @ 3.3VDC and your example code everything works fine. I changed to the MPR121 sensor using the same setup with the exception of code (used your example MPR121 test code) and it cannot find the sensor - hangs. Exactly the same error others have posted. For both sensors the 3.3VDC is supplied via a bench top power supply - not powered by the Metro USB. I have tried scanning the I2C bus it too hangs. Tried 0x5A the default address and 0x5B both hang. I believe the 121 sensor board to be defective.

Jimbee
 
Posts: 28
Joined: Wed Aug 01, 2018 12:49 pm

Re: MPR121 Sketch Won't Run

by adafruit_support_carter on Fri Aug 16, 2019 12:38 pm

@Jimbee Please start a new thread for your issue.

adafruit_support_carter
 
Posts: 12977
Joined: Tue Nov 29, 2016 2:45 pm

Please be positive and constructive with your questions and comments.