Help with PinMode / Total pins...

Hey Folks...

The Arduino is an awesome platform that I've only
been scratching the surface with. With the circuitry
for my project out of the way I've been coding.

Have a basic question with the assignments of the
pins (in code) and what range 0-13 / 1-14 etc and
the physical layout.

Sorry to ask but I cant find any clear documentation
that's specific here. So as an example:

int Pin1 = 0; - is this pin 0 rx on the bottom of the card?
int Pin13 = 13; - is this pin 13 on the bottom right?

How are A0 thru A5 assigned / accessed in code?

So is there any cheat sheet with ALL the dig/analog
pin assignments and how to address them in code?

Appreciate any clarity with the hardware/software
assignments anyone can offer!

Thanks in advance
HowY

Pinnumbers refered to in code matches the number on the board (in white print, that is)

He's right, the pin numbers in the code match what is on the board.

If I'm not mistaken (I'm new too)

For analog input commands, if you reference pins 0 thru 5, it will use the proper analog input pin.

For digital commands, if you reference pins 0 through 13 it will use the proper digital IO pin. If you reference 14 through 19, it will use analog input pins 0 thru 5 as digital IO pins... a neat feature that is not documented all that well.

Many thanks for the quick response!

"... For digital commands, if you reference pins 0 through 13 it will use the proper digital IO pin. If you reference 14 through 19, it will use analog input pins 0 thru 5 as digital IO pins... a neat feature that is not documented all that well. "

Thanks for that tidbit... 14-19 who'd thunk it!

I realize it obvious when you get wrapped around the process
but at first it's puzzling. :-[

Thanks a TON!

HowY

Hey, I'm still starting out too :slight_smile:

The "Hello World" beginner code is crucial. Run some of the tutorials, then make changes to the program and see what happens. And read Massimo's little book "Getting Started with the Arduino".

Also, it's fun to build some of your own hardware. Paul over at ModernDevice.com has some great kits! Over the last weekend I built a Bare Bones Board (an Arduino clone) and the serial LCD interface. Great fun!

I have been unsuccessful in getting the analog pins to work "transparently" as digital inputs and outputs.

HW: 3x4 matrix keypad (SparkFun COM-08653) connected to pure digital pins works fine, eg D7..D13.

When connected to analog pins, and #defines changed, associated rows/cols don't respond, eg. D2..D6, D14, D15, where the latter two don't respond.

I'm trying to reserve 7 digital pins for LCD output, 2 for serial, then use 5 for keypad, plus the two analog pins.

Is there some special initialization to use analog pins in digital mode?

I tried inserting a delay after each write of a col or read of a row, thinking the analog circuits needed time to recover, but it didn't help.

Here's my code... TIA for any suggestions. --Jeff

/* Keypad Testing: read keypad, write serial
2008-12-18
*/

// arduino pin numbers associated with rows/cols of keypad matrix
#define KPD_C1 2
#define KPD_C2 14 // 7 OK, problem when 14
#define KPD_C3 4
#define KPD_R1 15 // 8 OK, problem when 15
#define KPD_R2 6
#define KPD_R3 5
#define KPD_R4 3

byte kpd_cols[3] = {KPD_C1, KPD_C2, KPD_C3};
byte kpd_rows[4] = {KPD_R1, KPD_R2, KPD_R3, KPD_R4};

char kpd_keys[] = "123456789*0#";

void InitKeypad()
{
int i;
for(i=0; i<4; i++) pinMode(kpd_rows*, INPUT); // rows are inputs*
for(i=0; i<4; i++) digitalWrite(kpd_rows*, HIGH); // enable pull-ups*
for(i=0; i<3; i++) pinMode(kpd_cols*, OUTPUT); // cols are outputs*
for(i=0; i<3; i++) digitalWrite(kpd_cols*, HIGH); // cols default high*
}
byte GetKey()
{
* byte k = 0;*
* for(byte col=0; col < 3; col++)*
* {*
* digitalWrite(kpd_cols[col], LOW); // send a col low*
* delay(1);*
* for(byte row=0; row < 4; row++)*
* {*
* byte x=digitalRead(kpd_rows[row]);
_ delay(1);
if (x == 0) // see if the row caught it*

* {
Serial.print("kpc=");_

Serial.print(kpd_cols[col], DEC);
_ Serial.print(" kpr=");_
Serial.print(kpd_rows[col], DEC);
_ Serial.print(" col=");
Serial.print(col, DEC);
Serial.print(" row=");
Serial.print(row, DEC);_

k = kpd_keys[col+(3row)];

* delay(500); // debounce*
* break;*
* }*
* }*
* digitalWrite(kpd_cols[col], HIGH);
_ }
return k;
}
void setup()
{
InitKeypad();
Serial.begin(9600);
Serial.println("Going...");
}
void loop()
{
byte key = GetKey();
if (key > 0)
{
Serial.print(" key=");
Serial.println(key);
}
}
[/quote]*_

try something simple like:

int ledPin = 14;                // connect an led to analog pin 0

void setup()                    // run once, when the sketch starts
{
  pinMode(ledPin, OUTPUT);      // sets the digital pin as output
}

void loop()                     // run over and over again
{
  digitalWrite(ledPin, HIGH);   // sets the LED on
  delay(1000);                  // waits for a second
  digitalWrite(ledPin, LOW);    // sets the LED off
  delay(1000);                  // waits for a second
}

Doh! Tried a simple program like that suggested. Found I had miswired things, thinking that the analog pins numbered from 0 from the edge of the board, like the digital. RTFM! Always RTFM!

Found I had miswired things, thinking that the analog pins numbered from 0 from the edge of the board, like the digital.

Yes, always refer to a datasheet or manual. However, many packages with many pins will start with the lowest-numbered pin in one corner, and other pins will be counted upwards in the counterclockwise direction, all the way around all the edges of the part, as viewed from the part's top. This is true of chip packages as well as the standard Arduino board itself.

In the Picaxe world (and maybe others) they started to refer to "pin numbers" Vs "leg numbers" to try and make it more clear that a software definition of the same I/O pin can be different then the same physical pin number of the chip. A Chip manufacture's data sheet will have no knowlege of the software pin numbering assignments made by a specific software platform. This can be a hurdle for begineers to get their heads around.

Lefty