Go Down

Topic: how fast a contact can a linear soft potentiometer detect? (Read 5419 times) previous topic - next topic

MarkT

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: [Select]

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!
[ I won't respond to messages, use the forum please ]

helmutapplebaum

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

helmutapplebaum

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: [Select]

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!

Go Up