Hello everybody,
I want to read all the analog inputs on an Arduino DUE in a row. Upon testing my setup (which had worked great with an Arduino UNO), I saw the program read some weird values. So I used this simple program for a basic test:
int val1;
int val2;
void setup(){
Serial.begin(9600);
while (!Serial);
analogReadResolution(12);
}
void loop(){
Serial.println("0: ");
val1=analogRead(0);
Serial.println(val1);
delay(1000);
Serial.println("1: ");
val2=analogRead(1);
Serial.println(val2);
delay(1000);
}
I connected the 3.3V supply pin to A0 and GND to A1, expecting a readout of 0 for A0 and 4095 for A1. All other pins were unconnected. The result I got was:
0:
0
1:
4095
0:
0
1:
0
0:
0
1:
0
0:
0
1:
0
I played with interchanging the GND and 3.3V connections and discovered that the readout seems to be dominated by one of the pins. (e.g. when plugging the 3.3V into A0 and GND into A1 I would get readings of 4095 and 4094 on both pins.) Also I found similar behaviour for other pin combinations. (e.g. A10 and A11)
I observed this phenomenon on two Arduino DUEs (one of which was right out of the box).
Is this a known behaviour? Am I doing something wrong?
michinyon:
analogRead(0) and analogRead(1) might be meaningless.
You should try your experiment again with the recommended pin identifiers, A0 and A1.
Tried that. Did not change anything. It seems like the Arduino mostly prefers to stick to the input I read out first, however I also randomly observed the opposite.
I thought this might be a problem with the on-board multiplexer being too slow. So I tried reading the same input several times in a row (eg. 3x A0 then 2x A1) with 1s delay between each read operation. Still no change. I am completely at a loss here.
Magician:
Have you made a mistake in connection? 3.3V and 5V dangerously close.
Very strange indeed. Well, unless the pins are labelled wrong, I am pretty sure, I connected them correctly.
I tried again using your code and still get the exact same results as before. Seems like both of my Arduinos are broken.
At least it is good to know, that it is not a programming problem. Thanks for confirming that.