Analog pins stop responding

Hey there,

I'm using an arduino MEGA R3 with a sparkfun SD shield and an Adafruit protoshield.

I noticed this happening on one of my boards and I'd like to document it/ get some ideas on what it could be.

When I first plug in the setup and run a program that outputs the analog values to the serial monitor, I get what is expected, ie the value I'm putting at them, be it 0 for ground, 1023 fro 5v, or an intermediate from a potentiometer. However, If I unplug the arduino without closing the monitor then go through the standard method for fixing this (hold down reset as you plug the board back in), some of the analog pins stop responding. They will just keep the same value (usually around 300) regardless of what voltage I show it.

Any Ideas?

Thanks

edr2694:
then go through the standard method for fixing this (hold down reset as you plug the board back in)

Standard method? This method doesn't fix anything related to what you've stated.

If you unplug the board while the serial monitor is still open, close the serial monitor before plugging the board back in.

edr2694:
some of the analog pins stop responding.

There is only one ADC in a ATmega328. Each of the Analog Pins is connected to a multiplexer that connected to the single ADC. So if some pins "work" and some don't, it is something with the front-end hardware, not the ADC itself.

What are the pins connected to? Are they connected to the Arduino's own 5V or some external source?

I use this to get the board to respond to to the IDE, that is to say, I can upload and/ or re-open the serial monitor. I remember reading about it on here a few years ago actually. I admit it may very well be a terrible idea, I just don't know enough about the underlying system.

In application I'm using the analog pins as voltmeters, with carefully chosen resistors leading from a node I want to measure to the analog pin, and then to ground (10K from point, 1K to ground.) These values were chosen such that the current flowing along the path is minimal.

Could you post the schematic of how you connected everything? Doesn't have to be fancy, just a sketch 'll do.

And just for fun, perhaps sharing your code. A problem is always in the last place you check...

^link to schematic

The power supply side never goes above 10V, but even so, the resistive network was chosen so that it would only surpass 5V when the power supply was at 50V.

As for code, I'm literally just reading the values of the analog pins and writing them to serial so I can look at them.

edr2694:
I use this to get the board to respond to to the IDE

Holding the reset button on a Uno has no effect on the USB to Serial chip. The hold-down reset procedure is for holding the ATmega at its boot loader until avrdude on the PC starts sending data. It is not for telling an application on the PC to let go of its lock on the serial port.

edr2694:
In application I'm using the analog pins as voltmeters

Ideally, you shouldn't allow voltage on the ATmega's pins when it doesn't have VCC. You might be seeing some kind of latch-up behavior due to the I/O pins being "back-powered."

An interesting test might be to throw a transistor in your measurement circuit to effective disconnect the I/O pin from the voltage divider.

You could also disconnect your analogPin connections before re-attaching USB to see if the "stuck" behavior goes away.

Ok, so that explains what happens on the chip. I guess I didn't explain that very well, I knew the reset did nothing on the computer's end.

I'm not entirely sure how the analog pins could be "back powering" anything, as they aren't being told to output. I'm not sure how a Vcc would make a difference unless a voltage greater than it was input, but that's another can of worms. The ground plane is the same, so the values at the pin should be no different than what it would be from any other analog sensor.

FWIW, I adapted this from here:
https://blog.udemy.com/arduino-voltmeter/

I'll have to give this a shot tomorrow and see if it makes a difference.

Closing thought to this comment:
It's weird that I only ever saw this behavior on one of the two MEGA's I have with the exact same setup.

edr2694:
I'm not entirely sure how the analog pins could be "back powering" anything

Back-powering is when current finds a path through the protection diodes on the pins to the ATmega's VCC and effectively allows the chip to be powered even though now voltage is present at the VCC pin(s).

It is most common when people are using the analog pins to measure the voltage of a battery. In most cases the battery is separate from the supply used to power the ATmega / Arduino board. Since the grounds are connected together, there is a path for current to sneak through the ATmega chip when the chip's supply is removed.

The result is strange behavior like the chip being powered even though VCC is removed, strange start-up behavior and strange latching behaviors. Analog readings of 300 are pretty close to 1.4V, which is awfully close to two diode drops...

Sound familiar?

edr2694:
I'm not sure how a Vcc would make a difference unless a voltage greater than it was input

When VCC is removed, you're changing the entire circuit. In this case, the bias on the protection diodes change.

edr2694:
The ground plane is the same, so the values at the pin should be no different than what it would be from any other analog sensor.

Sensors don't provide (relatively) large amount of current. If the sensors are powered by the same VCC as the ATmega, they don't really do much of anything when it's VCC is removed.

Voltage dividers connected to batteries do, however, have a nice supply of current available.

edr2694:
It's weird that I only ever saw this behavior on one of the two MEGA's I have with the exact same setup.

Manufacturing differences in the chips will lead to slightly different behaviors. Things like the pull-up resistors and protection diodes don't have tight tolerances. This leads to slightly different behaviors, which are technically still within spec (by not being tightly specified).

Ok, I've played around with it a bit this morning and here's what I can report:

I plugged in the arduino to my PC and uploaded the test program. Nothing was connected, save for the shields. Starting with analog pin 0 and working my way up, I grounded each pin to check its response. Pins 0-2 responded fine, but pin 3 held its value of around 282/283. The value did change when the pins next to it were driven low, just like every pin does (each pin maintains its individual value if connected to something and isn't left floating.)

Do I just have a fried protection diode/ resistor? is there any way to fix this besides buying another board?

Edit: I should also mention I'm powering the Arduino with either the USB or a wall adapter barrell jack from Adafruit

I took out a multimeter and measured the voltage drop while the arduino was unplugged. It looks like pin 3 measures open between 5V, whereas the others are reading 1 nominal volt. So yeah...looks like a fried diode. Any way to prevent this while keeping my setup relatively the same?

And now I'm doubting everything because there's a chance it's a loose connection on the shield...ffs

Onion theory: peel off a layer, cry a bit, peel off another layer, cry some more. That's hardware debugging for you.

Final report on what's going on:

Nothing is wrong. It boils down to a loose fitting shield.

As many of you know, the adafruit protoshield's reset pin is opposite the analog inputs. It looks like when I hit the reset button, the shield is being lifted just enough for the pin to lose connection. This is why the problem was intermittent for me...and also why it varied from pin to pin occassionally...and why it never affected the pins closest to the fulcrum or the pins not on the shield. In any case, thank you everyone for the additional information. This will help me a lot on other projects!