CapSense Error Code -1

Hello,

I'm getting an error code of -1 on pins 7,8, or 9. Are these pins not available? Here's my Capsense Setup:

Common Pin: A5
Sense Pins: 2,3,4,5,6 (all working beautifully)

I need 6 CapSensors total, but I can't seem to utilize 7,8, or 9 (which are the only pins left available for my project see below for pin usage).

Any advice is much appreciated.

Thanks,

jamie

Pins for Project:

0,1: Serial
2,3,4,5,6: CapSense
7: Pullup switch
8: ***Would like to use as sixth CapSense, but error -1
9: ShiftPWM Latch
10,11,12,13: SPI
A0: ADXL335
A1: ADXL335
A2: ADXL335
A3: ADXL335
A4: Speaker Out
A5: CapSense Common

Capsense is no standard feature of Arduino, you should provide a link to the code/environment you used.

Here's where I found the library:

http://www.arduino.cc/playground/Main/CapSense

I'm wondering if there's a limit on the number of receive pins you can connect to a single send pin. I have it working just fine at 5-1, but I need 6-1. I have two extra A5,A6 on my pro mini, but they don't seem to have the digital hardware needed.

From the looks on the Web, it appears people have used pins 7,8,and 9, so I'm a bit stumped.

Cheers,

Jamie

Also it may be worth noting, I'm only using pins 11 and 13 although SPI is enabled for ShiftPWM. So if someone know how I can use pins 10 and 12 while SPI is running, I could give that a shot.

Capsense needs two pins in the constructor. Which is the sending one, which the receiving one?

If you get an error, the pin number cannot be translated into a port (either receiving or sending pin). Have you specified the correct board type? Which do you use?

If you want help then post the code that you are having trouble with, rather than having us guess what you might have done wrong.

I'm using an Arduino Pro Mini 3.3V. I have that as my board setting in the Arduino Editor. Do I need to declare this somewhere else too?I have the pin A5, configured as my send pin. It works on pins 2,3,4,5,6 but not on 7,8 or 9. I can rule out the sensor because I hooked it up to a good pin and it works. Here's a strip down of the code without my SPI routines, etc:

int sensePins[6] = {2,3,4,5,6,8};
CapSense mySensors[6] = { CapSense(A5, sensePins[0]),
                                        CapSense(A5, sensePins[1]),
                                        CapSense(A5, sensePins[2]),
                                        CapSense(A5, sensePins[3]),
                                        CapSense(A5, sensePins[4]),
                                        CapSense(A5, sensePins[5])};

setup(){
    Serial.begin(9600);
}

loop(){
    for(int i=0; i<6; i++){
        long capSenseValue = mySensors[i].capSense(30);
        Serial.print("Sensor Pin #");
        Serial.print(sensePins[i]);
        Serial.print(": ");
        Serial.print(capSenseValue);
        Serial.println();
    }
}
//    With my configuration, when I touch all sensors, this is what I see:
//    
//    Sensor Pin #2: 68
//    Sensor Pin #3: 53
//    Sensor Pin #4: 48
//    Sensor Pin #5: 63
//    Sensor Pin #6: 41
//    Sensor Pin #8: -1
//    ...

The problem with only posting part of your code is we don't get to see the errors.
If you add

#include <CapSense.h>

at the start and put void before setup() and loop() the thing compiles.
So what exactly is your problem?

I was hoping I would find someone with knowledege of the capsense library to help me better understand the error code of -1 from the sensor. My code works and runs perfectly, what you see here is psuedo code.

what you see here is psuedo code.

So all we can give you is pseudo answers.

Which version of the library do you use (3 or 4)? Is your Mini Pro using an ATmega168 or an ATmega328p?

Have you always used A5 as your sending pin?

Which version of the IDE do you use? The newest one (1.0.1)?

I'm using the latest version of the IDE, just downloaded it last week. I'm also using version4 of capsense, version3 didn't work for me. I have the 328.

pylon:
Have you always used A5 as your sending pin?

You caught me there, I should try with other pins as the send pin, perhaps a digital. I'll try swapping A5 and 8 and see if that does anything differently. I suppose I could use A5 as my switch input pin, that way I'm working with all digital pins.

In version 4 of the library the pins are checked that way:

#ifdef NUM_DIGITAL_PINS
	if (sendPin >= NUM_DIGITAL_PINS) error = -1;
	if (receivePin >= NUM_DIGITAL_PINS) error = -1;
#endif

By using the board "Mini Pro 3.3 with 328p" it should use the standard pin definition and NUM_DIGITAL_PINS should be 20. A5 is defined as 19, so you should not get the -1 back as you do. But that's the only location in the library where error is set to a negative number and the result code -1 means exactly that:

	if (error < 0) return -1;            // bad pin

Something is not going the same in your IDE as it's doing in mine. You should check what the values of A5 and NUM_DIGITAL_PINS are when the code is compiled on your machine by inserting something like:

Serial.print("A5=");
Serial.println(A5);
Serial.print("num_pins=");
Serial.println(NUM_DIGITAL_PINS);

into your setup routine. Post the results.