[SOLVED] Using Data Logging shield from Arduino UNO to Arduino Mega ADK

Hi,

I was using an Arduino Uno board with the Keyes Data Logging Shield to read a file from a SD card. Now I'm trying to use the same shield with an Arduino Mega ADK board. Is it possible to use a shield designed for UNO in Mega?

Sure, just jumper the SPI pins used on the Uno to feed from the Mega - 53 to 10 (SS), 52 to 13 (SCK), 51 to 11 (MOSI),and 50 to 12 (MISO).
Then leave 10-11-12-13 as INPUTs in the Mega code.

SS might need to go to 4, or whatever pin you using.

I tried connecting like this (image below) and the power led on the shield turned on, but I can’t intialize the SD Card.

Here’s the part of my code related to the SD card:

#include "Arduino.h"
#include "SD.h"

File arquivo;

void setup() {
	inicializarCartaoSD();
}

void loop() {

}

void inicializarCartaoSD() {
	Serial.println("Inicializando cartão SD...");
	pinMode(10, OUTPUT);
	if (!SD.begin(4)) {
		Serial.println("Não foi possível inicializar o cartão SD.");
		return;
	}
	Serial.println("Cartão SD inicializado.");
}

All I’m getting is the “Não foi possível inicializar o cartão SD.” message (in English: not able to initialize the SD card).

What do I need to do now?

pinMode(10, OUTPUT);

is Uno code. Use pin 53 for Mega.

You do not appear to have a connection to pin 4, or any alternative, for select.

If the holes line up, you should be able to use a 6-pin female for the ICSP cluster to access SPI, plug the board in in the normal manner, and get rid of those jumpers.

Nick_Pyner:

pinMode(10, OUTPUT);

is Uno code. Use pin 53 for Mega.

I changed this from 10 to 53 but still doesn't work.

Nick_Pyner:
You do not appear to have a connection to pin 4, or any alternative, for select.

I connected the pin 53 (SS) in the Mega to the pin 4 on the shield. Is that what you mean?

Nick_Pyner:
If the holes line up, you should be able to use a 6-pin female for the ICSP cluster to access SPI, plug the board in in the normal manner, and get rid of those jumpers.

The Mega has these 6 ICSP pins but I don't know what they do and where should I connect them in the shield. Could you explain that to me or give me a link to anything helpful?

Your code is calling for pin4 as chip select, therefore you need CS on pin4, so connect pin4 on Uno shield to Pin4 on Mega.

Most shields using SPI have an ICSP connector, thereby enabling them to be used on a Uno or Mega without all this drama. If the holes line up you should be able to install a 6pin connector and wire it across to the SPI pins 10,11,12,13 and power. The board was probably made with that in mind, and may even already have tracks for that purpose. Indeed. looking more closely at the picture, I see that the relevant pins have group markings on them, so there is a fair chance the tracks are there

jamilsonjunior:
I tried connecting like this (image below) and the power led on the shield turned on, but I can't intialize the SD Card.

Did you connect a power (5V) and ground between the Mega and the Shield? Your picture only show you have connected the SPI bus?

as Nick_Pyner says:

Nick_Pyner:
Your code is calling for pin4 as chip select, therefore you need CS on pin4, so connect pin4 on Uno shield to Pin4 on Mega.

Most shields using SPI have an ICSP connector, thereby enabling them to be used on a Uno or Mega without all this drama. If the holes line up you should be able to install a 6pin connector and wire it across to the SPI pins 10,11,12,13 and power. The board was probably made with that in mind, and may even already have tracks for that purpose.

You need to have your code match your hardware. You have the hardware connected using pin D53(SS) to connect to Shield Pin 4(black wire), but your code

pinMode(10, OUTPUT);
 if (!SD.begin(4))

is trying to use pin 4?

Change your code to this:

#include "Arduino.h"
#include "SD.h"

File arquivo;

void setup(){
SPI.begin(); // init SPI hardware
// other init stuff
inicializarCartaoSD();
}

void loop() {

}

void inicializarCartaoSD() {
 Serial.println("Inicializando cartão SD...");
 if (!SD.begin(53)) { // actually, I would rather use the predefined SS symbol
 Serial.println("Não foi possível inicializar o cartão SD.");
 return;
 }
 Serial.println("Cartão SD inicializado.");
}

chuck.

Nick_Pyner:
Your code is calling for pin4 as chip select, therefore you need CS on pin4, so connect pin4 on Uno shield to Pin4 on Mega.

I tried connecting pin 4 on shield and pin 4 on Mega and still can't read the SD card.

chucktodd:
Did you connect a power (5V) and ground between the Mega and the Shield? Your picture only show you have connected the SPI bus?

I didn't. Now I connected the power and GND like this:

Is that what you meant?

In the code, I made the changes you suggested but I still can't read the SD card.

Nick_Pyner:
looking more closely at the picture, I see that the relevant pins have group markings on them, so there is a fair chance the tracks are there

You mean these holes (highlited in blue)?

I don't know how I could use them.

jamilsonjunior:
I tried connecting pin 4 on shield and pin 4 on Mega and still can't read the SD card.

I didn't. Now I connected the power and GND like this:

Is that what you meant?

In the code, I made the changes you suggested but I still can't read the SD card.

When I zoomed in your image, It looks like you connected 5Vcc to GND and GND to 5Vcc? I hope Not!

jamilsonjunior:
You mean these holes (highlited in blue)?

I don't know how I could use them.

You would have to verify traces connected to those pins. I would NOT expect them to have traces connecting to the SPI bus. I think they are marked so that you could insert a female 2x3 connector from the bottom, allowing access to the ISP connector without removing the shield.

Keyes DataLogger Shield Manual

If this is the correct manual for your shield, It uses D10,D11,D12,D13 for connection to the SDcard. So, your wiring is incorrect. Connect Mega(D53) to Shield(D10). Verify your Vcc and Gnd connections. Change: sd.begin(53);

Try that.

Chuck.

jamilsonjunior:
You mean these holes (highlited in blue)?
I don’t know how I could use them.

Yes. If the tracks are not there, it simply means you have a painless option to use the holes for other purposes, and you can still use them for ICSP by installing the aforementioned 6pin female and running jumpers to the SPI pins 11>13.

I see the ICSP connection is alluded to in the above manual.

On a Mega, you just need to call Pin 53 as output. There is no actual need to connect to it. Also you can use another pin than pin 4 for CS, like pin 10, so long as you code correctly calls for it.

Finally it worked!

My connections are now these:

And my code is this:

#include "Arduino.h"
#include "SD.h"
#include "SPI.h"

File arquivo;

void setup() {
	SPI.begin();
	inicializarSerial();
	inicializarCartaoSD();
}

void loop() {

}

void inicializarCartaoSD() {
	Serial.println("Inicializando cartão SD...");
	pinMode(53, OUTPUT);
	if (!SD.begin(53)) {
		Serial.println("Não foi possível inicializar o cartão SD.");
		return;
	}
	Serial.println("Cartão SD inicializado.");
}

void inicializarSerial() {
	// Inicializando a porta Serial
	Serial.begin(9600);
	while (!Serial) {
		; // Esperando a porta Serial
	}
}

Thank you all for the help! You are awesome! :smiley:

Glad to hear it is working. You might still try using the ICSP cluster one day, and get rid of those jumpers.