MPR121 Capacitive Keypad with Photon

Hi!

I’m new with the Photon and Particle environment.
I want to connect my MPR121 Capacitive Keypad to my Photon via I2C communication. But I can’t find out how I initialize and setup it in my software.

I’m nether sure about the hardware setup. I know SDA -> D0 and SCL -> D1, but not sure with IRQ -> # ?

Hope someone can help me witht this setup. I want the opportunity to touch an passcode on the keypad, and get it into my code.

I am using the MPR121 breakout (no keypad) but as for the IRQ you can choose any Digital Pin.

I am using a modified Adafruit MPR121 lib like this (i don’t use interrupt functionality at all so far though)

 int irqpin = D5;                                        // Touch IRQ. Might be useful for ECO-Mode
 
 Adafruit_MPR121 cap = Adafruit_MPR121();

 void initMPR() {
     pinMode(irqpin, INPUT);
     digitalWrite(irqpin, HIGH);
     Wire.begin();

     if (!cap.begin(0x5A)) {

         //MPR121 Not Ready?
         Serial.println("MPR121 Not Ready");
}
3 Likes

Do anyone have an example code, that initialize the keypad?
I mean the actual setup of what should happen when you press the various pads.

@smnnekho, I’m not sure about these lines in your code

 pinMode(irqpin, INPUT);
 digitalWrite(irqpin, HIGH);

If this code came from an Arduino library this would cause the AVR chip to attach a pull-up resistor to the interrupt pin, but on the Particles you’d rather just write

 pinMode(irqpin, INPUT_PULLUP);

The other version would not work the same way.

@eskehagen, have you got a link to a library that would support that keypad on another platform (e.g. Arduino)?

@ScruffR Thank you for pointing that out. i didn’t use the interrupt functionality yet so i didn’t realize the code is wrong.

@ScruffR I have found this toturial, that use an Arduino and the ‘Adafruit_MPR121’ library.

I think that could be used white the Photon, but I don’t know how to adjusts to the Photon?

1 Like

I’m at it :wink: and put it onto Particle Build (aka WebIDE)

1 Like

Hi @eskehagen Check out the below link i have used it with particle photon and is working perfect.The below link has all the details and code for getting the mpr121 work.

http://bildr.org/2011/05/mpr121_arduino/

I’ve just published the Particle “port” of the library and added a sample that should also show the use of IRQ pin (D6 in my case).

Since I have no board I can’t test if it really works, so please try both samples and keep me posted :wink:

Great! :smiley:
But where did you published it? Can’t find it (“port”) when I search in the Particle Build webIDE library.

You might have to clear the cache and then search for MPR121


I see. I had port in double quotes since it was not really a lot to port but rather some minor additions to make :wink:

1 Like

Sorry, but I only can find this “ADAFRUIT_MPR121”. I have cleared the cache.

That’s very odd.
How have you cleared the cache?
Have you done it via the gear icon (bottom left of Build) and the CLEAR CACHE button?

Maybe clear the cache again, log out of Build, close your browser re open it in incognito mode (if possible) and the log in again.
I’ve tried this with an other account and I found the lib in the public list.

Wird!
I have cleared the cache via the gear icon -> “Clear Cache” button.

Now I have cleared, logged out and opened in incognito mode, but no succes.
Still I just can see “Adafruit_MPR121” and nothing “MPR121”.

Hmm! Maybe I was not clear enough :wink:
When I said search for “MPR121” I meant this as a short and easy search term, but actually the library I “ported” is exactly this “Adafruit_MPR121” library :sunglasses:

Ah okay :smile: Then problem solved! I will test the library now then. You hear from me about it later

Maybe a stupid question - but where do I find the “Wire” library and add it to the project ?

I get this error:

fatal error: Wire.h: No such file or directory

Hmm, that should not happen - let me check.
Which sample are you using?

You should not need Wire.h since it’s already included via application.h


Edit:OK, I retested my provided samples and they build without any errors
I suppose you are not using my provided samples then?

1 Like

It’s working ! :smiley:
I outcomment "#include “Wire.h”, added #include “application.h” and compiled. Boom!

Thank you very much for your help! :smile:

Hello @eskehagen can you help with the code and diagrams that use with this captive touch, im new with that and wanna know if you can help me!