Quick Pin Mapping Question

Total Newbie here. On the pin mapping diagram for the Mega2560, there are three numbers for each pin: pin number, pin name, and mapped pin name.

When I set a variable to a pin in the IDE, for instance:

int meter = 8;
//...
//...
pinMode(meter,INPUT);
// etc... etc..

Do I use the pin number or the mapped pin name (which is actually a number too, and differs from the pin number)?

Thanks!

The numbering of the pins on the ATMEL chip does not correlate to the pin numbers around the edge of the Arduino.

Use the number around the edge of the Arduino.

THanks for the response, I know what you mean. However, the pin mapping diagram doesn't say what is the chip and what is the arduino board. I haven't bought my arduino yet, so the schematics and diagrams are all I have to go by.

For instance, if on the pin mapping diagram, it was listed like this:

Pin Number: 35; Pin Name PL0; Mapped Pin Name: Digital Pin 49

(This is an actual pin on the 2560)

Which would you use to assign it to a variable, 35 or 49?

Thanks again!

Wade

35 is the Amtel pin #. D49 is the Arduino pin#.

Always use the Arduino pin #.

Perhaps the following pin mapping worksheet will help you out. Column 1 has the Arduino pin# you use in digitalRead, digitalWrite, and mode commands:

https://spreadsheets.google.com/pub?key=rtHw_R6eVL140KS9_G8GPkA&gid=0

Lefty

123Splat: 35 is the Amtel pin #. D49 is the Arduino pin#.

Always use the Arduino pin #.

Ok. That seems fine except for you wouldn't set the int to D49, you would set it to 49.

The only place where that doesn't make sense is when I am trying to set some analog pins. For instance, one analog input I would like to use is labeled like this on the pin map diagram:

pin number: 97; pin name: (ADCO)PF0; mapped pin name: Analog Pin 0

So according to that logic, I would enter this code:

//Initialize variables
int sensor = 0;         // this is the analog pin for the sensor. using the 'mapped pin name' from the pin map diagram, which is "analog pin 0."
//..
//..
void setup() {
     Serial.begin(9600);
     pinMode(sensor, INPUT);  // setting it to be an input
}

Now something about that seems wrong since I heard at one point that 0 and 1 was used for USB-serial connection.

retrolefty: Perhaps the following pin mapping worksheet will help you out. Column 1 has the Arduino pin# you use in digitalRead, digitalWrite, and mode commands:

https://spreadsheets.google.com/pub?key=rtHw_R6eVL140KS9_G8GPkA&gid=0

Lefty

Where do you get those numbers in the first column? They don't match up with anything in the pin map diagram available from Arduino. Not saying you're wrong at all, just wondering where it came from.

The PD, PB, PC refer to the arduino port registers for direct addressing of i/o pins. PORTD maps to Arduino digital pins 0 to 7 PORTB maps to Arduino digital pins 8 to 13 PORTC maps to Arduino analog pins 0 to 5

There is a good write up at here. http://www.arduino.cc/en/Reference/PortManipulation

wadesweatt:

retrolefty:
Perhaps the following pin mapping worksheet will help you out. Column 1 has the Arduino pin# you use in digitalRead, digitalWrite, and mode commands:

https://spreadsheets.google.com/pub?key=rtHw_R6eVL140KS9_G8GPkA&gid=0

Lefty

Where do you get those numbers in the first column? They don’t match up with anything in the pin map diagram available from Arduino. Not saying you’re wrong at all, just wondering where it came from.

It came from the arbitrary abstraction that the Arduino platform defined in their ‘core libraries’. There is no logical relationship between the AVR processor port and pin numbers Vs the Arduino abstracted pin numbers, it is what it is because they defined it as such. :wink:

They don’t match up with anything in the pin map diagram available from Arduino.

Which map are you referring to? Can you post a link to what you are looking at.
Lefty

retrolefty: Which map are you referring to? Can you post a link to what you are looking at. Lefty

Here's the link: http://arduino.cc/en/Hacking/PinMapping2560

Scroll down the page and you'll see the big table with all the values I've been referring to. I just need to know which number to use when assigning variables to pins. Didn't think it would be so confusing.

wadesweatt:

123Splat: 35 is the Amtel pin #. D49 is the Arduino pin#.

Always use the Arduino pin #.

Ok. That seems fine except for you wouldn't set the int to D49, you would set it to 49.

The only place where that doesn't make sense is when I am trying to set some analog pins. For instance, one analog input I would like to use is labeled like this on the pin map diagram:

pin number: 97; pin name: (ADCO)PF0; mapped pin name: Analog Pin 0

So according to that logic, I would enter this code:

//Initialize variables
int sensor = 0;         // this is the analog pin for the sensor. using the 'mapped pin name' from the pin map diagram, which is "analog pin 0."
//..
//..
void setup() {
     Serial.begin(9600);
     pinMode(sensor, INPUT);  // setting it to be an input
}

Now something about that seems wrong since I heard at one point that 0 and 1 was used for USB-serial connection.

First you don't use pinMode commands to setup analog input commands, you just use the pin names A0 to A5 in the analogRead(x) , where x can be either 0,1,2,3,4,5 or A0, A1....A5. The 0 is not to be confused with digital pin number 0 which is a different physical pin. To make it even more confusing you can utilize analog input pins as digital input or output pins by using the normal digital input and output and mode commands but using arduino digital pin numbers 14 to 19. That is assuming we are talking about a 168/328 based chip as the mega1280/2560 uses different digital pin numbers to map to it's 16 analog input pins.

I'm sure that is clear as mud now. ;)

The numbers down the left are the physical pins on the chip. You need to use the "Mapped Pin Name" colunm. The first line of that table, Digital Pin 4 on your Arduino Mega is pin 1 on the chip itself. PG5 is it's register address.

ie

int pwmPin = 4; // Pwm from *Pin1* of MEga

When u get ur board, you’ll see how easy, it says next to every pin
use that number

inboxjason: The numbers down the left are the physical pins on the chip. You need to use the "Mapped Pin Name" colunm. The first line of that table, Digital Pin 4 on your Arduino Mega is pin 1 on the chip itself. PG5 is it's register address.

ie

int pwmPin = 4; // Pwm from *Pin1* of MEga

See my coding example two or three posts up... the only problem with that is that the mapped pin name for the analog pin in my example is 0. So I'm not sure how using the mapped pin name can be the right number since I know for a fact that 0 and 1 are usb-serial ports..

EDIT: Here is the code:

//Initialize variables
int sensor = 0;         // this is the analog pin for the sensor. using the 'mapped pin name' from the pin map diagram, which is "analog pin 0."
//..
//..
void setup() {
     Serial.begin(9600);
     pinMode(sensor, INPUT);  // setting it to be an input
}

inboxjason: The numbers down the left are the physical pins on the chip. You need to use the "Mapped Pin Name" colunm. The first line of that table, Digital Pin 4 on your Arduino Mega is pin 1 on the chip itself. PG5 is it's register address.

ie

int pwmPin = 4; // Pwm from *Pin1* of MEga

See my coding example two or three posts up... the only problem with that is that the mapped pin name for the analog pin in my example is 0. So I'm not sure how using the mapped pin name can be the right number since I know for a fact that 0 and 1 are usb-serial ports..

EDIT: Here is the code:

//Initialize variables
int sensor = 0;         // this is the analog pin for the sensor. using the 'mapped pin name' from the pin map diagram, which is "analog pin 0."
//..
//..
void setup() {
     Serial.begin(9600);
     pinMode(sensor, INPUT);  // setting it to be an input
}

Also, Just thinking, that listed in the 'mapped pin name' section, there is a digital pin 0 and an analog pin 0, so if I say:

int newPin = 0;

Am I talking about the analog pin 0 or the digital pin 0?

It's assumed you mean a digital pin unless you specify an analog pin with

int analogPin = A0

D0 + D1 are used for serial tx/rx so stay away from these.