XIAO RA4M1 analog A4 and A5 pins unexplained behavior

Hello,

I am having some unexplained behavior attempting to read analog input to the A4 and A5 pins.

The problem began in a large code where I was using A1-A3 for analog input, but could not get the A4 pin to read using “analogRead(A4_SDA)”, but using “analogRead(A5_SCL)” instead worked as expected. All are using potentiometers as the analog source.

Since the code is large, I wanted to isolate the issue into a small code to share here in the forum, and then a whole different problem occurred. I wrote the simple code below. But in this code, A4_SDA does not read on pin A4, but rather from A1. And reading A5_SCL does not read from any pin, but follows the activity on A1.

void setup() {
Serial.begin(9600);
}

void loop() {
  int read1 = analogRead(A4_SDA);
  Serial.print(read1);
  delay(10);
  Serial.print("\t");
  int read2 = analogRead(A5_SCL);
  Serial.println(read2);
  delay(100);
}

To recap, the behavior in my two sketches are treating pins A4 and A5 totally differently. In the large sketch, A4 does not read at all but A5 does. In the small sketch posted above, A4 reads from the A1 pin and A5 follows the behavior of A1. It is as confusing as it sounds.

Am I supposed to configure pins A4 and A5 in a special way in order to use them for analog input? Thank you.

Hi there,
So on most of the pins if you are using a specific LIB then some of the pin functions will be defined and set differently than you think. I always put some code ahead to show the I2C and SPI pins the code thinks is set, the same with the CS or SS pins the system sets with as defaults. Try that and see if which pins you think are the assigned ones.
With the Pin multiplexing that can be done , you probably need to pre define the pins you need.
HTH
GL :slight_smile: PJ :v:

ie.

Serial.println("--------------");
  Serial.println(SS_SPI0);
  Serial.println(MOSI); // master out, slave in
  Serial.println(MISO); // master in, slave out
  Serial.println(SCK);  // clock
 Serial.println("--------------");

do same thing with I2c pins. :+1:

Hello,

Thanks for your response. I realized also that the “A4” pin is marked as analog, but it isn’t an ADC pin. It seems to be analog PWM only. I have just noticed the light blue ADC labels on the pins in the pinout image.

1 Like