Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 12 of 12

Thread: Did anybody use CAP1188?

  1. #1
    Member
    Join Date
    Mar 2019
    Location
    Hoboken, New Jersey, USA
    Posts
    33

    Did anybody use CAP1188?

    I just found out that MPR121 (12 capacitive sensors in one chip) is no longer made and has been replaces with CAP1188 (same thing, only 8 sensors).
    Did anybody try it yet with Teensy?

    I'm going to buy and try it, but if somebody did already, please let me know if I should bother.

    Thanks.

  2. #2
    Member
    Join Date
    Mar 2019
    Location
    Hoboken, New Jersey, USA
    Posts
    33
    Just got 3 of these: https://learn.adafruit.com/adafruit-...reakout/wiring
    Put them on the breadboard, ran I2C scanner and says that it found all 3, but the Adafruit example says "CAP1188 not found".
    I did try all 3 addresses.
    Did anybody get it working?

    Here is the example from Adafruit in their library:
    Code:
    /*************************************************** 
      This is a library for the CAP1188 I2C/SPI 8-chan Capacitive Sensor
    
      Designed specifically to work with the CAP1188 sensor from Adafruit
      ----> https://www.adafruit.com/products/1602
    
      These sensors use I2C/SPI to communicate, 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 <SPI.h>
    #include <Adafruit_CAP1188.h>
    
    // Reset Pin is used for I2C or SPI
    #define CAP1188_RESET  9
    
    // CS pin is used for software or hardware SPI
    #define CAP1188_CS  10
    
    // These are defined for software SPI, for hardware SPI, check your 
    // board's SPI pins in the Arduino documentation
    #define CAP1188_MOSI  11
    #define CAP1188_MISO  12
    #define CAP1188_CLK  13
    
    // 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);
    
    // Or... Hardware SPI, CS pin & reset pin 
    // Adafruit_CAP1188 cap = Adafruit_CAP1188(CAP1188_CS, CAP1188_RESET);
    
    // Or.. Software SPI: clock, miso, mosi, cs, reset
    //Adafruit_CAP1188 cap = Adafruit_CAP1188(CAP1188_CLK, CAP1188_MISO, CAP1188_MOSI, CAP1188_CS, CAP1188_RESET);
    
    void setup() {
      Serial.begin(9600);
      Serial.println("CAP1188 test!");
    
      // Initialize the sensor, if using i2c you can pass in the i2c address
      if (!cap.begin(0x28)) {
        Serial.println("CAP1188 not found");
        while (1);
      }
      Serial.println("CAP1188 found!");
    }
    
    void loop() {
      uint8_t touched = cap.touched();
    
      if (touched == 0) {
        // No touch detected
        return;
      }
      
      for (uint8_t i=0; i<8; i++) {
        if (touched & (1 << i)) {
          Serial.print("C"); Serial.print(i+1); Serial.print("\t");
        }
      }
      Serial.println();
      delay(50);
    }
    Last edited by KurtE; Yesterday at 10:31 PM. Reason: code tags

  3. #3
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,413
    Might help to have additional information, like what Teensy? What pins are you hooked up to? Pictures are good as it helps find things like, if someone put their Teensy on a breadboard, but the pins are not soldered to the Teensy or ...

    And what addresses did yours show up as? i.e. what resistor... did you use to set address? That is did address 0x28 show up in the list of scan? As I think that is the one you are trying to use in the example app...

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,544
    Looking at that library's code, I see the begin() function is supposed to print a few lines to the serial monitor.

    Code:
      // Useful debugging info
    
      Serial.print("Product ID: 0x");
      Serial.println(readRegister(CAP1188_PRODID), HEX);
      Serial.print("Manuf. ID: 0x");
      Serial.println(readRegister(CAP1188_MANUID), HEX);
      Serial.print("Revision: 0x");
      Serial.println(readRegister(CAP1188_REV), HEX);
    In setup(), add this line so it will wait for you to open the serial monitor:

    Code:
      while (!Serial) ; // wait
    With that added, you should always see at least "CAP1188 test!" printed. Do those 3 other lines from within the begin() function print anything?

  5. #5
    Member
    Join Date
    Mar 2019
    Location
    Hoboken, New Jersey, USA
    Posts
    33
    Sorry, forgot the connections and the monitor output.
    I just thought that the fact that the I2C scanner finds all boards proves that the connections are good.
    I use I2C on pins 18 and 19.

    Here is the board:
    Click image for larger version. 

Name:	20191012_185729.jpg 
Views:	10 
Size:	139.8 KB 
ID:	17884


    This is what I see in the serial monitor in the test:
    CAP1188 test!
    Product ID: 0x50
    Manuf. ID: 0x1
    Revision: 0x1
    CAP1188 not found


    This is the I2C scanner output:
    I2C Scanner
    Scanning...
    I2C device found at address 0x28 !
    I2C device found at address 0x29 !
    I2C device found at address 0x2A !
    done

    I tried with and without the reset pin, tried all addresses.

    Appreciate you looking into this.

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,544
    Which version of Teensyduino are you using?

    Version 1.48 (the latest) fixed a bug in the Wire library. If you're using 1.47 or older, please update to 1.48.

  7. #7
    Member
    Join Date
    Mar 2019
    Location
    Hoboken, New Jersey, USA
    Posts
    33
    Yesterday I downloaded the latest of everything.
    Checking now.
    Adduino help says Adruino 1.8.10 and Teensyduino 1.48
    The Adafruit library I downloaded today.

  8. #8
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,544
    Can you confirm whether the problem happens with only 1 of these boards, or if 2 or 3 are needed.

    I will order 1, 2 or 3 from Adafruit for testing, depending on your answer.

  9. #9
    Member
    Join Date
    Mar 2019
    Location
    Hoboken, New Jersey, USA
    Posts
    33
    Forgot to mention. It's Teensy 4.0
    Love it. Want to stuff it with everything I can.

  10. #10
    Senior Member vjmuzik's Avatar
    Join Date
    Apr 2017
    Location
    Florida
    Posts
    335
    Looks like the register values are not reading back what it expects, the product ID is right but the revision and Manufacturer ID are not. Here is what the library expects the values to be:
    Code:
       if ((readRegister(CAP1188_PRODID) != 0x50) ||
          (readRegister(CAP1188_MANUID) != 0x5D) ||
          (readRegister(CAP1188_REV) != 0x83)) {
        return false;
      }
    You can change those values in this if statement to the values that Serial monitor shows and see if it works after that. This is located in the begin function directly after the Serial prints so this is what is causing it to say not detected even though it is reading from the chips.

  11. #11
    Member
    Join Date
    Mar 2019
    Location
    Hoboken, New Jersey, USA
    Posts
    33
    Tried to change the "if" like below. Still see the "?????" in the monitor. Don't understand how it can print "0x1" and fail to compare to it.
    Anyway, I commented the "if" out and can see the touches, but they never go away after I stop touching. Once touched, it stays "touched" until I power it down.
    And sensor 1 is "touched" on power up, even though I never touch it.
    Tried with 1 and 3 chips, same thing.

    /*if ((readRegister(CAP1188_PRODID) != 0x50) ||
    (readRegister(CAP1188_MANUID) != 0x1) ||
    (readRegister(CAP1188_REV) != 0x1)) {
    Serial.println("?????");
    return false;
    }*/

    I'll keep digging and adding serial outputs in the Adafruit library to see if I can find something.

    Thanks for all the help.

  12. #12
    Member
    Join Date
    Mar 2019
    Location
    Hoboken, New Jersey, USA
    Posts
    33
    Quote Originally Posted by PaulStoffregen View Post
    Can you confirm whether the problem happens with only 1 of these boards, or if 2 or 3 are needed.

    I will order 1, 2 or 3 from Adafruit for testing, depending on your answer.
    1 or 3, same thing.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •