Pages: [1]   Go Down
Author Topic: sensors affecting one another  (Read 1969 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 1
Posts: 12
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I am using the arduino to take inputs from a Spectra industries linear softpot (basically like a potentiometer with a floating wiper when not actuated by pressure) as well as a Yamaha BC3 breath controller (a breath-pressure sensor for musical instrument control). The data is then sent out via midi to a synthsizer.

The softpot sends out 'pitchbend data', the breath-controller sends out 'control change data' - you can just think of them as data types 'A' and 'B'

The softpot works fine in this setup, always sending out Pitchbend. The breath-controller works fine when I don't use the softpot (I comment out the softpot part of the code), but when used together it transmits both Control-change  _and_  Pitchbend. I think the code is sound (although I am completely new to any sort of programming), so I think that the problem is on the hardware side.

What have I done wrong?
Here's the circuit:

And here's the code:
#include <MIDI.h>

// These constants won't change:
const int sensorPin = A0;    // pin that the sensor is attached to
const int pitchpin = A1;

// variables:
int sensorValue = 0;         // the sensor value
int sensorMin = 1023;        // minimum sensor value
int sensorMax = 0;           // maximum sensor value
int midval = 0;
int prevmidval = 0;
int THRESHOLD = 2;
int pitchbendval = 0;
int prevpitch = 0;
int pitchthresh = 1;

void setup() {
  // turn on LED to signal the start of the calibration period:
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);
  MIDI.begin(1);
  {
  Serial.begin(31250
  );
}
 
 

//  // calibrate during the first five seconds
  while (millis() < 5000) {
    sensorValue = analogRead(sensorPin);

//    // record the maximum sensor value
    if (sensorValue > sensorMax) {
      sensorMax = sensorValue;
    }
//
//    // record the minimum sensor value
    if (sensorValue < sensorMin) {
      sensorMin = sensorValue;
    }
  }

//  // signal the end of the calibration period
//  digitalWrite(13, LOW);
}

void loop() {
//  // read the sensor:
  sensorValue = analogRead(sensorPin);

//  // apply the calibration to the sensor reading
  sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 127);
//
//  // in case the sensor value is outside the range seen during calibration
  sensorValue = constrain(sensorValue, 0, 127);
// 
  midval = -sensorValue+127 ;
 
  if(abs(midval - prevmidval) >= THRESHOLD){
   
 
  MIDI.sendControlChange(02, midval, 1);
  prevmidval = midval;
  }
  pitchbendval = analogRead(pitchpin) ;
  pitchbendval = map(pitchbendval, 0, 1023, 0, 16383);
  if (pitchbendval==0)  if (prevpitch > 2) {
    pitchbendval = 8192;
  }
  if(abs(pitchbendval - prevpitch) >= pitchthresh){
 
 
  MIDI.sendPitchBend( pitchbendval , 1);
  prevpitch = pitchbendval;
  }
 
//  delay (1000) ;

//  Serial.println(midval, DEC);
}

Logged

0
Offline Offline
Shannon Member
****
Karma: 160
Posts: 10418
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am unsure what you intend.  I would have thought things are working as expected - both sensors are being read and sending updates via Midi - but you don't want this?
Logged

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

0
Offline Offline
Newbie
*
Karma: 1
Posts: 12
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

both are sending data via midi, but the second sensor (the breath controller) is also sending data out through the parameters assigned to the pot.

I.e. the A1 input is picking up data from the sensor plugged in to A5
Logged

0
Offline Offline
Shannon Member
****
Karma: 160
Posts: 10418
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ah, should have noticed the "floating wiper" in your description.  Try placing a capacitor from A1 to ground - then when you stop pitch-bending it will hold the soft pot's output voltage steady.  At the moment its picking up capacitive cross-talk.  Try something like 100nF to start with, increase if that's not enough to cure the problem.
Logged

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

Left Coast, CA (USA)
Online Online
Brattain Member
*****
Karma: 331
Posts: 16490
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Perhaps if you could post links to datasheets for those two sensors we might gain more insite to what might be the problem.

Lefty
Logged

0
Offline Offline
Newbie
*
Karma: 1
Posts: 12
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'll find the datasheets and post them - I have one on my pc at home.

I will try the capacitor, but I'd love to _understand_ what's going on as well as just fixing it. Is the cap idea what they cal a 'decoupling capacitor'? Why do we get the linkage in the first place.

Thanks for everyone's help!
Logged

0
Offline Offline
Shannon Member
****
Karma: 160
Posts: 10418
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'll find the datasheets and post them - I have one on my pc at home.

I will try the capacitor, but I'd love to _understand_ what's going on as well as just fixing it. Is the cap idea what they cal a 'decoupling capacitor'? Why do we get the linkage in the first place.

Thanks for everyone's help!

I would think it of the capacitor as a 'hold' capacitor in a sample-and-hold circuit - if I understand the soft-pot correctly it goes open circuit when not being manipulated, and the capacitor is acting to sample and then hold the wiper voltage.

If an analog input is open circuit it is VERY high impedance which means it will be driven by capacitive coupling from nearby signals (on or off chip).  Modern CMOS IC inputs are impressively high impedance, around 10^12 ohms, so tiny amounts of stray capacitance can act as a 'low impedance' by comparison.  The idea of adding a capacitor is to provide a much more powerful (low impedance) voltage source to drown out the stray capacitances.
Logged

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

0
Offline Offline
Newbie
*
Karma: 1
Posts: 12
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok, i went and picked up a 0.1u cap, and when i got home i could not duplicate the problem. I wonder if it is only present if the two wires i close enough to induce the current/noise.

I did play with the cap, and noticed that it created a slight amount of lag in the response to the pot - is that because it is filtering the low frequency change of voltage caused by moving the pot?

What it did not seem to do was 'hold' the value of the pot when the wiper was lifted if i had it connected from A1 to ground.

does that make sense?

Thanks for your input - i am learning!
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 508
Posts: 31355
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
What it did not seem to do was 'hold' the value of the pot when the wiper was lifted if i had it connected from A1 to ground.
does that make sense?
Yes it does, it should not hold the voltage why should it. You actually need a pull down resistor here about 100K not a capacitor. Then because even 100K is too big read each sensor twice and use the second reading and disregard the first. This is due to the input capacitor inside the arduino not having time to charge (or discharge) with 100K. The optimal input impedance is 10K, but using that value will spoil your soft pot linearity.
Logged

0
Offline Offline
Newbie
*
Karma: 1
Posts: 12
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, I've actually got a 120kohm pulldown resistor there.

I noticed that the lower values effect the linearity more, but that increasing the amount beyond 120k doesn't mitigate the non-linearity any further. What is actually happening with this effect?

Now you seem to be suggesting that there is a possible negative effect of the high values for the pull down - I am not seeing it, so its academic, but im still interested - what is the role of the input capacitor and what is the effect I might see. As soon as I press the wiper, is that capacitor not going to charge through the softpot side of the circuit?

Thanks for the help
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 508
Posts: 31355
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
What is actually happening with this effect?
It is the fact that the bottom leg of the potential divider is not just the whole value minus the top value. But that in parallel with the pull down. When this value is large compared to the pull down it has little effect, but the closer to the pull down value the bottom leg is the more effect it has. When the bottom leg is equal to the pull down then the bottom leg is half the value it should be from the wiper position. Hence the linearity of the pot is not what it should be.

Quote
Now you seem to be suggesting that there is a possible negative effect of the high values for the pull down
Yes it is that the reading of one channel will change when the sensor on the other channel changes. This is because the input capacitor on the A/D has not got time to charge up (or down) to the input level when the multiplexer is switched to it. This will change depending on the voltage on the original channel. You are suffering the effect but maybe you haven't noticed it yet.

Quote
what is the role of the input capacitor
It is for the sample and hold circuit on the front of the A/D.

Logged

Pages: [1]   Go Up
Jump to: