Arduino · A000067

Arduino Mega 2560

Arduino Mega 2560 Rev3: an ATmega2560 (8-bit AVR, 16 MHz) at 5 V, with an ATmega16U2 as its USB serial.

AVR (C)Arduino
Arduino Mega 2560Arduino · ATmega2560 · AVR · 16 MHz · 8 KB · bare metalArduino Mega 256012345678910111usb USBUSB-B (power, uploads, serial)2pwr Power5 V USB, or 7 V to 12 V on the barrel jack3v3v3 Power3.3V pin4v5 Power5V pin (from USB: its 500 mA fuse)5gnd PowerGND6uart0 UARTUSART0 (D1, D0: the USB serial too) · tx PE1,rx PE07uart1 UARTUSART1 (D18 TX1, D19 RX1) · tx PD3, rx PD28uart2 UARTUSART2 (D16 TX2, D17 RX2) · tx PH1, rx PH09uart3 UARTUSART3 (D14 TX3, D15 RX3) · tx PJ1, rx PJ010i2c0 I²CTWI, the I²C (D20, D21) · sda PD1, scl PD011spi0 SPISPI (D52, D51, D50, D53) · sck PB1, mosi PB2,miso PB3, cs PB071 GPIO pins, each a port (led, …)

In short

The big Arduino: an ATmega2560 at 16 MHz, 256 KB flash, 8 KB SRAM, 5 V pins. 54 digital pins (15 PWM), 16 analog inputs and 4 UARTs. No CAN: add an MCP2515 on SPI.

Clock16 MHz
Flash256 KB
RAM8 KB
GPIO68
Logic5 V

Specs

From the board’s model in the store.

Processor
ATmega2560 · 1× AVR · chip "atmega2560"
Clock
16 MHz
Flash
256 KB
RAM
8 KB
GPIO pins
68
ADC
ADC 16 ch 10-bit
Logic level
5 V
Power
5 V USB, or 7 V to 12 V on the barrel jack (in); 3.3V pin: 3.3 V (≤ 50 mA); 5V pin (from USB: its 500 mA fuse): 5 V (≤ 500 mA)
Current per pin
20 mA
Buses
UART ×4, I²C ×1, SPI ×1
Runs
bare metal (no OS)

Pin map

Each pin by what it does. Hover or tap a pin to see what else it can be.

  • Power 3
  • Ground 1
  • Digital 40
  • Analog 16
  • Bus 12
  • Control 2
  • PE0D0 (RX0)
  • PE1D1 (TX0)
  • PE4D2 (PWM, INT4)
  • PE5D3 (PWM, INT5)
  • PG5D4 (PWM)
  • PE3D5 (PWM)
  • PH3D6 (PWM)
  • PH4D7 (PWM)
  • PH5D8 (PWM)
  • PH6D9 (PWM)
  • PB4D10 (PWM)
  • PB5D11 (PWM)
  • PB6D12 (PWM)
  • PB7D13 (PWM, LED L)
  • PJ1D14 (TX3)
  • PJ0D15 (RX3)
  • PH1D16 (TX2)
  • PH0D17 (RX2)
  • PD3D18 (TX1, INT3)
  • PD2D19 (RX1, INT2)
  • PD1D20 (SDA, INT1)
  • PD0D21 (SCL, INT0)
  • PA0D22
  • PA1D23
  • PA2D24
  • PA3D25
  • PA4D26
  • PA5D27
  • PA6D28
  • PA7D29
  • PC7D30
  • PC6D31
  • PC5D32
  • PC4D33
  • PC3D34
  • PC2D35
  • PC1D36
  • PC0D37
  • PD7D38
  • PG2D39
  • PG1D40
  • PG0D41
  • PL7D42
  • PL6D43
  • PL5D44 (PWM)
  • PL4D45 (PWM)
  • PL3D46 (PWM)
  • PL2D47
  • PL1D48
  • PL0D49
  • PB3D50 (MISO)
  • PB2D51 (MOSI)
  • PB1D52 (SCK)
  • PB0D53 (SS)
  • PF0A0
  • PF1A1
  • PF2A2
  • PF3A3
  • PF4A4
  • PF5A5
  • PF6A6
  • PF7A7
  • PK0A8
  • PK1A9
  • PK2A10
  • PK3A11
  • PK4A12
  • PK5A13
  • PK6A14
  • PK7A15
  • pwr5 V USB, or 7 V to 12 V on the barrel jack
  • v3v33.3V pin
  • v55V pin (from USB: its 500 mA fuse)
  • gndGND

Watch out

What archec checks for this board, from its data. Each one names the check that catches it.

  • Its pins give 5 V. A 3.3 V part on one of them needs a level shifter between them.

    check pin-level

  • One pin gives at most 20 mA. An LED needs a resistor; a motor or a relay needs a driver.

    check pin-current

  • Two of the board’s connectors share these pins: PB7 (LED L (D13) / D13 (PWM, LED L)), PE1 (USART0 (D1, D0: the USB serial too) / D1 (TX0)), PE0 (USART0 (D1, D0: the USB serial too) / D0 (RX0)), PD3 (USART1 (D18 TX1, D19 RX1) / D18 (TX1, INT3)), PD2 (USART1 (D18 TX1, D19 RX1) / D19 (RX1, INT2)), PH1 (USART2 (D16 TX2, D17 RX2) / D16 (TX2)), PH0 (USART2 (D16 TX2, D17 RX2) / D17 (RX2)), PJ1 (USART3 (D14 TX3, D15 RX3) / D14 (TX3)), PJ0 (USART3 (D14 TX3, D15 RX3) / D15 (RX3)), PD1 (TWI, the I²C (D20, D21) / D20 (SDA, INT1)), PD0 (TWI, the I²C (D20, D21) / D21 (SCL, INT0)), PB1 (SPI (D52, D51, D50, D53) / D52 (SCK)), PB2 (SPI (D52, D51, D50, D53) / D51 (MOSI)), PB3 (SPI (D52, D51, D50, D53) / D50 (MISO)), PB0 (SPI (D52, D51, D50, D53) / D53 (SS)). Use one or the other.

    check pin-conflict

  • The board already uses PB7 (LED L (D13)), PE0 (D0 (RX0)), PE1 (D1 (TX0)), PE4 (D2 (PWM, INT4)), PE5 (D3 (PWM, INT5)), PG5 (D4 (PWM)), PE3 (D5 (PWM)), PH3 (D6 (PWM)), PH4 (D7 (PWM)), PH5 (D8 (PWM)), PH6 (D9 (PWM)), PB4 (D10 (PWM)), PB5 (D11 (PWM)), PB6 (D12 (PWM)), PB7 (D13 (PWM, LED L)), PJ1 (D14 (TX3)), PJ0 (D15 (RX3)), PH1 (D16 (TX2)), PH0 (D17 (RX2)), PD3 (D18 (TX1, INT3)), PD2 (D19 (RX1, INT2)), PD1 (D20 (SDA, INT1)), PD0 (D21 (SCL, INT0)), PA0 (D22), PA1 (D23), PA2 (D24), PA3 (D25), PA4 (D26), PA5 (D27), PA6 (D28), PA7 (D29), PC7 (D30), PC6 (D31), PC5 (D32), PC4 (D33), PC3 (D34), PC2 (D35), PC1 (D36), PC0 (D37), PD7 (D38), PG2 (D39), PG1 (D40), PG0 (D41), PL7 (D42), PL6 (D43), PL5 (D44 (PWM)), PL4 (D45 (PWM)), PL3 (D46 (PWM)), PL2 (D47), PL1 (D48), PL0 (D49), PB3 (D50 (MISO)), PB2 (D51 (MOSI)), PB1 (D52 (SCK)), PB0 (D53 (SS)), PF0 (A0), PF1 (A1), PF2 (A2), PF3 (A3), PF4 (A4), PF5 (A5), PF6 (A6), PF7 (A7), PK0 (A8), PK1 (A9), PK2 (A10), PK3 (A11), PK4 (A12), PK5 (A13), PK6 (A14), PK7 (A15). Something else wired there fights with it.

    check pin-conflict

  • The 3.3V pin gives at most 50 mA at 3.3 V. Add up what you power from it.

    check board-current

  • The 5V pin (from USB: its 500 mA fuse) gives at most 500 mA at 5 V. Add up what you power from it.

    check board-current

  • It gives 3.3 V (3.3V pin), 5 V (5V pin (from USB: its 500 mA fuse)). Power each part from a rail at its own voltage.

    check board-supply

  • It has 4 UART, 1 I²C, 1 SPI. One more bus of a kind than that is an error.

    check board-peripheral

  • Each bus goes on the pins that can carry it (see the pin map). Another pin is an error.

    check pin-function

First model

A blink for this board: the board, an LED and a part that turns it over every 500 ms. archec checks it, then writes the code on the right.

main.archeOpen in the playground
project Blink "Blink" {
  version "0.1.0"
  edition "1.0"
  uses arche-hw-store "^0.1"
}

include "arche-hw-store/boards/arduino-mega-2560/arduino-mega-2560.arche"
include "arche-hw-store/devices/led/led.arche"

/// Turns the LED over at each step.
component Blinker "Blinker" {
  out led: requires Led
  fn blink "Blink" {
    ```arche
    led.toggle()
    ```
    wcet 50us
  }
}

/// The board, an LED on the board's LED L (D13) (PB7), and the blinker.
system Hw "Blink" {
  part board:   ArduinoMega2560
  part led:     GpioLed { in pin { pins { pin PB7 } } }
  part blinker: Blinker
  blinker.led -> led.led
}

/// The firmware: the blinker every 500 ms.
deployment OnBoard "On the board" {
  system Hw
  platform Hw
  binary blink on board {
    thread main "Blink" { runs blinker; period 500ms; step blink }
  }
}
archec gen --target cblinker.c
/* Generated by archec: component Blinker. Do not edit outside the USER CODE regions: run `archec gen --target c` again, it keeps them. */
#include "blinker.h"
#include "arche_rt.h"
#include <math.h>
/* USER CODE BEGIN Blinker.includes */
/* USER CODE END Blinker.includes */

/* @arche Blinker.init main.arche:11 init */
void blinker_init(blinker_t *self)
{
    (void)self;
    /* USER CODE BEGIN Blinker.init */
    /* USER CODE END Blinker.init */
}

/* @arche Blinker.blink main.arche:13 fn */
void blinker_blink(blinker_t *self)
{
    blinker_call_led_toggle(self);
}

blinker.c, one of the 18 files archec writes.

Open in the playground

Parts on the board

What each numbered part is. Click a number to find it on the board.

1 2 3 4 5 6 7 8 9 10 11 12 13 14

Find the part

The quiz names a part: click it on the board. A first try scores a point.

Compare every board