LowPowerLab Forum

Hardware support => Moteino => Topic started by: alonzo on December 03, 2017, 03:01:24 PM

Title: how to use analog inputs A0-A5?
Post by: alonzo on December 03, 2017, 03:01:24 PM
I'm trying to read battery voltage through a voltage divider on a motino but have had no success using pins A0-A5.
I can use A6,A7 with no problem but connecting my divider to A0-A5 just pulls the input to near ground.
It doesn't make any difference whether I set the pin to INPUT or not.
However, connecting A0, etc. to 3.3V gives ~1023, as I would expect.

Connecting my divider to A0-A5 on a  Arduino Pro Mini  works fine,
I need to be able to read at least 3 analog inputs on this project but seem to only have 2 pins that work for me.

What am I missing here?

Thanks for any help you can give.

-- alonzo
Title: Re: how to use analog inputs A0-A5?
Post by: TomWS on December 03, 2017, 05:03:02 PM
Quote from: alonzo on December 03, 2017, 03:01:24 PM
What am I missing here?
What we're missing is your code so we might determine what you're missing.
See: https://www.arduino.cc/reference/en/language/functions/analog-io/analogread/

Tom
Title: Re: how to use analog inputs A0-A5? {SOLVED]
Post by: alonzo on December 03, 2017, 10:29:08 PM
Thanks, Tom --
  Problem solved -- Operator Error (actually, operator is an idiot.)
As I was putting my code together to post here I noticed this in the boilerplate that I had copied from some of the example motino code:

for (uint8_t i=0; i<=A5; i++)
  {
    if (i == RF69_SPI_CS) continue;
    if (i == FLASH_SS) continue;
    pinMode(i, OUTPUT);
    digitalWrite(i, LOW);
  }


This was being executed -after- I was calling  pinMode(A0, INPUT);

After I cut that out things started working as I had expected.
Now, I need to go back to the example code and see what that code was in there for.

Sorry for the wasted bandwidth and
Thanks for your input.
-- alonzo
Title: Re: how to use analog inputs A0-A5?
Post by: TomWS on December 04, 2017, 09:03:14 AM
No problem, glad you found it.

I suspect that the code in question is an attempt to make sure all unused pins are configured and not floating to save power.  However, there are better ways to deal with this in a system with known pin functions.

Tom