If I understand correctly you have an instrument that you use to measure the diameter of tubes ( sort of caliper, for small tubes or big caliper for big tubes ).
This 'instrument' ( I imagine ) is digital ( so you read the measured value ) and it has an analog output 0-1V range ( that converts the measured value in analog value ).
You want to save these values to an excel database, and you want that these saved values are exactly the same as those read in your 'instrument'.
If this is correct the problem I see is that this double conversion ( from digital to analog in your 'instrument' and from analog to digital in arduino ) is not easy to do if we are talking of millivolts, and it is not the best way of doing it ( best way is not doing any analog conversion, is staying digital ).
Having said that if this is the only way to do it ( or the way you want to do it ) I'd say:
you need an a/d with greather resolution than 1mV / bit ( you could also try with oversampling/averaging, but it should be done 'the proper way' ) and reasonable caracteristics
you need to calibrate this a/d ( the internal of arduino, or the external with higher precision ), so that it maches with your 'instrument' output
how to do this calibration? It could be a simple 'two point' calibration ( if both 'instrument' and a/d are linear enough ) or a more complex one ( using more points ) to correct non linearities
yes, that seems to be an accurate summation. I'm not particularly set in how i need to go about this, but using an Arduino or raspberry pi to read the analog data seemed by far the simplest and cheapest solution, and made use of parts I already had. The double conversion definitely seems to be an issue. I have some raspberry pi picos that i tried using with a very similar setup, despite the higher resolution of the pico, which should be enough, I'm running into the same issue as the arduino uno where the value is off by 1 or 2 mV but it isn't consistent, so i can't just add/subtract a flat value. (this is after the correction of the 255 offset that pico apparently has for analog read)
definitely thought this was gonna be simpler than it turned out to be. So if you other suggestions on alternatives or how to make better use of the arduino or pico I would definitely appreciate it.
I think of it as representing the 1024 binned intervals by the value at the center of their intervals, rather than by the minimums of their intervals.
If you think of it that way, the common /1023 scheme represents the 0th bin by the value of the bottom of the 0th interval, and the 1024th interval by the value of the top of the 1024th interval, with the bias within the intervals slowly shifting across the 0-1023 range.
For the Arduino's ADC, Nick's whole page is worthwhile reading.
Here's the micro python code I used for the pico. there was an issue with consistency from the pico, so I am currently averaging 500 values, but have been able to run the code with 5000 samples per cycle and still have the code outputing at the desired frequency. from my testing it seemed that lower frequencies required a higher correction. (eg read voltage = 0.254, correction = 315; read voltage 0.623, correction = 280) these values were not always consistent, but were required even after the variability had been smoothed out by the averaging. I tried to create a linear function to have a variable correction value, but it didn't seem to be linear and there might be a better way than spending a ton of time creating a custom function using a ton of data points
#import from the raspberry pi, classes: Pin, ADC, and Timer
from machine import Pin, ADC, Timer
#sets the analog pin to read from
adc = ADC(Pin(27))
#creates a instance of the timer class called timer
timer = Timer()
#conversion factor, used to change from the integer value back to the measured value
conFac = 3.254/65535
def getData(timer):
val = 0
#reads data from the analog pin 10 times and adds averages it
for i in range(500) :
val += adc.read_u16()
val = (val/500)
#creates a correction value that is related to the measured value
correction = 255
val = val - correction
#ensures no negative values are recorded
if val < 0:
val = 0
#convertes from the integer value reading to the measurement
volt = (val * conFac)
#prints out the measurement rounded to 3 digits
print(round(volt,3))
#creates a periodic action that calls the function "getData" 4 times each second
timer.init(freq=4, mode=Timer.PERIODIC, callback=getData)
Ok, as I said you need at least a 'two point' calibration ( an offset is not enough, is a single point calibration, as you noted is never ok ).
A two point calibration is simply the measurement at 2 different points ( let's say 1/3 and 2/3 of the span ), you save those measurements and use to correct all other mesurements.
If both systems ( the instrument and the a/d ) are linear this is enough.
If one or both are 'not so linear' you need a calibration on more then 2 points ( 3,4... ), then for every measurement you take you correct the reading using the two nearest calibration points and you are done.
If you ever used a resistive touch screen you should remember the 'touch calibration routine' it had a small dropdown box with: '5 points', '9 ponts', '16 points' and '25 points' ( yes we had also the 25 point touchscreen calibration... but never tried prefer wasting time with solitaire ; - ), this is similar a higher number of points to correct higher grade of nonlinearity
Also as noted by others starting with a higher resolution adc could be a good idea ( also having analog separed from digital is good in terms of noise ), never used these but seems using a decent adc from texas so why not ( at a bargain price )
You could try your initial idea of amplifying the signal with an opamp. But a much better and easier solution would be to use an external ADC like the ADS1115 board:
It even has a Programmable Gain Amplifier, so it can amplify the signal before sampling. That together with the theoretical 16 bits, should be more than enough for what you need, I suppose.
That is possible, but maybe not so straight forward. The opamp should be rail to rail and make sure that it goes down to zero or below, small error, etc. Otherwise you loose some millivolts here and there. So, no old common jellybeans.
If it was my project I'd probably use an ADS1015 12-Bit ADC like this one from Adafruit. Use its PGA in an auto-ranging scheme to get the resolution at the low voltage you are interested in.
In your Pico experiment, try a >> 4 of the 16-bit readings to get them down to the actual 12-bit resolution of the ADC and see what that does for your repeatability.
Better ADC(ADS1115), with PGA, suggested in post #12 or thereabouts; perhaps OP wasn't yet 'ready' for a better idea.
With builtin reference and gain as needed, the OP should be well ahead by now.
Out.
Every voltmeter I’ve built I’ve also included a calibration routine .
You also need to be careful with your maths as that can introduce rounding errors .
Print out the raw A/D 1024 values verses voltage and put in a spreadsheet that will show linearity , offset and what the true value of the reference voltage .
That will be the best result and you can see if your maths causes a problem.
You can fit a calibration routine around the map function
Beware if your connections ( common grounds etc ) as you can introduce volt drops into your measurable.
Remember you are dealing with a $3 voltmeter here and the accuracy of your reference voltmeter needs to be checked ( it will have an error band too )
Apologies if this repeats ( re enforces?) comments already made
Asking for 1 mV accuracy on a 10 bit ADC with a 1.1V range is a complete and utter waste of time, IMO. It's about time the OP returned and told us the present state of affairs - continuing to pursue the 10-bit solution, or integrating a better ADC, or switching to another Arduino with a better ADC?
As I found an ads1115 board, I tested it comparing with the arduino mega 2560 a/d: no match!
I simulated the analog input with a multiturn pot, but the arduino a/d does not 'stay still' ( had to use 10000 samples to have better results ), the ads1115 is ok, super stable ( used 10 samples )
Atthached the two codes, both contain a two point calibration ( initialized with some values )
Arduino a/d
// Millivolt resolution caliper ( using arduino a/d )
#define IN_PIN A2
#define CAL_POINTS 2
#define NUM_SAMPLES 100
#define VOLT_CONV 0.107421875
unsigned long adVal;
float diam;
float volt;
unsigned long adRaw[CAL_POINTS];
float diamCal[CAL_POINTS];
float mapf(long x, float in_min, float in_max, float out_min, float out_max)
{return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;}
void setup() {
// put your setup code here, to run once:
pinMode(IN_PIN, INPUT);
Serial.begin(115200);
#if defined(__AVR_ATmega2560__)
analogReference(INTERNAL1V1);
#else
analogReference(INTERNAL);
#endif
// set calibration values ( retrieved from eeprom? )
adRaw[0] = 30000;
adRaw[1] = 60000;
diamCal[0] = 200.0;
diamCal[1] = 400.0;
}
void loop() {
// put your main code here, to run repeatedly:
adVal = 0;
for (int i = 0; i < NUM_SAMPLES; i++)
{adVal += analogRead(IN_PIN);}
diam = mapf(adVal,adRaw[0],adRaw[1],diamCal[0],diamCal[1]);
volt = adVal*VOLT_CONV;
volt = volt * (0.01 / NUM_SAMPLES);
Serial.print("adVal: ");
Serial.print(adVal);
Serial.print(" uncalVolt: ");
Serial.print(volt,4);
Serial.print(" diam: ");
Serial.println(diam, 4);
delay(500);
}