Using Interrupts with CAP1188 touch sensor

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
alisyedz
 
Posts: 31
Joined: Wed Oct 21, 2015 2:50 pm

Using Interrupts with CAP1188 touch sensor

Post by alisyedz »

Hello,
I'm having difficulty with using CAP1188 8-key cap touch sensor.

I've hooked it up to an I2C bus and I'm using it with an Arduino Micro, connecting the I2C bus to pins 2 and 3 on the micro, for SDA and SCL.

Then I ran the sample code and I'm able to see the touch activity on the Serial console, so I know that the touch sensor part of it is working properly.

Next I tried to use the IRQ pin to setup an interrupt and handle touch events in real time instead of polling for them.

I'm using pin 7 on the micro to detect "FALLING" type activity on the IRQ pin and call an interrupt handler routine.

I'm not getting the interrupts properly on the IRQ pin so my handler is not getting triggered properly when I touch the terminals.

If I pull the wire out from the IRQ pin and disconnect it from the breadboard I get the handler to trigger a bunch of times so I think that part is able to receive stuff on IRQ and trigger the right routine.

I read the CAP1188 tutorial and near the end of it there's a sample code on how to get interrupts to work, but it doesn't use I2C and instead uses SPI (i think) so I wasn't able to use it directly into my sketch.

I also am using a second cap touch sensor, the 12-key MPR121 (also via I2C), and if I hook up my pin 7 to the IRQ pin on that board, I'm able to get the interrupts to happen properly, so I know that it's partially working.

I can provide my entire sketch as well as a photo of my setup later today but was wondering if there's a way I can make the CAP1188 work, or there's something I'm doing wrong?

Thanks.

User avatar
alisyedz
 
Posts: 31
Joined: Wed Oct 21, 2015 2:50 pm

Re: Using Interrupts with CAP1188 touch sensor

Post by alisyedz »

Here's the sketch I'm running:

Code: Select all

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_CAP1188.h>


int IRQ_pin = 7;


// Reset Pin is used for I2C or SPI
//#define CAP1188_RESET  9


// For I2C, connect SDA to your Arduino's SDA pin, SCL to SCL pin
// On UNO/Duemilanove/etc, SDA == Analog 4, SCL == Analog 5
// On Leonardo/Micro, SDA == Digital 2, SCL == Digital 3
// On Mega/ADK/Due, SDA == Digital 20, SCL == Digital 21

// Use I2C, no reset pin!
Adafruit_CAP1188 cap = Adafruit_CAP1188();

// Or...Use I2C, with reset pin
//Adafruit_CAP1188 cap = Adafruit_CAP1188(CAP1188_RESET);




void setup()
{
    
    delay (5000);
    Serial.begin(9600);
    Serial.println("CAP1188 test!");

    // Initialize the sensor, if using i2c you can pass in the i2c address
    //               Wire connecting AD to 3V             -> I2C address 0x28
    //               No resistor or wire attached to AD   -> I2C address 0x29
    //               600K resistor from AD to ground      -> I2C address 0x2A
    //               300K resistor from AD to ground      -> I2C address 0x2B
    //               180K resistor from AD to ground      -> I2C address 0x2C

    if (!cap.begin(0x29))
    {
        Serial.println("CAP1188 not found");
        while (1);
    }
    Serial.println("CAP1188 found!");

    // Turn off multitouch so only one button pressed at a time
    //cap.writeRegister(0x2A, 0x80);  // 0x2A default 0x80 use 0x41  — Set multiple touches back to off
    //cap.writeRegister(0x41, 0x39);  // 0x41 default 0x39 use 0x41  — Set "speed up" setting back to off
    //cap.writeRegister(0x72, 0x00);  // 0x72 default 0x00  — Sets LED links back to off (default)
    //cap.writeRegister(0x44, 0x41);  // 0x44 default 0x40 use 0x41  — Set interrupt on press but not release
    //cap.writeRegister(0x28, 0x00);  // 0x28 default 0xFF use 0x00  — Turn off interrupt repeat on button hold

    
    delay (5000);
    Serial.println("Attaching Interrupt");

    pinMode(IRQ_pin, INPUT);
    attachInterrupt(digitalPinToInterrupt(IRQ_pin), myblink, FALLING);

}

void loop()
{
    Serial.println ( "tick" );
    delay (1000);
    Serial.println ( "tock" );
    delay (1000);
}

void myblink()
{
    Serial.println ( "touched" );
}

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Using Interrupts with CAP1188 touch sensor

Post by adafruit_support_mike »

Post a photo showing your hardware and connections and we'll take a look at those too. 800x600 images usually work best.

User avatar
alisyedz
 
Posts: 31
Joined: Wed Oct 21, 2015 2:50 pm

Re: Using Interrupts with CAP1188 touch sensor

Post by alisyedz »

I wasn't able to get the interrupts working on this breakout and didn't want to spend a lot of time troubleshooting this issue.

I wound up ordering the 12-key Cap touch sensor breakout and used that one for my project and carried on with completing the circuitry.

I've had much better luck with the 12-key MPR121 breakout. I'm using two of those in my project. One has got the default I2C address of 0x5A and the other one I've tied the ADDR pin to the 3.3V pin and get that one to address at 0x5B.

Then I used pin 1 for interrupts of one of the two breakouts and pin 0 for the other.

No issues with getting all of that to work for me.

I'm using all 12 keys on one breakout and only 4 keys on the second breakout, the rest of the 8 keys remain unused, but it got me to finish everything much sooner.

Essentially I've given up on the 8-key CAP touch sensor CAP1188 and may use it in the future for some other project.

I didn't get a chance to provide a photo of my circuit but essentially this is how I hooked it up.

I used one power rail for 5v and ground.
I used the second power rail as an I2C bus. Red = SDA and Blue = SCL

On the arduino micro I attached

Pin 2 = Red side of the I2C rail
Pin 3 = Blue side of I2C rail.

and then on the CAP1188 I did the same
SDA pin = Red side of the I2C rail
SCL pin = Blue side of I2C rail.
VIN = Red side of power rail
GND = Blue side of power rail

Power and I2C communication are happening properly on the board.
The LED's are also lighting up next to each of the cap touch key when it is touched.

Then I connected the IRQ pin from the CAP1188 breakout to Pin 7 on the arduino micro and tried to attach the interrupt as shown in my sketch and nothing. No activity, either RISING or FALLING or CHANGE.

If you guys have some chance to configure a setup similar to mine and try it, I'd appreciate it, because I'd really like to get to the bottom of it so I can use this 8-key breakout in the future.

Not using interrupts and polling the thing at a high rate is a possibility but I'd rather use the interrupts and get a realtime synchronous response instead of a polled detection that happens to mimic realtime.

Thanks for any help you can provide.

User avatar
alisyedz
 
Posts: 31
Joined: Wed Oct 21, 2015 2:50 pm

Re: Using Interrupts with CAP1188 touch sensor

Post by alisyedz »

Okay I figured out the solution to this.

I needed to be a little more educated about open-drain type setups.

All I needed to do on pin 7 was to enable the pull-up resistor, so it doesn't float anymore and leans toward high under normal circumstances.

Code: Select all

    pinMode ( 7, INPUT_PULLUP );
    attachInterrupt(digitalPinToInterrupt( 7 ), test_ISR, FALLING);
Once I enable the pull-up resistor, the thing fires interrupts just fine.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Using Interrupts with CAP1188 touch sensor

Post by adafruit_support_mike »

Glad to hear you got it working!

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

Return to “Other Products from Adafruit”