Pages: 1 2 [3]   Go Down
Author Topic: how fast a contact can a linear soft potentiometer detect?  (Read 3347 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Shannon Member
****
Karma: 216
Posts: 12556
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Firstly the speed of the code is completely limited by the Serial.write call - even at
115200 baud that's 87us per byte, almost as slow as the default analogRead() call.

So you have to poll the analog reading without doing Serial output, detect an event,
and only then report back.

To detect you need more circuitry.

Add a resistor from the wiper to a resistor to a digital output pin.

code like this:
Code:
int detect_loop ()
{
  int l, h ;
  do
  {
    digitalWrite (wiperbias_pin, LOW) ;
    l = fastAnalogRead (A0) ;
    digitalWrite (wiperbias_pin, HIGH) ;
    h = fastAnalogRead (A0) ;
  } while (h - l > THRESHOLD) ;
  return (h + l) / 2 ;
}



Choose a resistance value that doesn't affect the readings very much when the soft
pot is being pressed, but has significant effect when not pressed - select a THRESHOLD
value that discriminates these two cases reliably.  Bingo!
Logged

[ I won't respond to messages, use the forum please ]

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

Keep the ideas coming, .....I'm ordering a new 25 quid sensor to fry!!!
Logged

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

Thanks,

I believe the issue with that is; since I am sending other sensors over serial to processing, and in processing writing them to an array, I can't really have a sensor that only sends when it has a certain reading.

BTW, what is the circuit you propose - 1 resistor between the Softpot output and ta digital pin?

Firstly the speed of the code is completely limited by the Serial.write call - even at
115200 baud that's 87us per byte, almost as slow as the default analogRead() call.

So you have to poll the analog reading without doing Serial output, detect an event,
and only then report back.

To detect you need more circuitry.

Add a resistor from the wiper to a resistor to a digital output pin.

code like this:
Code:
int detect_loop ()
{
  int l, h ;
  do
  {
    digitalWrite (wiperbias_pin, LOW) ;
    l = fastAnalogRead (A0) ;
    digitalWrite (wiperbias_pin, HIGH) ;
    h = fastAnalogRead (A0) ;
  } while (h - l > THRESHOLD) ;
  return (h + l) / 2 ;
}



Choose a resistance value that doesn't affect the readings very much when the soft
pot is being pressed, but has significant effect when not pressed - select a THRESHOLD
value that discriminates these two cases reliably.  Bingo!
Logged

Pages: 1 2 [3]   Go Up
Jump to: