Problem:
ItsyBitsy M0 - AREF pin (42/A12 ) does not support analogRead() function !!!
How to (re)produce the problem:
1) Setting up the AREF pin as input with:
pinMode(A12, INPUT);
2) Read value with:
int i = analogRead(A12); // It returns wrong values !!!
Solution:
In arduino core (samd 1.7.11) code, usually found under
C:\Users\UserName\AppData\Local\Arduino15\packages\adafruit\hardware\samd\1.7.11\variants\itsybitsy_m0 manipulate the following:
1) In file variant.h, after line 102, add a new line:
#define PIN_A12 (PIN_A0 + 12);
2) In file variant.h, after line 117, add a new line:
static const uint8_t A12 = PIN_A12;
3) In file variant.cpp, change the line 103
from:
{ PORTA, 3, PIO_ANALOG, PIN_ATTR_ANALOG, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // DAC/VREFP
to:
{ PORTA, 3, PIO_ANALOG, PIN_ATTR_ANALOG, ADC_Channel1, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE },// ADC/AIN[1]/DAC/VREFP
4) Recompile your code...
NOTE: In next update/upgrade of the core (samd x.x.x) the above patches will be lost...
ItsyBitsy M0 - AREF pin (42/A12 ) does not support analogRead() function
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- iskaz
- Posts: 1
- Joined: Wed Feb 01, 2023 11:40 am
- blnkjns
- Posts: 963
- Joined: Fri Oct 02, 2020 3:33 am
Re: ItsyBitsy M0 - AREF pin (42/A12 ) does not support analogRead() function
It feels weird to use a AREF pin as input, as it is usually the reference for the analog input pins. So you feed it with the voltage you want the analog pins to reference to.
- westfw
- Posts: 2008
- Joined: Fri Apr 27, 2007 1:01 pm
Re: ItsyBitsy M0 - AREF pin (42/A12 ) does not support analogRead() function
The problem is that the data structure used by Arduino to do the pin mapping and mode changes isn't really well designed WRT pins that have multiple functions (which is pretty much "all of them" in newer chips.)
Please be positive and constructive with your questions and comments.