Pages: [1]   Go Down
Author Topic: Analog inputs linked somehow?  (Read 1986 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 42
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 have two functions reading the analogue pins on my mega 1280
The input pins are different, the variables are different, the functions are different. Still both
functions will take input from either input pin.
I.E input on pin 0 is read by both functions, and input on pin 2 is read by both functions.
What's causing this??

Code:
 
  int boostPin = A0;   // input pin for the MPX4250
  int af_Pin = A2;   //

Code:

  int boostRead = 0; //Stores value read from MPX4250
  int af_Read = 0; //Stores value read from UEGO

The reading itself is done in the looop by:
Code:

void loop(){  
    boostRead = analogRead(boostPin);
    af_Read = analogRead(af_Pin);
    }

Code:
function boost(){
caluculate input from boostRead;
lcd.print (bCalculation);
}

function afr(){
caluculate input from af_Read;
lcd.print (afCalculation);}
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8501
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Firstly that's not compilable code.

Secondly where do you call the two functions?

Thirdly, unless it's huge just show us the entire code, as it is anything could be happening between the snippets.


______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

0
Offline Offline
Newbie
*
Karma: 0
Posts: 42
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The code is too long for the forum.

http://pastebin.com/AYFtVZ82

Could this bit be the culprit?
Code:
//_____________Defining Encoder Inputs_________________________________________
  #define button 22
  #define ENC_A 20  //MUST be pin 0 i pinD range
  #define ENC_B 21  //MUST be pin 1 i pinD range
  #define ENC_PORT PIND  //Create a port wich low-level reads all pinD pins simultaneously (=pin0-pin7)=low level read

« Last Edit: March 01, 2011, 07:38:58 am by Bebbetufs » Logged

Italy
Offline Offline
Full Member
***
Karma: 3
Posts: 142
jayduino rox
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


How did you connect the sensors to the inputs? are they floating right now? That can lead to weird results.
Logged

Juergen

0
Offline Offline
Newbie
*
Karma: 0
Posts: 42
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The sensors are not really there. I'm using a pot for testing. it is connected to the analog input, ground is from the board and 5v is from my power supply, the one that powers the board. Currently running @ 5.2 volts.

I also tried feeding the pot 5v from the Arduino board. Same results.
Could it be that the voltage is too low for the board?
Logged

United States (Texas)
Offline Offline
God Member
*****
Karma: 3
Posts: 525
Arduino socks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

are you using one pot or two?
Logged

Georgina Ontario
Offline Offline
Sr. Member
****
Karma: 5
Posts: 437
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If what you are saying is that: You can read the input (with no lead) next to the pin that you actually do have wired... then the answer is yes. I can confirm this.

If I am only using say three Analog inputs, I GROUND the inputs on either side of the three (sequential) leads that I am using... At least then I spot my stooopid typoes eh?

So I think I can confirm your question...

Logged

Just another Hacker

0
Offline Offline
Newbie
*
Karma: 0
Posts: 42
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
If what you are saying is that: You can read the input (with no lead) next to the pin that you actually do have wired... then the answer is yes. I can confirm this.

If I am only using say three Analog inputs, I GROUND the inputs on either side of the three (sequential) leads that I am using...
Is this how it is supposed to be?
I'm only using one pot for testing and shifting this from port A0 to A2. I also tried A0 and A8 just to be sure.
When i adjust the pot which is now only connected to input A8 the analog read function reads the exact same values from the presently unconnected A0.

Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 18
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

as far as I remember, the inputs in Arduino are multiplexed and the system
switches between them to digitize the signal.
If your input is hanging in the air, I suspect that the charge sitting
at the "collecting plate" at the moment of measuring the
previous signal has no sink and the second pin appears to be at the
same potential. What happens if you ground the second pin?
I think you'll measure zero in this case.

Basically, what is your question? Why does the floating pin measure
the same voltage as a connected one? Even if it is so why should
one worry about any data from floating inputs? smiley

Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 42
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I tried grounding the second pin.
No difference.
The two bars on my LCD which are supposed to measure different inputs both move in perfect sync no matter if I ground pin A0 and connect the pot to pin A2, or vice versa. The value input to one pin is duplicated to the other.
Logged

Montreal
Offline Offline
Faraday Member
**
Karma: 29
Posts: 2590
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your code is HUGE.
have you ever try split it ? debug one piece at a time?
as they say, you can't swallow an ellefant.
 
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 18
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, then do a simple test:
write a routine that reads the inputs
one after another and sends the results to
the serial output (to eliminate possible messing with overlapped
pin numbers).
Just several lines: read the input, print the data, 1 sec delay.

If this routine will return similar values for each pin no matter what
you do with the pot then it's the problem of the board and this might mean
that the digitizer or the multiplexor has been fried.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 42
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Did the test and was able to sort it out. Thanks for the tip.
I had set the PSU to 5v which seems to make the board unstable somehow. I also had to sort out my wiring a bit.
It's working now so thanks to everyone for their help.
Logged

Pages: [1]   Go Up
Jump to: