A0 works as analog input, but why doesn't A5 seem to?

lcpalm · 3 · 1286

lcpalm

  • Jr. Member
  • **
    • Posts: 6
    • View Profile
Hi,
I'm having trouble and not sure why: Have a circuit set up with a sensor attached to A0, and it reads fine; but if I attach the sensor to A5, it does not report the input.

Here is my code:

---------------------------------

#include <SPI.h>

int readValue1 = 0;
int readValue2 = 0;

// setup for TinyZero
#if defined(ARDUINO_ARCH_SAMD)
  #define SerialInterface SerialUSB
#else
  #define SerialInterface Serial
#endif

void setup() {
  SerialInterface.begin(9600);
  delay(3000);

}

void loop() {

  String dataString = "";

  readValue1 = analogRead(A0);
  readValue2 = analogRead(A5);

  dataString += String(readValue1);
  dataString += ",";
  dataString += String(readValue2);

  SerialInterface.println(dataString);

  delay(1000);

}

----------------------

My circuit is:
 VCC ---> 220ohm ---> IR-emitter ---> GND
VCC ---> 10k ohm ---> A0 [or A5]
                                |--> IR-detector ---> GND

This works as expected when connected to A0: it reports low values when there is IR light striking the IR-detector, and reports high values when the light is blocked. That is, in serial monitor, we get sensor value in A0, and nothing meaningful in A5, as expected:
A0, A5
42,332
43,370
43,367
43,357
361,382 <-- when light blocked
349,373 <-- blocked
340,354 <-- blocked

But when connected to A5, it doesn't report sensor value in A5:
A0, A5
361,382
349,373
340,354
321,372
305,368
that is, here the second column should be low; but it never is.

I'm not sure what is wrong here?

Thank you!


lcpalm

  • Jr. Member
  • **
    • Posts: 6
    • View Profile
For what it's worth... I hooked up the sensor to A2 instead of A5 and it worked fine.
Not sure what is wrong (is A5 not an analog input?) but will go ahead and use A2.



lennevia

  • Administrator
  • Hero Member
  • *****
    • Posts: 236
    • View Profile
Hello there,

A4 and A5 are also the pins used for I2C devices (A4-SDA, A5-SCL), which can normally be used as regular analog pins when no I2C devices are being interfaced, but the TinyZero has the option of an onboard accelerometer that relies on I2C. It is likely you have an accelerometer populated on your board that is interfering with your ability to use pin A5 for regular analog. You can check this with the pictures on the product page that show where the small black chip is: https://tinycircuits.com/collections/processors/products/tinyzero-processor?variant=21137366515796

If you click between the Not Present and Present options, it should be clear where the part is.

Let me know if that seems to be the case!

Thanks,
RĂ©na


 

SMF spam blocked by CleanTalk