serial object not outputting complete range of potentiometer-arduino

n871's icon

I have a potentiometer connected to an external 16bit ADC attached to an arduino due.
Although I'm using single ended inputs I should get at least 32768 values (15bit),
for some reason I'm only getting around 17600. Anyway I have a problem which is far more urgent than this one:

Max Patch
Copy patch and select New From Clipboard in Max.

My maxpatch works well for values 0-999, from 1000 on it's outputting wrong values. In the serial monitor
of the arduino software everything is just working fine. Below my max patch and arduino code.

#include
#include

Adafruit_ADS1115 ads1115;

void setup(void)
{
Serial.begin(9600);
Serial.println("Hello!");

Serial.println("Getting single-ended readings from AIN0..3");
Serial.println("ADC Range: +/- 6.144V (1 bit = 188uV)");
ads1115.begin();
}

void loop(void)
{
int16_t adc0;

adc0 = ads1115.readADC_SingleEnded(0);

Serial.print(" "); Serial.println(adc0);
Serial.println(" ");

delay(10);
}

brendan mccloskey's icon

Hi
does it still give unexpected values beyond 999 if you change the penultimate two lines to just:

Serial.println(adc0);

Max Patch
Copy patch and select New From Clipboard in Max.

and replace [select 10 13] with [select 13 10] in your Max patch? I'm not familiar with the Adafruit library, so this is just guesswork atm.

Brendan

n871's icon

Hello Brendan,

what else to do than thank you for being the pro you are :)
this works great!

May I ask if you have a clue why I'm getting 'only' 17650 values instead of 32768?
I'd like to use differential connections for the adc as explained here: https://learn.adafruit.com/adafruit-4-channel-adc-breakouts/signal-connections

Apparently this would give true 16bit output and less noise.
but I don't understand how to hook up my potentiometer...

n871's icon

some additional info: I'm using 3.3V on the arduino due, when I put the jumper cable in 5V I do get more values (around 26.000) but less stability.

The arduino sketch says the range of the ADC =6.144V (1bit=188uV)
I changed these values to 3.3V (1bit = 101uV) but it changed nothing, the maximum value is still 17651.

brendan mccloskey's icon

Sorry N871, this is where we expose my skill-ceiling I'm afraid. I'm only familiar with 'native' 10-bit adc on the Arduino. I must investigate the Due, just to see what difference the 12-bit adc makes . . .

17600 suggests slightly more than 14-bit.

I grabbed this off the Arduino Due page, which you've already seen obviously:

"Analog Inputs: pins from A0 to A11
The Due has 12 analog inputs, each of which can provide 12 bits of resolution (i.e. 4096 different values). By default, the resolution of the readings is set at 10 bits, for compatibility with other Arduino boards. It is possible to change the resolution of the ADC with analogReadResolution(). The Due’s analog inputs pins measure from ground to a maximum value of 3.3V. Applying more than 3.3V on the Due’s pins will damage the SAM3X chip. The analogReference() function is ignored on the Due".

Maybe you could enlighten me?

Brendan