Go Down

Topic: Multiple analog inputs measure same value (Read 552 times) previous topic - next topic

jbares

Feb 03, 2014, 07:52 pm Last Edit: Feb 03, 2014, 07:57 pm by jbares Reason: 1
Hi everyone,
First I am a newbie with Arduino, so maybe my problem is really simple...
I want to measure different inputs as a function of time using 4 different analogic inputs (A0, A1, A2, A3) of my Arduino Due. From now I have just plugged A0 and A1 to a 1.5V battery and grounded A2 and A3. My problem is that most of the time my Due measures the wrong input.

Here is a draw of my circuit:


Here is my code:
Code: [Select]
///Assign pins:
//Pin of the analog input 1:
byte SensorPin1 = 0;
//Pin of the analog input 2:
byte SensorPin2 = 1;
//Pin of the analog input 1:
byte SensorPin3 = 2;
//Pin of the analog input 2:
byte SensorPin4 = 3;

///Define variables:
//Time (in ms):
unsigned long Time0;
//Analog measure input 1:
unsigned int Analog1;
//Analog measure input 2:
unsigned int Analog2;
//Analog measure input 3:
unsigned int Analog3;
//Analog measure input 4:
unsigned int Analog4;


///Stepup:
void setup()
{
 //Initialize serial port (speeds: 9600, 14400, 19200, 28800, 38400, 57600, 115200):
 Serial.begin(9600);
 
 //Turn the resoltion to 12 bits:
 analogReadResolution(12);
}

///Functionning loop:
void loop()
{
 //Measure time:
 Time0=millis();
   
 //Measure analog inputs:
 Analog1=analogRead(SensorPin1);
 Analog2=analogRead(SensorPin2);
 Analog3=analogRead(SensorPin3);
 Analog4=analogRead(SensorPin4);

 //Return data:
 Serial.print(Time0);
 Serial.print(" , ");
 Serial.print(Analog1);
 Serial.print(" , ");
 Serial.print(Analog2);
 Serial.print(" , ");
 Serial.print(Analog3);
 Serial.print(" , ");
 Serial.println(Analog4);
}


Here is what I get:
2 , 1880 , 1885 , 1885 , 6
29 , 1884 , 4 , 3 , 1884
56 , 1886 , 6 , 4 , 1883
83 , 1885 , 6 , 4 , 1872
110 , 1885 , 5 , 3 , 1884

I would be really grateful if one of you have an idea to help me !
Thanks in advance...




Palliser

Hello jbares,

I ran your code on my DUE and it works perfectly.
I tested it using a 1.5VDC AA battery without the 100ohm resistor. Here the output:

Quote

...
21123 , 2003 , 2005 , 0 , 0
21153 , 2005 , 2004 , 0 , 0
21183 , 2004 , 2002 , 0 , 0
21214 , 2005 , 2005 , 0 , 0
21244 , 2004 , 2005 , 0 , 0
21274 , 2006 , 2005 , 0 , 0
21304 , 2005 , 2005 , 0 , 0
21334 , 2005 , 2005 , 0 , 0
21364 , 2004 , 2005 , 0 , 0
21395 , 2006 , 2005 , 0 , 0
21425 , 2005 , 2005 , 0 , 0
21455 , 2004 , 2006 , 0 , 0
21485 , 2005 , 2006 , 0 , 0
21515 , 2005 , 2004 , 0 , 0
21545 , 2005 , 2005 , 0 , 0
21576 , 2005 , 2005 , 0 , 0
21606 , 2005 , 2005 , 0 , 0
21636 , 2005 , 2006 , 0 , 0
...


It seems to me that your battery could be dead and your wiring could be wrong.
I would recommend you to run the test with a different battery (preferably new)  and double check your wiring.
Regards, Palliser

MarkT

1.5.5 is broken for analogRead() on > 1 pin.  This is a known bug that should be
fixed in the nightly builds and the next release, 1.5.3 should work too, but
is slower.
[ I won't respond to messages, use the forum please ]

jbares

:) Problem solved !!  :)  Thanks alot !
I used 1.5.3 as you suggested MarkT and everything works fine !
Also, thank you Palliser for taking some time to look at my problem.
I can move forward now and look more interesting things than a battery voltage...

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy