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

I'm using a linear soft potentiometer in a project;
https://www.sparkfun.com/datasheets/Sensors/Flex/SoftPot-Datasheet.pdf
https://www.sparkfun.com/datasheets/Sensors/Flex/SoftPot-Specs.pdf

The project involves mounting the soft pot on the side of an air hockey table and registering where the puck strikes.
As the Softpot registers a different value for where it is pressed on the sensor, it seems a good way to get this sort of data in with a minimum of fuss (one sensor covers 50cm, accuracy is quite precise, the puck bounce is unimpeded and there is only set of cables to deal with for install).

My concern before I tried it was the puck would strike too hard and damage the sensor. However, in practice, the sensor does not get damaged, but the puck seems to strike it  too fast for a contact to register. (BTW, I also tried it without the paper over top)


I wonder if there is any advice someone can give me? is faster sampling a solution?
I am currently tying this :
http://forum.arduino.cc/index.php/topic,6549.0.html

If this doesn't work, I can do a series of ir pairs, but it gets messier....many thanks for any input

Any better advice?
Logged

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

Right, I tried the faster analog read:
http://forum.arduino.cc/index.php/topic,6549.0.html
but no luck.
Logged

Norfolk UK
Offline Offline
Faraday Member
**
Karma: 69
Posts: 2557
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It will help if you tell us what Arduino you have (UNO, MEGA etc). Draw or describe how the sensor is connected and show us the code you tried. I'm sure the arduino can do the job but maybe analogue read is not the answer and you may need to try a comparator input.
Logged


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

Thanks for the advice, that sounds promising!

Sorry to forget, I am using an Arduino Uno.

From the sensor there is just one wire for 5v, one ground, and one going into A0;

image from http://bildr.org/2012/11/touch-sliders-with-a-softpot-arduino/
and here is the code for the Arduino;
Code:
int softPot = A0;
int softPotReading = 0;
int inByte = 0;

void setup() {
Serial.begin(9600);
digitalWrite(softPot, HIGH); //enable pullup resistor
establishContact();
}
void loop() {
  if (Serial.available() > 0) {
    inByte = Serial.read();
    softPotReading = analogRead(softPot)/4;
    Serial.write(softPotReading);
  }
}
void establishContact() {
 while (Serial.available() <= 0) {
 Serial.print('A'); // send a capital A
 delay(300);
}
}

From here, it goes into processing where the serial output is read into an array and a rect is displayed according to the value from the pot.
It all works, bar the fast puck contact.

Any thoughts very welcome....
« Last Edit: March 09, 2014, 12:06:56 pm by helmutapplebaum » Logged

Norfolk UK
Offline Offline
Faraday Member
**
Karma: 69
Posts: 2557
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I cannot see what the need of inByte is for in your code and because the analogue pot is read only when a byte is received from processing your not going to read very quickly. No need to turn on internal pullup on the analogue input pin.
A better idea would be to have a threshold value that sits just above/below (depends if reading increases/decreases when puc hits)  the reading you get when the strip is inactive and read the analogue pin as fast as you can. If the reading goes under/over the threshold value (a puc has hit it) then send it to processing over serial. Speed up the serial from 9600 to 115200 will also make reaction time quicker.

Code:
int softPot = A0;
byte softPotReading = 0;

int threshold = 512 >> 2;

void setup() {
  Serial.begin(115200);
  establishContact();
}
void loop() {
  softPotReading = analogRead(softPot) >> 2;
  if (softPotReading > threshold) {  // Assume reading increases when puc hits
    Serial.write(softPotReading);
  }
}
void establishContact() {
  while (Serial.available() <= 0) {
    Serial.print('A'); // send a capital A
    delay(300);
  }
}

Logged


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

Thanks,

I have inByte, as I have other sensors other than the Pot and am sending multiple values over serial.
I have code from the link below in processing to detect the start of data to get the incoming data into the correct slots in an array in processing;

Code:
void serialEvent(Serial myPort){
  int inByte = myPort.read();
  if (firstContact==false){
    if (inByte=='A'){
      myPort.clear();
      firstContact = true;
      myPort.write('A');
    }
  }
  else {
    serialInArray[serialCount] = inByte;
    serialCount++;
    if (serialCount > 1){
      psoftPotReading = serialInArray[0];
      pir1Reading = serialInArray[1];
      println("psoftPotReading = " + psoftPotReading);
      println("pir1Reading = " + pir1Reading);
      myPort.write('A');
      serialCount = 0;
    }
  }


it made some sense to me!

I'm trying out your example, many thanks for the help
Logged

Offline Offline
Faraday Member
**
Karma: 62
Posts: 3031
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If analog reading doesn't work,   you may need to design some kind of special detector circuit to detect impacts on the pot.  This is certainly possible but would require quite a bit of expertise  and a lot of trial and error.

What you would need to do,  is design some combination of opamps, capacitors and diodes which will :

(a)  detect deviation from the quiescent state
(b)  capture and hold the peak level of the deviation
(c)  signal the arduino by interrupt to collect the peak level of the deviation
(d)  reset in preparation for the next impact.

Detecting events is quite easy,  it is a bit harder to capture the peak level of the event,  which you need to do in this case because it represents the position along the strip.
Logged

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

Thanks for the great suggestion and examples.

Unfortunately, due to my low level of skill and short timeframe (two weeks), I will have to do something a bit more manageable than that.
I was hoping the softpot would be a fairly straightforward solution, as I have to do some construction as well.

As it is, I am trying the solution by Riva, without much luck at the moment, but it looks more hopeful....

thanks for all your input.
Logged

Norfolk UK
Offline Offline
Faraday Member
**
Karma: 69
Posts: 2557
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

As it is, I am trying the solution by Riva, without much luck at the moment, but it looks more hopeful....
For a start forget linking with processing and just run the below sketch and view the results in the serial monitor. Without touching the pot strip you should get a slightly fluctuating readings. After a few seconds make a note of the min/max values and let us know. When you press the strip the min/max reading should change.

Code:
int softPot = A0;
int softPotReading = 0;
int minReading = 1024;
int maxReading = 0;

void setup() {
  Serial.begin(115200);
  softPotReading = analogRead(softPot);
 
}
void loop() {
  softPotReading = analogRead(softPot);
  if (softPotReading > maxReading){
    maxReading = softPotReading;
  }
  if (softPotReading < minReading){
    minReading = softPotReading;
  }
 
  Serial.print("MAX:");
  Serial.print(maxReading);
  Serial.print("\t");
  Serial.print("MIN:");
  Serial.println(minReading);
  delay(10);
}
Logged


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

just saw this, thanks, will try!

I was just sorting my other sensors - ir pairs, thanks for sticking with it.
Logged

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

Thanks,

When I first try your code, I get gibberish in the serial monitor. By changing the baud rate to 9600, I get sensible output.

Max values start anywhere between 800 and 200, and stay stable until touching  a few times.
Min start just below Max and decreases quickly, then very slowly after 250

When I touch it, it sometimes eventually defaults to 1023 Max or 0 Min, and touching  gives some Min (and sometimes Max)  values (but not very responsive at all, and sometimes the values don't make complete sense) until it decides to stop working. Total Max and Min is 1023 and 27 (rest is hidden in corner).

I can still get it to work with my old code going to processing. The readings there are stable at about 250 (/4 in Arduino code) until I press, then they spit out a number in the 10-245 range (corner), and go back to 250. Works fine except for the speed , and anything over 245 I have do nothing,)
« Last Edit: March 10, 2014, 02:13:37 pm by helmutapplebaum » Logged

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

Ok, I think I see what the code is doing now, somehow the max or minReadings are sent in the next step?
Not 100% sure

It seems less responsive than the other code though....
Logged

Offline Offline
Faraday Member
**
Karma: 62
Posts: 3031
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The problem with rivas code,   is that you are probably only looking at the device about once every 14 milliseconds.   The impact even would come and go between readings,   and you would not even know that it has happened.
Logged

Offline Offline
Faraday Member
**
Karma: 62
Posts: 3031
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The other issue that I can forsee,  is that when there is an impact,   the "wiper" contact of the pot is pushed against the long linear resistor,  and will return the voltage,  which at that point should be proportional along the length of the resistor.

it is not clear,   what voltage will be present on the sensor terminal of the device at other times.  It may be floating randomly if it is not in contact with anything.  You may need to connect the sensor terminal to one of the other terminals of the device to provide a definite state when there is no contact -  this is similar concept to using a pull-up or pull-down resistor on a switch.
Logged

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

Thanks,
That might explain the responsiveness issue, ....

BTW, there is no wiper, and the pot is not floating, so no problem there...
Logged

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