Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

analogRead(A9) 255 #128

Closed
yourSpace24 opened this issue Sep 7, 2021 · 3 comments
Closed

analogRead(A9) 255 #128

yourSpace24 opened this issue Sep 7, 2021 · 3 comments

Comments

@yourSpace24
Copy link

Hi,

when i read the ADC value from Analog pin: A9 - (PF3 on a TQFP32 Atmega4808 pin23) i always get 255 even when nothing is connected.

If it is floating or put to ground always 255. All the other ADC pins working fine tested it on multiple cpus.

does someone have an idea ? I use the latest MegaCoreX 1.0.9 on Arduino.

cheers

Michael

@SpenceKonde
Copy link
Contributor

does it reproduce when PF3 is grounded (through a resistor, something in the 100-1000 range should be good)? If yes, do you confirm that ~0v is measured on the pin through an external device?

The fact that 255 is the number makes me suspicious that a -1 might be getting treated as a signed byte somew2here along the line.

A pin connected to nothing should never be used as a test of behavior except under very rare use cases - literally any value could be measured for it's voltage without violating any reasonable assumptions, providedd that value was between ground and the supply voltage.

@MCUdude
Copy link
Owner

MCUdude commented Sep 7, 2021

Thanks for reporting! I'm able to reproduce the issue.

int analogRead(uint8_t pin)
{
pin = digitalPinToAnalogInput(pin);
if (pin > NUM_ANALOG_INPUTS)
return NOT_A_PIN;

The problem is that digitalPinToAnalogInput returns the analog pin channel not the analog pin number. For 32-pin parts, you only have 12 analog pins, but the highest analog channel number is 15. This is also an issue for the Nano 4808 pinout as well. A9 isn't the only pin that's not working; A10 and A11 are also affected.

I'll fix it right away, but there won't be a new boards manager release just yet. There are some library improvements I'd like to finish first. Meanwhile, you can replace NUM_ANALOG_INPUTS on line 57 with 15 instead.

MCUdude added a commit that referenced this issue Sep 7, 2021
@MCUdude MCUdude closed this as completed in 1337691 Sep 7, 2021
@yourSpace24
Copy link
Author

Hi Hans,

perfect it works. Thanks so much for the quick fix.

cheers
Michael

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants