analogRead with or without delay?

Hi,
This might be quite a basic question but I don't know the answer so thought of asking. When reading the analog pins should one use a delay inside the loop or can you just skip it? I saw some examples where there is a short delay at the end of the loop so the arduino can recover os something..

Thanks

Reading previous posts I see that analog.read will return the value from the sensor in about 100uS. Putting a delay between analog.reads may be sensible if the device being read does not change very rapidly or if it requires time to react to whatever is being measured.

You can speed up Analog.read by fiddling with the ports directly but accuracy may suffer.

What sort of device do you need to read ?

Most of the time the delay is totally unnecessary. It comes about from a missunderstanding about what is going on.

And, of course, we can't see your code, nor do we have any idea what you are connecting to the analog pin.

Many of those examples are just reading the analog input and printing the result to the serial monitor. In those cases the delay is just there so the information doesn't get blasted to the serial monitor faster than you as a human can read it. Can you imagine trying to catch 10000 data point a second? Another example is when a servo must move or some other such thing should happen so that you can wait until the action has completed before initiating a new action.

If you are just watching for an analog signal to go above or below some threshold like in a while loop then there is no reason for the delay and you can keep reading just as fast as it will let you.

I'm just connecting potentiometers to the pins. For a quick test I tried the standard Firmata cause I wanted to see if my circuit was correct. I'm sending the data to Pd you see and I'm using Arduino as a controller. But I realized that even the standard Firmata uses some short delay cause when I was turning the knobs fast I was getting value changes in discrete steps.
I'm gonna write my own firmware which just reads those values without using Firamta, so thought of asking if I should use a delay since a library that's being used so much like the Firmata does use a delay.

Thanks for your answers

A delay in loop() between calls to analogRead doesn't really help unless you are re-reading the same input. What does help a great deal is to insert a delay inside the analogRead code, between setting the multiplexer to the desired input channel and starting the conversion. A delay of 10us here allows use of inputs with up to 100kohms source resistance without loss of precision, and a delay of 100us works for up to 1Mohm (but expect some loss of accuracy in this case, since the ADC has a typical input resistance of 100Mohms). Adding a delay here is much more effective than the usual remedy of repeating the analogRead() call and discarding the first reading.

dc42:
What does help a great deal is to insert a delay inside the analogRead code, between setting the multiplexer to the desired input channel and starting the conversion. A delay of 10us here allows use of inputs with up to 100kohms source resistance without loss of precision, and a delay of 100us works for up to 1Mohm (but expect some loss of accuracy in this case, since the ADC has a typical input resistance of 100Mohms). Adding a delay here is much more effective than the usual remedy of repeating the analogRead() call and discarding the first reading.

dc42,
Do you mean then to modify the analogRead( ) function itself?
[ If so - How? ]

You could go into the Arduino core and alter it, but probably better to leave that one alone and just write your own function to use.

OK, I guess, so why not drop the other shoe, mate?

In file C:\Arduino-1.04\hardware\arduino\cores\arduino\wiring_analog.c at line 72 is the following:

// without a delay, we seem to read from the wrong channel
//delay(1);

I usually put a delayMicroseconds(10) call at that point.

Any idea where could that be on a mac?

alexandros301:
Any idea where could that be on a mac?

Same place.
Control click on the arduino app and chose show packet contents, then it is
Contents\Resources\Java\hardware\arduino\cores\arduino\wiring_analog.c