3 | P a g e
SPI: 50 (MISO), 51 (MOSI), 52 (SCK), 53 (SS). These pins support SPI communication using
the SPI library. The SPI pins are also broken out on the ICSP header, which is physically
compatible with the Uno, Duemilanove and Diecimila.
LED: 13. There is a built-in LED connected to digital pin 13. When the pin is HIGH value, the
LED is on, when the pin is LOW, it's off.
I
2
C: 20 (SDA) and 21 (SCL). Support I
2
C (TWI) communication using the Wire library
(documentation on the Wiring website). Note that these pins are not in the same location as
the I
2
C pins on the Duemilanove or Diecimila.
The Mega2560 has 16 analog inputs, each of which provide 10 bits of resolution (i.e. 1024 different
values). By default they measure from ground to 5 volts, though is it possible to change the upper end
of their range using the AREF pin and analogReference() function.
There are a couple of other pins on the board:
AREF. Reference voltage for the analog inputs. Used with analogReference().
Reset. Bring this line LOW to reset the microcontroller. Typically used to add a reset button to
shields which block the one on the board.
Communication
The Arduino Mega2560 has a number of facilities for communicating with a computer, another
Arduino, or other microcontrollers. The ATmega2560 provides four hardware UARTs for TTL (5V)
serial communication. An ATmega8U2 on the board channels one of these over USB and provides a
virtual com port to software on the computer (Windows machines will need a .inf file, but OSX and
Linux machines will recognize the board as a COM port automatically. The Arduino software includes
a serial monitor which allows simple textual data to be sent to and from the board. The RX and TX
LEDs on the board will flash when data is being transmitted via the ATmega8U2 chip and USB
connection to the computer (but not for serial communication on pins 0 and 1).
A SoftwareSerial library allows for serial communication on any of the Mega2560's digital pins.
The ATmega2560 also supports I2C (TWI) and SPI communication. The Arduino software includes a
Wire library to simplify use of the I2C bus; see the documentation on the Wiring website for details.
For SPI communication, use the SPI library.
Programming
The Arduino Mega can be programmed with the Arduino software (download). For details, see the
reference and tutorials.
The ATmega2560 on the Arduino Mega comes preburned with a bootloader that allows you to upload
new code to it without the use of an external hardware programmer. It communicates using the
original STK500 protocol (reference, C header files).
You can also bypass the bootloader and program the microcontroller through the ICSP (In-Circuit
Serial Programming) header; see these instructions for details.
The ATmega8U2 firmware source code is available in the Arduino repository. The ATmega8U2 is
loaded with a DFU bootloader, which can be activated by connecting the solder jumper on the back of
the board (near the map of Italy) and then resetting the 8U2. You can then use Atmel's FLIP software
(Windows) or the DFU programmer (Mac OS X and Linux) to load a new firmware. Or you can use the
ISP header with an external programmer (overwriting the DFU bootloader). See this user-contributed
tutorial for more information.