ResponsiveAnalogRead Library

Status
Not open for further replies.

donkeyahoy

Well-known member
Hi. I would like to share this really great library and also need some help with software problems. It is called ResponsiveAnalogRead and is used for eliminating noise in analogRead inputs without decreasing responsiveness. The theory and formulas look really impressive and would work great for eliminating noise in potentiometer reading and also filtering out that last place number jitter that always happens. Here it is :

https://github.com/dxinteractive/ResponsiveAnalogRead#analog-resolution
http://damienclarke.me/code/posts/writing-a-better-noise-reducing-analogread

I am having some code trouble though. If you are interested, let me know if you can get it to work correctly. I'm using a Teensy 3.1 with IDE Arduino 1.6.11 Teensyduino 1.30. 10k potentiometer hooked up to the 3.3V and AGND with center wiper into pin A4.

My problems are :

1) Serial.print(analog.getRawValue()); always prints 0
2) Serial.print(analog.getValue()); only prints values of 1 to 1022. I would like it to be 0 to 1023.
3) I can't get it to operate at higher bits than 10. analog.setAnalogResolution(12); only prints getValue() of 1 to 11.

Let me know if you experience the same problems. This library looks promising. Thanks!

PHP:
// include the ResponsiveAnalogRead library
#include <ResponsiveAnalogRead.h>

// define the pin you want to use
const int ANALOG_PIN = A4;

// make a ResponsiveAnalogRead object, pass in the pin, and either true or false depending on if you want sleep enabled
// enabling sleep will cause values to take less time to stop changing and potentially stop changing more abruptly,
// where as disabling sleep will cause values to ease into their correct position smoothly and with slightly greater accuracy
ResponsiveAnalogRead analog(ANALOG_PIN, true);

// the next optional argument is snapMultiplier, which is set to 0.01 by default
// you can pass it a value from 0 to 1 that controls the amount of easing
// increase this to lessen the amount of easing (such as 0.1) and make the responsive values more responsive
// but doing so may cause more noise to seep through if sleep is not enabled

void setup() {
  // begin serial so we can see analog read values through the serial monitor
  Serial.begin(9600);
}

void loop() {
  // update the ResponsiveAnalogRead object every loop
  analog.update();

  Serial.print(analog.getRawValue());
  Serial.print("\t");
  Serial.print(analog.getValue());

  // if the repsonsive value has change, print out 'changed'
  if(analog.hasChanged()) {
    Serial.print("\tchanged");
  }

  Serial.println("");
  delay(20);
}
 
Problem #3 update : Serial.print(analog.getValue()); now prints values 1 to 4094

just add these lines to code :

analogReadResolution(12);
analog.enableEdgeSnap();
analog.setAnalogResolution(4096);


That edge snap doesn't seem to be working. The values should print 0 to 4095. Raw value is still printing all 0s. Hmm...
 
Really impressed with the stability though! Rock solid 12 bits from a potentiometer. Higher bits are really not needed because you can't even turn that many fine steps with your hand physically.
 
Raw value is still printing all 0s. Hmm...

on the github site there is already an issue filed about rawValue, and suggested fix.

i think keywords.txt is informational. enableEdgeSnap() is defined in the .h

i think you have to also enableSleep() for edgesnap to work (just looking at the code)

i don't see that library actually calls analogReadResolution() to change the ADC, so it will just be using 10 bits ....
maybe in your sketch you can call analogReadResolution() and then tell the library the resolution with setAnalogResolution()
EDIT: which is what you did in post#2
 
Last edited:
I'm going to bring this library into the 1.32 installer. Looks like it could *really* help many people build MIDI controllers.
 
on the github site there is already an issue filed about rawValue, and suggested fix.

i think keywords.txt is informational. enableEdgeSnap() is defined in the .h

i think you have to also enableSleep() for edgesnap to work (just looking at the code)

i don't see that library actually calls analogReadResolution() to change the ADC, so it will just be using 10 bits ....
maybe in your sketch you can call analogReadResolution() and then tell the library the resolution with setAnalogResolution()
EDIT: which is what you did in post#2

Looked at the rawValue fix. It said not tested and was written by someone else besides the original author, so I'm a little wary using it. Not really needed I guess. I just won't use it.

Yep, keyword.txt just makes the keywords orange when writing the code. Not needed either. Just read about keyword files.

I had to manually set it to 12 bits, but it does work! Yes!

Still not having any luck with the edge snap. The code does now have the sleep enable both times. Once in the original ResponsiveAnalogRead and then again with the enableEdgeSnap(). Hmmm. Maybe my pot is not going close enough to 0V and 3.3V. 12 bits is a very small volt amount. Wish there was a edge snap amount to set.

Thanks for the help!!
 
I'm going to bring this library into the 1.32 installer. Looks like it could *really* help many people build MIDI controllers.

Good idea! Ya, I'm working with control voltage analog synthesizers and this library is really helping a lot. Glad I could contribute and not just ask questions for once. :p
 
Looked at the rawValue fix. It said not tested and was written by someone else besides the original author, so I'm a little wary using it. Not really needed I guess. I just won't use it.

The fix only adds one line to save the rawValue, and I tried it and it works. rawValues are printed out in the example.
 
The fix only adds one line to save the rawValue, and I tried it and it works. rawValues are printed out in the example.

Cool. Mine is updated now too. Working great! Thanks for testing.

Forgot to mention I'm using a 100nF cap from the input pin to AGND, if anyone else is trying this.

Have a good night.
 
The fix only adds one line to save the rawValue, and I tried it and it works. rawValues are printed out in the example.

Having some new trouble. Could someone try this out? I'm trying to read two pots at the same time with two objects from this library.

The AnalogCVpot object will flip out sometimes if it is getting readings somewhere in the range of 1970-2000. If I delete all the second object code it works fine with one object.

Any ideas?

PHP:
// include the ResponsiveAnalogRead library
#include <ResponsiveAnalogRead.h>

// define the pin you want to use

const int CV_POT_PIN = 18;
const int CV_JACK_PIN = 16;

// make a ResponsiveAnalogRead object, pass in the pin, and either true or false depending on if you want sleep enabled
// enabling sleep will cause values to take less time to stop changing and potentially stop changing more abruptly,
//   where as disabling sleep will cause values to ease into their correct position smoothly and more accurately

ResponsiveAnalogRead AnalogCVpot(CV_POT_PIN, true, 0.01);
ResponsiveAnalogRead AnalogCVjack(CV_JACK_PIN, true, 0.01);

// the next optional argument is snapMultiplier, which is set to 0.01 by default
// you can pass it a value from 0 to 1 that controls the amount of easing
// increase this to lessen the amount of easing (such as 0.1) and make the responsive values more responsive
// but doing so may cause more noise to seep through if sleep is not enabled

void setup() {
  // begin serial so we can see analog read values through the serial monitor
  Serial.begin(9600);

  analogReadResolution(12);
  
  AnalogCVpot.enableSleep();
  AnalogCVpot.enableEdgeSnap();
  AnalogCVpot.setAnalogResolution(4096);

  AnalogCVjack.enableSleep();
  AnalogCVjack.enableEdgeSnap();
  AnalogCVjack.setAnalogResolution(4096);
  
}

void loop() {
 
  // update the ResponsiveAnalogRead object every loop  
  
  AnalogCVpot.update();  

  Serial.print(AnalogCVpot.getValue());
  Serial.print("\t");
  
  // if the responsive value has change, print out 'changed'
  if(AnalogCVpot.hasChanged()) {
    Serial.print("\tchanged\t");
  }
  else {
    Serial.print("\t\t");
  }

  // jack section

  AnalogCVjack.update();  

  Serial.print(AnalogCVjack.getValue());
  Serial.print("\t");
  
  // if the responsive value has change, print out 'changed'
  if(AnalogCVjack.hasChanged()) {
    Serial.print("\tchanged");
  }
  else {
    Serial.print("\t");
  }
  
  Serial.println("");  
  
  delay(20);
}
 
I tried one pot with this library and one pot with the standard analogRead. I even tried putting a large delay between them. Is there some issue with trying to read multiple pins with the adc?
 
Status
Not open for further replies.
Back
Top