Hi,
I'm new to arduino and this is the first time I use my Due board.
The problem is that no matter I build a breadboard circuit when I analogRead Ak pins the function always returns the value on the pin with lower index, id est, if I connect A1 and A5 it is
analogRead(A5) = analogRead(A1)
any suggestion?
Yes I am also getting erroneous values.
No code. No schematic. Hard to help when we are blind.
int val1,val2;
void setup()
{
Serial.begin(9600);
}
void loop()
{
val1 = analogRead(0);
val2 = analogRead(1);
delay(200);
Serial.print("A0 = ");
Serial.print(val1);
Serial.print("\tA1 = ");
Serial.println(val2);
delay(1000);
}
I have used a voltage divider with two 10KOhm resistors across VCC and Gnd. A0 is connected to VCC and A1 is connected to the junctions of resistors(i.e. 2.5V).
I am getting
A0 = 1023 A1 = 824 (instead of 512 or near) the A1 value is slowly increasing.
saravananm92:
I have used a voltage divider with two 10KOhm resistors across VCC and Gnd. A0 is connected to VCC and A1 is connected to the junctions of resistors(i.e. 2.5V).I am getting
A0 = 1023 A1 = 824 (instead of 512 or near) the A1 value is slowly increasing.
The reading from A0 is what you would expect.
The reading from A1 might indicate that you have a floating input i.e. that it is not actually connected in the way you think. Try connecting A1 directly to Vcc and GND and see whether you get sensible readings then.
Also, can you confirm you're selected the correct board type in the IDE?
I didn't put any code and scematics beacuese it seems to be independent to that.
I attached the circuit image.
With this configuration (and with other ones too) if
Ak is connexted to pin_k , if I analogRead input Ai I get always the value on Ak where k is the lowest index used!
my code:
void setup() {
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
delay(1000);//analogReadResolution(10);
Serial.println("----");Serial.println(analogRead(A1));
delay(500);
Serial.println(analogRead(A3));
delay(500);
Serial.println(analogRead(A5));
}
ps. saravananm92: please if you have a problem open a new topic
Sorry for the inconvinience.I thought it may help you as well.
Does your breadboard have a gap in the middle of the power and ground rails? Some breadboards are like that and need the gap bridged to carry power and ground to both ends. If you have a meter, check the voltage at the A1 input to make sure the 2.5V is there or not. If you don't have a meter get one, soon. You will need it.
saravananm92: your help is gold, but you presented a problem different from mine in this post and this causes confusion.
groundfungus: thanks for replying! I use a mini 170 - points bradboard (http://cdn.shopify.com/s/files/1/0045/8932/products/BREADBOARD-170-YELLOW_medium.jpg?v=1357778860) and it only has equi-potential rows. Anyway the voltages in the circuit seem good! in fact if I change the pins on the fly (runtime) by joining the working analog input with different poins in the circuit I get a good result! So there seems to be a problem in the read process
PLEASE READ.
I could not figure out were the error was. So I though the evil was windows and I tried in linux. Now it works so it may be a problem related to the windows implementation of arduino software stuffs!
I suppose it is possible that a Windows version of the IDE generates different code from the Linux version but it seems unlikely.
Have you tried uploading the sketch using Linux and connecting the Arduino to Windows and vice versa?
Have you tried swapping the connections between pins? Is it still always the lowest numbered pin that is read?
Have you tried doing a pair of analogRead()s on each pin and discarding the first of the pair?
...R
Have you tried uploading the sketch using Linux and connecting the Arduino to Windows and vice versa?
yes. linux code works. Windows side serial monitor shows good results. Windows code instead shows bad results in linux too
Have you tried swapping the connections between pins? Is it still always the lowest numbered pin that is read?
Yes.
Have you tried doing a pair of analogRead()s on each pin and discarding the first of the pair?
yes. There is a change in the behaviour, i.e. instead of the lowest pin always display the intermediate one.
ps. I tried also to use the A11 pin and in this case on windows the dominant pin is a11 no more A0
mbin:
Have you tried doing a pair of analogRead()s on each pin and discarding the first of the pair?
yes. There is a change in the behaviour, i.e. instead of the lowest pin always display the intermediate one.
This is potentially interesting, but I don't know what you mean by the intermediate pin.
It's also interesting, and very strange, that the sketch uploaded by Linux works fine into a Windows PC.
...R
if I have three pins A1, A6 and A11 with "intermediate" I erroneously mean A6.
It is not strage. once the code has been compiled it is stored and execute inside arduino so what I see on windows is merely its serial output. It is also for this reason that one could think to a compile\build error in windows like environment
If you don't find it strange I wonder why you are asking about it here
As far as I know the Arduino IDE is written in Java and its code should be identical on Windows and Linux so I would expect the compiled code sent to the Arduino to be identical also - assuming you are using the same version of the IDE on Windows and Linux.
I still don't understand what you mean by the "intermediate one" - let me explain ...
You have three connections at 5v, 2.5v and 0v and you have three analog pins A1, A6 and A11
I can only guess that you have A1 connected to 5v, A6 connected to 2.5v and A11 connected to 0v, and that when you say intermediate you mean you are always getting 2.5v no matter which pin you read. (It is both the intermediate voltage and the intermediate pin).
But what happens if you connect A6 to 5v, A11 to 2.5v and A1 to 0v? Then 2.5v would be the intermediate voltage but it would not be expected on the intermediate pin.
And what happens if you do three analaogRead()s in succession and discard the first 2?
...R
If you don't find it strange I wonder why you are asking about it here smiley
Oh no I find it very strange!
I still don't understand what you mean by the "intermediate one" - let me explain ...
Ok sorry I used a very naif language, but with "intermediate" I simply refer to the index of the pin, not to the voltage!( because as you pointed out it would be topological dependent! and so inconsistent)
My "intermediate" was only because I didn't want to speak about a particular pin number, I wanted to speak about 3 pins no matter what index they have (because the point is that arduino doesn't work independently to which pin I consider) so they can be (A0,A3,A7) or (A1,A6,A11) or any other triplet and I can refer to them generally by calling one the "lowest" that means the lower-indexed pin between the three I consider, the second one the "intermediate" and the last one the "higher". That's all!
Anyway let throw away "intermediate" and just call them A1 A6 and A11!
By the way. I tried to run arduino with this topology:
A1 connected to GND
A6 connected to 3.3V
A11 connected to 1.65V
the same code compiled with windows give (in both win and linux serail monitor)
(the order of my measurement is A1, A6, A11)
----
0
1019
0
----
598
471
471
----
470
470
471
----
471
471
471
and then stabilizes to a common value
The same code uploaded and compiled in linux gives (in both win and linux):
------
0
1023
571
------
0
1019
571
------
0
1022
572
------
0
1021
572
------
0
1023
574
that is ok.
As far as I know the Arduino IDE is written in Java and its code should be identical on Windows and Linux so I would expect the compiled code sent to the Arduino to be identical also - assuming you are using the same version of the IDE on Windows and Linux.
Yes it is very weird .
The bytecode must be the same, maybe the difference is in the syscalls i.e. in the way the SO manage the system calls , the periferical access and the java vm in general... I dont know but facts are facts
anyway thanks for support me!
OK. That's much clearer.
Have you tried swapping the pins around as I suggested?
I don't like Windows but I'm curious so I might try this out later.
Is this the Arduino code you are using (from an earlier post)
void setup() {
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
delay(1000);
//analogReadResolution(10);
Serial.println("----");
Serial.println(analogRead(A1));
delay(500);
Serial.println(analogRead(A3));
delay(500);
Serial.println(analogRead(A5));
}
...R
Robin2:
Have you tried swapping the pins around as I suggested?
yes I have and the same thing happens
Please --- you have gone back to generalities and I don't understand.
How have you swapped the pins?
When you say that "the same thing happens" do you mean that you get 471 on all the pins or do you get the number that's appropriate to the A6 pin?
...R
well arduino code might be the same, but compiler code might not.
I have no idea what compilers you're using for windows and linux, but:
- on Windows with stock Arduino IDE dl-ed from arduino.cc, you get a very old avr-gcc 4.3.
- on Linux, it's often using distribution's avr-gcc, which is relative new (like 4.7 or 4.8 nowadays).
so, i suggest you update the windows version avr, it can be dl-ed from Atmel:
you want "Atmel AVR 8-bit Toolchain 3.4.3 - Windows".
plus, will pinMode(An, INPUT);
in setup() help?