Due to high demand expect some shipping delays at this time, orders may not ship for 1-2 business days.
0

External LEDs on CAP1188
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

External LEDs on CAP1188

by ninanas98 on Thu Oct 28, 2021 8:21 am

Hi,

For a school project, I need to use capacitive sensors to turn on LEDs.
I am using two CAP1188 modules to control 16 LEDs.
I got the 2 modules working and can turn on LEDs that are connected to the Arduino, but I can only connect 11 LEDs to Arduino. So I want to use the output pins on the CAP1188 module. How do I control the L1-L8 output on the CAP1188?

My code so far for controlling LED's connected to the Arduino is:
Code: Select all | TOGGLE FULL SIZE
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_CAP1188.h>

// For I2C, connect SDA to your Arduino's SDA pin, SCL to SCL pin
// On UNO/Duemilanove/etc, SDA == Analog 4, SCL == Analog 5

// Use I2C, no reset pin!
Adafruit_CAP1188 cap1 = Adafruit_CAP1188();
Adafruit_CAP1188 cap2 = Adafruit_CAP1188();
uint8_t capAddr1 = 0x29;
uint8_t capAddr2 = 0x28;

uint8_t touched1 = 0;
uint8_t touched2 = 0;

int led1 = 2;
int led2 = 3;
int led3 = 4;
int led4 = 5;
int led5 = 6;
int led6 = 7;
int led7 = 8;
int led8 = 9;
int led9 = 10;
int led10 = 11;
int led11 = 12;

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

  while (!cap1.begin(capAddr1))
  {
    Serial.println("CAP1188 1 not found");
  }
  Serial.println("CAP1188 1 found!");

  while (!cap2.begin(capAddr2))
  {
    Serial.println("CAP1188 2 not found");
  }
  Serial.println("CAP1188 2 found!");

  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
  pinMode(led6, OUTPUT);
  pinMode(led7, OUTPUT);
  pinMode(led8, OUTPUT);
  pinMode(led9, OUTPUT);
  pinMode(led10, OUTPUT);
  pinMode(led11, OUTPUT);
}

void loop() {

  touched1 = cap1.touched();
  touched2 = cap2.touched();

  for (uint8_t i = 0; i < 8; i++) {
    if (touched1 & (1 << i)) {
      Serial.print("C1"); Serial.print(i + 1); Serial.print("\t");
    }
  }

  for (uint8_t i = 0; i < 8; i++) {
    if (touched2 & (1 << i)) {
      Serial.print("C2"); Serial.print(i + 1); Serial.print("\t");
    }
  }


  Serial.println();
  delay(50);

  if (touched1 & 0x01) {
    digitalWrite(led1, HIGH);
  }
  else
  {
    digitalWrite(led1, LOW );
  }

  if (touched1 & 0x02) {
    digitalWrite(led2, HIGH);
  }
  else
  {
    digitalWrite(led2, LOW );
  }

  if (touched1 & 0x04) {
    digitalWrite(led3, HIGH);
  }
  else
  {
    digitalWrite(led3, LOW );
  }

  if (touched1 & 0x08) {
    digitalWrite(led4, HIGH);
  }
  else
  {
    digitalWrite(led4, LOW );
  }

  if (touched1 & 0x10) {
    digitalWrite(led5, HIGH);
  }
  else
  {
    digitalWrite(led5, LOW );
  }

  if (touched1 & 0x20) {
    digitalWrite(led6, HIGH);
  }
  else
  {
    digitalWrite(led6, LOW );
   
  }

  if (touched1 & 0x40) {
    digitalWrite(led7, HIGH);
  }
  else
  {
    digitalWrite(led7, LOW );
  }

  if (touched1 & 0x80) {
    digitalWrite(led8, HIGH);
  }
  else
  {
    digitalWrite(led8, LOW );
  }

    if (touched2 & 0x01) {
    digitalWrite(led9, HIGH);
  }
  else
  {
    digitalWrite(led9, LOW );
  }

  if (touched2 & 0x02) {
    digitalWrite(led10, HIGH);
  }
  else
  {
    digitalWrite(led10, LOW );
  }

  if (touched2 & 0x04) {
    digitalWrite(led11, HIGH);
  }
  else
  {
    digitalWrite(led11, LOW );
  }
}


Thanks in advance!!

ninanas98
 
Posts: 3
Joined: Thu Oct 28, 2021 8:17 am

Re: External LEDs on CAP1188

by adafruit_support_bill on Thu Oct 28, 2021 8:44 am

The output pins are active LOW. So connect the anode of your LED to 3.3v via a current limiting resistor. And connect the cathode to the output pin of the CAP1188.

adafruit_support_bill
 
Posts: 82453
Joined: Sat Feb 07, 2009 10:11 am

Re: External LEDs on CAP1188

by dastels on Thu Oct 28, 2021 8:57 am

Section 4.4 (page 32) and Sections 5.25-5.38 (pages 65-82) detail the LED output control. It doesn't sound like you'll need much, just set them for direct control, and then control them (so probably just involving 2 registers). Direct control is actually the default but the begin method sets the LEDs to respond to the cap touch inputs (write 0x00 to the LED_LINK register). Then you just need to control them via the LED Output Control Register (see section 5.28).

The library doesn't support direct LED control and I don't see any forks that do either so it will need to be added. The code is at https://github.com/adafruit/Adafruit_CAP1188_Library

Dave

dastels
 
Posts: 7959
Joined: Tue Oct 20, 2015 3:22 pm

Re: External LEDs on CAP1188

by dastels on Thu Oct 28, 2021 8:58 am

See the schematic https://learn.adafruit.com/assets/35807 for how to wire the LEDs.

Dave

dastels
 
Posts: 7959
Joined: Tue Oct 20, 2015 3:22 pm

Re: External LEDs on CAP1188

by ninanas98 on Thu Oct 28, 2021 9:32 am

dastels wrote:Section 4.4 (page 32) and Sections 5.25-5.38 (pages 65-82) detail the LED output control. It doesn't sound like you'll need much, just set them for direct control, and then control them (so probably just involving 2 registers). Direct control is actually the default but the begin method sets the LEDs to respond to the cap touch inputs (write 0x00 to the LED_LINK register). Then you just need to control them via the LED Output Control Register (see section 5.28).

The library doesn't support direct LED control and I don't see any forks that do either so it will need to be added. The code is at https://github.com/adafruit/Adafruit_CAP1188_Library

Dave


Thank you for your answer!

I read through the datasheet multiple times but didn't really understand it.

How does it code technical work, can I write them as digitalWrite or do I need to address the output pins on the CAP1188 differently then a Arduino output?

Also thanks to Bill

ninanas98
 
Posts: 3
Joined: Thu Oct 28, 2021 8:17 am

Re: External LEDs on CAP1188

by ninanas98 on Thu Oct 28, 2021 9:42 am

adafruit_support_bill wrote:The output pins are active LOW. So connect the anode of your LED to 3.3v via a current limiting resistor. And connect the cathode to the output pin of the CAP1188.


Thanks for the help Bill!!

This did exactly what I needed.

ninanas98
 
Posts: 3
Joined: Thu Oct 28, 2021 8:17 am

Please be positive and constructive with your questions and comments.