How to connect ArduCAM shield to MEGA 2560

Published by Lee Jackson on

Arduino beginners often face compatibility problems between UNO and MEGA board. The truth is that the UNO and MEGA board doesn’t compatible in some ways, for example, UNO SPI port pins are 10,11,12,13, and I2C port pins are A4, A5, while Mega board SPI port pins are 50,51,52,53, and I2C port pins are 20,21. Actually the UNO and MEGA boards made some changes from the R0 version to the R3 version to make the I2C interface compatible.

ArduCAM shield uses a hardware I2C interface, which is A4(SDA), A5(SCL) on the UNO board, and 20(SDA),21(SCL) on the MEGA board. Arduino UNO R3 and MEGA2560 R3 add additional pins for the I2C interface but the R0 version doesn’t.
If you have MEGA 2560 R0 or R2 version, you have to re-wire the I2C and make some changes in the sketch.

Mega2560_I2C_rewire-1
Mega2560_I2C_rewire-2

The sketch should be modified as follows:

void Setup()
{
  ....
  pinMode(A4, INPUT);
  pinMode(A5, INPUT);
  ...
}

ArduCAM shield use hardware SPI interface for SD/TF read and write, which is 10(SS),11(MOSI),12(MISO),13(SCK) on UNO board. But on the MEGA2560 board, they are 53(SS),51(MOSI),50(MISO),52(SCK). When ArduCAM shield used on MEGA board, the user should use software SPI, changes should be made as follows:

Open the file …\Arduino\libraries\SD\utility\Sd2Card.h and changed “#define MEGA_SOFT_SPI 0” to “#define MEGA_SOFT_SPI 1”. Then added “pinMode(53, OUTPUT); in the Setup() function.

Categories: Tutorial

2 Comments

Edgar · July 17, 2013 at 12:46 pm

if i have a arduino MEGA 2560R3, do i need change the Sd2Card.h? thanks i load the sketch but not save the picture

    admin · July 21, 2013 at 2:20 pm

    Yes, if you want to use the sd card socket in the ArduCAM shield you have to change the Sd2Card.h to make it use software spi library. Or else, you can use hardware SPI port to a additional SD card reader adapter board.

Leave a Reply

Your email address will not be published. Required fields are marked *