element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum What are the Arduino IDE pin assignments?
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 12 replies
  • Answers 8 answers
  • Subscribers 392 subscribers
  • Views 8056 views
  • Users 0 members are here
  • pin
  • ide
  • assignment
  • mapping
Related

What are the Arduino IDE pin assignments?

Former Member
Former Member over 11 years ago

I am going to write a program for an existing ATmega32 processor and was trying to understand the pin number assignments. As an example the blink program has the following code.

 

// Pin 13 has an LED connected on most Arduino boards.

// give it a name:

int led = 13;

 

But the key word is "MOST" and it is a pin number which has a mapping to a processor I/O pin. On the UNO the LED is on pin 19/PB5. I wanted to understand why this was 13 and wanted a way to use an more understandable translation from code to hardware. For example:

 

// LED connected to PB5.

// give it a name:

int led = PB5;

 

PB5 is defined in one of the iomXX.h files that depend on the processor.

This would work if PB5 was mapped to the processor's pin used for port B bit 5, but it is not. It is assigned the value of 5.

PA5, PB5, PC5 and PD5 are all assigned the value of 5.

 

I analyzed the pins_arduino.h files to understand the pin mapping so I could define a value for the pins that would map to the processor's pins. For example on a ATmega32 the following definitions give variable names to the pins. This is not the pin on the microprocessor, but the pin number that the Arduino IDE uses to communicate with the functions like digitalWrite(8,HIGH) with set PinB0 high.

 

static const uint8_t PinB0 = 8;

static const uint8_t PinB1 = 9;

static const uint8_t PinB2 = 10;

static const uint8_t PinB3 = 11;

static const uint8_t PinB4 = 12;

static const uint8_t PinB5 = 13;

static const uint8_t PinB6 = 14;

static const uint8_t PinB7 = 15;

 

Using these definitions I can write code that I use to wire up my LED.

 

// LED connected to PinB5.

// give it a name:

int led = PinB5;

 

So here is my question. I really wanted the variable name to be PB0, not PinB0 since that is the name the datasheet uses, but that name is already defined in iom32.h.

What is the reason that PBx is defined in iom32.h?

 

Is there some combination of the pin assignments in iom32.h that I should be using that give me the mapping to the pin number, or is there some documentation that defines the mapping?

  • Sign in to reply
  • Cancel

Top Replies

  • shabaz
    shabaz over 7 years ago in reply to sbkenn +2 suggested
    Hi Shane, As I understand (been a while since I tried Arduino, so this information is just general), you can directly ignore nearly all Arduino functions (you'll still need the usual starting function…
  • Former Member
    Former Member over 11 years ago in reply to ntewinkel +1 suggested
    Thanks for the fast response. Again let me ask the question (without all the support statements) with different words. It isn't about the UNO or any board, it is about the microprocessor and the datasheet…
  • ntewinkel
    ntewinkel over 11 years ago in reply to Former Member +1 suggested
    Hi Bill, I don't know, but I wonder if the other definitions are used for direct port manipulation: http://arduino.cc/en/Reference/PortManipulation So it looks like PB5 can only be used when looking at…
Parents
  • ntewinkel
    0 ntewinkel over 11 years ago

    Hi Bill,

     

    The pins are marked on the board itself. When the sample says pin 13, that's shorthand for D13 = digital 13. When referencing Analogue pins you would use A0, A1, etc.

     

    Take a look at the picture of the Uno here and you'll see all the I/O ports are marked with numbers:

    http://arduino.cc/en/uploads/Main/ArduinoUno_r2_front.jpg

     

    More details about the Uno:

    http://arduino.cc/en/Main/arduinoBoardUno

     

    Hope that helps image

     

    Cheers,

    -Nico

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • ntewinkel
    0 ntewinkel over 11 years ago in reply to ntewinkel

    Oops, sorry, I see I didn't read your question carefully enough!

    This diagram might help, in that it shows the mappings:

    http://forum.arduino.cc/index.php/topic,146315.0.html

     

    Not sure if that's what you're looking for...

     

    Cheers,

    -Nico

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
Reply
  • ntewinkel
    0 ntewinkel over 11 years ago in reply to ntewinkel

    Oops, sorry, I see I didn't read your question carefully enough!

    This diagram might help, in that it shows the mappings:

    http://forum.arduino.cc/index.php/topic,146315.0.html

     

    Not sure if that's what you're looking for...

     

    Cheers,

    -Nico

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube