KurtE
Senior Member+
@frankzappa - What you are doing sounds good. My main suggestion, is when you are starting out, for me the best thing is to try small bits and pieces, and most importantly have fun!
Again if I know I want to read in the 10 ADCs is to do simple experiments... Even before you decide to use ADC library... You can try different things with the Arduino built in ADC functions.
The simplest is something like:
And it is printing out 173 the majority of time...
You can then extend it... And see what setting the Resolution and the number of averaging does to this.
Again nothing special here
Example output:
as you can see the setting for number of bits of resolution and how many times the analogs are averaged makes a big difference on speed.
So then you need to decide how important is each of these to your usage?
You can then go to the ADC library and see that it has similar settings. Actually even more settings, that you can try. And then as I mentioned you can the work to use both ADCs...
In the above code all of these reads use a single ADC...
Again the goal is to have fun!
Again if I know I want to read in the 10 ADCs is to do simple experiments... Even before you decide to use ADC library... You can try different things with the Arduino built in ADC functions.
The simplest is something like:
Code:
const uint8_t adc_pins[] = {A0, A1, A2, A3, A4, A5, A6, A7, A8, A9};
void setup()
{
while (!Serial && millis < 4000) ;
Serial.begin(9600);
}
void loop()
{
elapsedMicros em = 0;
uint32_t sensorValue[10];
for (int i = 0; i < sizeof(adc_pins); i++)
{
sensorValue[i] = analogRead(adc_pins[i]);
}
Serial.println(em, DEC);
delay(1000);
}
And it is printing out 173 the majority of time...
You can then extend it... And see what setting the Resolution and the number of averaging does to this.
Again nothing special here
Code:
const uint8_t adc_pins[] = {A0, A1, A2, A3, A4, A5, A6, A7, A8, A9};
void setup()
{
while (!Serial && millis < 4000) ;
Serial.begin(9600);
}
void loop()
{
elapsedMicros em = 0;
uint32_t sensorValue[10];
for (int anal_res = 8; anal_res < 14; anal_res += 2) {
analogReadRes(anal_res);
for (int anal_avg = 2; anal_avg < 64; anal_avg *= 2) {
analogReadAveraging(anal_avg);
em = 0;
for (int i = 0; i < sizeof(adc_pins); i++)
{
sensorValue[i] = analogRead(adc_pins[i]);
}
Serial.printf("(%d:%d)=%u ", anal_res, anal_avg, (uint32_t)em);
Serial.flush(); // make sure not to influence the next run
delay(5);
}
}
Serial.printf("\n");
delay(1000);
}
Code:
(8:2)=32 (8:4)=109 (8:8)=214 (8:16)=423 (8:32)=842 (10:2)=48 (10:4)=174 (10:8)=343 (10:16)=681 (10:32)=1358 (12:2)=56 (12:4)=206 (12:8)=407 (12:16)=810 (12:32)=1615
(8:2)=32 (8:4)=110 (8:8)=214 (8:16)=423 (8:32)=842 (10:2)=48 (10:4)=174 (10:8)=343 (10:16)=681 (10:32)=1357 (12:2)=56 (12:4)=206 (12:8)=407 (12:16)=810 (12:32)=1615
(8:2)=32 (8:4)=109 (8:8)=214 (8:16)=423 (8:32)=842 (10:2)=48 (10:4)=174 (10:8)=343 (10:16)=681 (10:32)=1357 (12:2)=56 (12:4)=206 (12:8)=407 (12:16)=810 (12:32)=1615
(8:2)=32 (8:4)=109 (8:8)=214 (8:16)=423 (8:32)=842 (10:2)=48 (10:4)=174 (10:8)=343 (10:16)=681 (10:32)=1356 (12:2)=56 (12:4)=206 (12:8)=407 (12:16)=810 (12:32)=1615
(8:2)=32 (8:4)=110 (8:8)=214 (8:16)=423 (8:32)=842 (10:2)=48 (10:4)=174 (10:8)=343 (10:16)=681 (10:32)=1357 (12:2)=56 (12:4)=206 (12:8)=407 (12:16)=810 (12:32)=1615
(8:2)=32 (8:4)=109 (8:8)=214 (8:16)=423 (8:32)=842 (10:2)=48 (10:4)=174 (10:8)=343 (10:16)=681 (10:32)=1357 (12:2)=56 (12:4)=206 (12:8)=407 (12:16)=810 (12:32)=1615
(8:2)=32 (8:4)=110 (8:8)=214 (8:16)=423 (8:32)=842 (10:2)=48 (10:4)=174 (10:8)=343 (10:16)=681 (10:32)=1357 (12:2)=56 (12:4)=206 (12:8)=407 (12:16)=810 (12:32)=1615
(8:2)=32 (8:4)=110 (8:8)=214 (8:16)=423 (8:32)=842 (10:2)=48 (10:4)=174 (10:8)=343 (10:16)=681 (10:32)=1357 (12:2)=56 (12:4)=206 (12:8)=407 (12:16)=810 (12:32)=1615
So then you need to decide how important is each of these to your usage?
You can then go to the ADC library and see that it has similar settings. Actually even more settings, that you can try. And then as I mentioned you can the work to use both ADCs...
In the above code all of these reads use a single ADC...
Again the goal is to have fun!