request for correction to documentation

On this Arduino web page: & - Arduino Reference, about half way down the page you see these two paragraphs.

Example Program
A common job for the bitwise AND and OR operators is what programmers call Read-Modify-Write on a port. On microcontrollers, a port is an 8 bit number that represents something about the condition of the pins. Writing to a port controls all of the pins at once.

PORTD is a built-in constant that refers to the output states of digital pins 0,1,2,3,4,5,6,7. If there is 1 in an bit position, then that pin is HIGH. (The pins already need to be set to outputs with the pinMode() command.) So if we writePORTD = B00110001; we have made pins 2,3 & 7 HIGH. One slight hitch here is that we may also have changeed the state of Pins 0 & 1, which are used by the Arduino for serial communications so we may have interfered with serial communication.

In the second paragraph, this sentence seems wrong: So if we writePORTD = B00110001; we have made pins 2,3 & 7 HIGH. It should say we have made pins 5,4, & 0 HIGH, or else change the binary number to B10001100.

Yes it seems to be wrong. But they do say “pins 2,3 and 7” not bits, does that map to the Arduino pins?

EDIT: I looked at the UNO schematic, the PORTD bits map directly to logical pin numbers so yes the doc is wrong.


I never thought about the mapping between the mega2560 chip pins and the Arduino board pins. I was thinking strictly about the port pins on the chip itself.

That documentation is totally wrong for a Mega. PORTD is I2C, RXD1 and pin 38 on the Mega. Bits 4-6 are not connected.