Hello,
In Nick Gammon's post about turning off the ADC, he does it in the setup() routine. I don't know what ADCSRA=0 does, but it seems to save a lot of power. Can you use this command to control ADC on/off in the loop part of the program instead of the setup? Can I turn ADC on and off as needed? What kind of implications does that have? I read that the analog input pins use capacitors to read voltage - do I need to do a ADCSRA=1, delay for 2 seconds, then perform the analog read in order to get accurate readings? Then I want to turn off ADCSRA and sleep the controller.
#include <avr/sleep.h>
void setup ()
{
for (byte i = 0; i <= A5; i++)
{
pinMode (i, OUTPUT); // changed as per below
digitalWrite (i, LOW); // ditto
}
// disable ADC
ADCSRA = 0;
set_sleep_mode (SLEEP_MODE_PWR_DOWN);
sleep_enable();
// turn off brown-out enable in software
MCUCR = bit (BODS) | bit (BODSE);
MCUCR = bit (BODS);
sleep_cpu ();
} // end of setup
void loop () { }
Your code stops at the loop() so ... is it the code?
No wiring diagram etc ... how do you know that 0 is the wrong value? (what is the refernec voltage and the setup thereto?) Try using the Example sketch AnalogInSerialOut to verify your circuit.
No, you need to write the correct value to ADCSRA to enable the ADC and configure it correctly for the mode the Arduino uses. It would be possible to work out what the correct value is either by reviewing the Arduino code which initialises the ADC, or by reading the microprocessor's data sheet.
If you're only doing this to save power, perhaps one of the power management libraries already implements this option; using an existing working solution would be much easier than implementing your own.