On Arduino I can set digital pins by setting special variables PORTB and PORTD (or maybe they are not variables?). Where are those variables defined? I grepped /usr/share/arduino, but found nothing.

grep -r 'PORTB' /usr/share/arduino/

2 Answers 2


PORTB is defined by the "toolchain". It is not defined by Arduino. For instance in my setup the Arduino Uno uses "toolchain" avr-gcc\4.9.2-amtel3.5.3-arduino2\avr.

If you grep that folder (location dependent on tool and installation options) you will find a file called iom328p.h that defines

#define PORTB _SFR_IO8(0x05)

This is a mapping to a physical address of the cpu.

  • Thank you. And how does this file gets included when my program is compiled and linked? Is it included by Arduino.h?
    – user983447
    Commented Feb 15, 2017 at 14:04
  • 1
    Arduino.h includes avr/io.h, which in turn includes the ioXXX.h file relevant to your specific MCU. Commented Feb 15, 2017 at 14:24

. Where are those variables defined?

In the device header file. Like other device specific macros.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.