We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Smooth/ease values from sensors
Page Index Toggle Pages: 1
Smooth/ease values from sensors (Read 1785 times)
Smooth/ease values from sensors
Jan 3rd, 2010, 11:42am
 
I'm working on an installation and the values from the proximity sensors (Sharp long- and mid-distance IR sensors) 'flicker' or change very fast (check the video here: http://www.youtube.com/watch?v=yxS_sV3b674). This problem renders the whole project useless, as it was supposed to generate music and change values (cutoff, pitch, etc.). I've bee trying to find the answer for ages, with not much success. Any ideas welcome...
Re: Smooth/ease values from sensors
Reply #1 - Jan 3rd, 2010, 11:45am
 
i get an error checking your vid
Re: Smooth/ease values from sensors
Reply #2 - Jan 3rd, 2010, 12:02pm
 
video works now.
hmm strange results.
what is actually the right result ? or what should it look like.
i cant read what this is showing me.
it always jumps from left to right.  that what would be the correct value and what is the error ?
Re: Smooth/ease values from sensors
Reply #3 - Jan 3rd, 2010, 12:12pm
 
Coding is nice, but it might be easy to try the analog way. Isn´t there an analog voltage output you can acces before being digitalized? Why not add a capacitor, depending of the resistance of the sensor out?
Re: Smooth/ease values from sensors
Reply #4 - Jan 3rd, 2010, 12:25pm
 
The actual result should be smoother. As I move my hand slowly towards or away the sensors, the values flickr/jump/bounce. The values are represented with the x and y position of the cross. By the way, the sketch:

//use the 'standard firmata' for processing library!

import cc.arduino.*;
import processing.serial.*;
import promidi.*;
PFont font;
Arduino arduino;
MidiIO midiIO;
MidiOut midiOut;
int sensor1;
int sensor2;
int cs1= width/2;
Note note;

void setup(){
size(500,500);
arduino = new Arduino(this, Arduino.list()[1], 57600);
arduino.pinMode(7, Arduino.INPUT);
arduino.pinMode(6, Arduino.INPUT);
arduino.pinMode(5, Arduino.INPUT);
midiIO = MidiIO.getInstance(this);
midiOut = midiIO.getMidiOut(1,"IAC Driver - Bus 1");
midiIO.printDevices();
println(Arduino.list());
}
void draw(){
background(0);
fill(255);
smooth();
rectMode(CENTER);
noStroke();
int cs1 = constrain(sensor1,0,height);
int cs2 = constrain(sensor2,0,500);
rect(cs2,cs1,10,40);
rect(cs2,cs1,40,10);
sensor1 = arduino.analogRead(0);
sensor2 = arduino.analogRead(1);

midiOut.sendController(new Controller(1 sensor1=3*sensor1*sensor1-2*sensor1*sensor1;,sensor1/4));
midiOut.sendController(new Controller(2,sensor2/4));
println(cs2);
delay(10);

if (arduino.digitalRead(7) == Arduino.LOW){
 note = new Note(64,64,1);
 midiOut.sendNote(note);
 fill(255);
 ellipse(width*0.3,height/2,80,80);
 println("HIGH");
}
else {
 noFill();
 stroke(255);
 ellipse(width*0.3,height/2,80,80);
}
}





















Re: Smooth/ease values from sensors
Reply #5 - Jan 3rd, 2010, 12:27pm
 
There is an analog output. I gotta check the manufacturer's spec sheet.


abel wrote on Jan 3rd, 2010, 12:12pm:
Coding is nice, but it might be easy to try the analog way. Isn´t there an analog voltage output you can acces before being digitalized Why not add a capacitor, depending of the resistance of the sensor out

Re: Smooth/ease values from sensors
Reply #6 - Jan 3rd, 2010, 12:31pm
 
By the way, just realised that the output of the sensor is digital... Spec sheet here: http://tiny.cc/ma20j

That puts the whole scenario in a new perspective, as I have used the sensor with analog inputs. Should I try it with digital pin?
Re: Smooth/ease values from sensors
Reply #7 - Jan 3rd, 2010, 12:33pm
 
It might need some debouncing:

only accept a value if it stayed the same (or for analog: within a certain range) over a period of time (50-100ms).

Or some averaging:

Save the last x (where x depends on the number of samples per second) values and average those to use as the actual value.
Re: Smooth/ease values from sensors
Reply #8 - Jan 3rd, 2010, 12:57pm
 
As  I understand the spec sheet, the output is pure analog. The output-voltage is updatet every x milliseconds, but no digital information.
Of course, software debouncing or analog will cause a retarded reaction.
Re: Smooth/ease values from sensors
Reply #9 - Jan 3rd, 2010, 12:59pm
 
JR, that's what I need but my coding skills and knowledge is appalling. How can I average the value or debounce? Can you give me an example please?

Thank you very much for all the effort guys!
Re: Smooth/ease values from sensors
Reply #10 - Jan 3rd, 2010, 2:39pm
 
You can do the smoothing on the Arduino.  See the smoothing tutorial on the Arduino tutorials page Wink
Re: Smooth/ease values from sensors
Reply #11 - Jan 3rd, 2010, 2:40pm
 
An interesting development: Lucky Larry realised that the IR sensor send exponential values (see the spec sheet!). He managed to convert the values to linear ones and get the correct distance. Link here:

http://tiny.cc/exptolin

He used the conversion snippet in his Arduino code, while I used it in my Processing sketch. It works!

Still need some help with the debouncing/averaging though...
Re: Smooth/ease values from sensors
Reply #12 - Jan 3rd, 2010, 3:22pm
 

blindfish wrote on Jan 3rd, 2010, 2:39pm:
You can do the smoothing on the Arduino.  See the smoothing tutorial on the Arduino tutorials page Wink


Thanks dude, but I'd rather do it in Processing. I know there's a simple way, just cannot find it... Will try the Arduino-stuff...
Re: Smooth/ease values from sensors
Reply #13 - Jan 4th, 2010, 2:13am
 
Whether you do it in Processing or on the Arduino the same principles apply - i.e. the Arduino code from the tutorial is easy enough to implement in Processing...
Re: Smooth/ease values from sensors
Reply #14 - Jan 5th, 2010, 10:07am
 
Good to read this thread, having the same problem with the sharp ir sensor, and its sending my graph a bit haywire with the noise. Links provided should be of help.

Thanks folks!
Page Index Toggle Pages: 1