Pages: [1]   Go Down
Author Topic: capacitive sensor with no ground  (Read 1194 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 3
Posts: 188
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I am trying to set up a capacitive sensor on an attiny. I have it working fine when the power is supplied from an arduino but when I cut it off and only do battery it goes completely haywire. I am assuming this is because I am cutting off a large ground. I just ordered a 7 segment display to see what the readings are like when its cut from ground since I can't do serial monitor with it unplugged :/

any suggestions on how to handle this would be great. I rather not have to connect it to a large ground (like http://playground.arduino.cc//Main/CapacitiveSensor?from=Main.CapSense suggests).
Logged

for(i = 0, i < 820480075, i++){ Design(); Code(); delay(1000); } // hellowoo.com

Cumming, GA
Offline Offline
Edison Member
*
Karma: 20
Posts: 1657
Ultimate DIY: Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

That's not making sense.  battery power should not matter.
« Last Edit: January 20, 2013, 02:52:09 pm by pwillard » Logged

Offline Offline
Full Member
***
Karma: 3
Posts: 188
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

That's not making sense.  battery power should not matter.

why would it not make sense? You are completely removing the ground from the system. attiny grounded through arduino through usb through computer through house...right? when you go battery the ground from house is removed, hence changing the values.

or am I missing something?
Logged

for(i = 0, i < 820480075, i++){ Design(); Code(); delay(1000); } // hellowoo.com

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 150
Posts: 5638
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That's not making sense.  battery power should not matter.

It does for capacitive sensors...when you switch to batteries you remove a huge chunk of metal from the system.


Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I too saw this same effect of the sensor not working when on battery verses on the "mains".  I made some slight modifications to the CapacitiveSensor.cpp library file that seems to have fixed this issue.  Essentially, I wanted to drive the circuit to an output set low as to connect it to ground.  This helps to drain the capacitance on each iterative cycle so that each measurement cycle starts from zero.  In addition, I also added a timer to the loop to help allow the discharge be complete before the next measurement.

Code:
int CapacitiveSensor::SenseOneCycle(void)
{
    noInterrupts();
*sOut &= ~sBit;    // set send pin to INPUT     (<<<<<<<<<<<< Change here <<<<<<<<<<<<)
*sOut &= ~sBit;        // set Send Pin Register low

*rReg &= ~rBit;        // set receivePin to input
*rOut &= ~rBit;        // set receivePin Register low to make sure pullups are off

*rReg |= rBit;         // set pin to OUTPUT - pin is now LOW AND OUTPUT
*rReg &= ~rBit;        // set pin to INPUT

*sOut |= sBit;         // set send Pin High
    interrupts();

while ( !(*rIn & rBit)  && (total < CS_Timeout_Millis) ) {  // while receive pin is LOW AND total is positive value
total++;
}

if (total > CS_Timeout_Millis) {
return -2;         //  total variable over timeout
}

// set receive pin HIGH briefly to charge up fully - because the while loop above will exit when pin is ~ 2.5V
    noInterrupts();
*rOut  |= rBit;        // set receive pin HIGH - turns on pullup
*rReg |= rBit;         // set pin to OUTPUT - pin is now HIGH AND OUTPUT
*rReg &= ~rBit;        // set pin to INPUT
*rOut  &= ~rBit;       // turn off pullup
        *sOut |= sBit; // set send pin to OUTPUT     (<<<<<<<<<< change here <<<<<<<<<<<<)
*sOut &= ~sBit;        // set send Pin LOW
    interrupts();

Code:
long CapacitiveSensor::capacitiveSensorRaw(uint8_t samples)
{
total = 0;
if (samples == 0) return 0;
if (error < 0) return -1;                  // bad pin - this appears not to work

for (uint8_t i = 0; i < samples; i++) {    // loop for samples parameter - simple lowpass filter
if (SenseOneCycle() < 0)  return -2;   // variable over timeout
delay(5);                              // (<<<<<<<<<<< Change Here <<<<<<<<<<<<<<<<<<<)
}

return total;
}
Logged

Offline Offline
Full Member
***
Karma: 3
Posts: 188
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I will be testing this very soon. thank you for this reply smiley
Logged

for(i = 0, i < 820480075, i++){ Design(); Code(); delay(1000); } // hellowoo.com

Pages: [1]   Go Up
Jump to: