Go Down

Topic: About pins ... (Read 18051 times) previous topic - next topic

EasyGoing1

OK, so I got my first Arduino (RobotDyn CH340/A 2650) several months ago, and I've been playing with it ... experimenting .... learning ... tons of Googling ... Ive even successfully used a few shields ... but I'm struggling with something that I feel should be very easy to grasp and I've decided to post my dilemma here.

I seem to be struggling with inputs and accuracy in reading voltages. You see, when I set a pin as an input because I want to read some voltage (between 0 and 5 volts of course), the behavior of the Arduino does not seem to be consistent from one pin to the next, and I want to start a project that would require some consistency in this thing. I'm starting to wonder if this unit is faulty.

When you set an analog pin such as A10 as an input, then start reading the pin value without any voltage applied to it, is it normal to get readings in the 500 range? When I take the pin to ground, SOMETIMES it goes to zero (depending on the pin), and sometimes it makes no change at all. Then when I apply a small voltage to it, sometimes it changes, sometimes it doesn't and again it seems to be depend on the pin im using (usually between A10 and A15).

Second question: Ive noticed that when I declare an int to something like A8, it actually comes out as 62 when I print it to serial. So that got me wondering about the literal pinouts etc., and in my searching, I looked at this link for my unit, but according to that page, pin 62 is ground ... so what gives?

Is there a way to test this thing and the inputs to make sure they are functioning properly? Some kind of uniform thing I can do say with a AA batter or something that I can apply to certain pins and get a known value etc.?

Thank you,

Mike Sims
Mike Sims

CrossRoads

"When you set an analog pin such as A10 as an input, then start reading the pin value without any voltage applied to it, is it normal to get readings in the 500 range?"
A floating input pin can be all over the place. Try a 100k pullup resistor to provide a steady reading when nothing is connected.
Use a 1K, 5K, 10K pot with legs at Gnd and 5V, wiper to an input pin. Should see steady reading with values reported at ~ level/4.88mV.

Physical pin numbers are not the same as the software mapped pin numbers.  Header pins D0 and D1 connect to chip pin 2 and 3 for example.
D62 = A8 = physical pin 89 for example.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

EasyGoing1

Use a 1K, 5K, 10K pot with legs at Gnd and 5V, wiper to an input pin. Should see steady reading with values reported at ~ level/4.88mV.
OK, I'll give that a shot.

Physical pin numbers are not the same as the software mapped pin numbers.  Header pins D0 and D1 connect to chip pin 2 and 3 for example.
D62 = A8 = physical pin 89 for example.
So then how does someone wrap their head around all of this seeming inconsistency?
Mike Sims

(deleted)


EasyGoing1

If you search for Arduino MEGA2560 Pin out - all pins and functions are listed there.  :)
You mean like the one I linked to in my original question?  Yeah, its clear as mud :-)
Mike Sims

EasyGoing1

Use a 1K, 5K, 10K pot with legs at Gnd and 5V, wiper to an input pin. Should see steady reading with values reported at ~ level/4.88mV.
So to alleviate any confusion, here is a diagram of exactly how I have the Arduino connected as you suggested, using a 10k trim pot.



Here is the code I used to obtain the information:
Code: [Select]

#include <Wire.h>
#include <LiquidCrystal.h>
#include <LCDKeypad.h>

template<class T> inline Print &operator <<(Print &obj, T arg) { obj.print(arg); return obj; }

#define p1 A8
#define p2 A12

LCDKeypad lcd;

void setup() {

lcd.begin(16,2);
lcd.clear();
lcd.setCursor(0,0);
lcd << "A8  A12";
pinMode(p1, INPUT);
pinMode(p2, INPUT);

}

void loop() {
    lcd.setCursor(0,1);
    lcd << "         ";
    lcd.setCursor(0,1);
    lcd << String(analogRead(p1)) + " " + String(analogRead(p2));
    delay (500);
}



Here are the readings I get as I move the swiper on the pot:


Meter    A8      A12
------   ---     ----
  0      520      0
  1.04   521      522
  2.27   520      522
  3.03   522      520


See what I mean by inconsistent?
Mike Sims

(deleted)


EasyGoing1

Mike Sims

(deleted)


EasyGoing1

Nope - like this one

Mega Pin Out
I cleaned up the pic a little and made it easier to reference...

Mike Sims

EasyGoing1

Code: [Select]
pinMode(p1, INPUT);
pinMode(p2, INPUT);


If you remove these lines, the pins are already inputs, you could read the pins here to 'prime' them.
I removed those lines as you suggested, but the results are the same.
Mike Sims

(deleted)


EasyGoing1

#12
Jan 04, 2017, 02:12 am Last Edit: Jan 04, 2017, 03:00 am by EasyGoing1
Can you connect A8 direct to GND on the mega, and A12 direct to 5V and then to 3.3V and post the results.
OK, here are those results with A8 connected directly to ground and A12 on the Arduino 5V pin then the 3.3v pin:


A8    A12
------------
511   510 (5v)
513   514 (3v)

Mike Sims

(deleted)


EasyGoing1

Your ADC is Broken!  :(
That's not what I wanted to hear, but I've suspected as much.  Any idea how this could happen? And I suppose there's no way to repair it ... that a replacement board is now my only option?  Should I not get the cheap-o Chinese version again / and what do you recommend for a Mega dev board or something other than a Mega??
Mike Sims

Go Up