Mega 2560 + data logger shield problem

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Woodcutter
 
Posts: 6
Joined: Wed Dec 14, 2011 3:27 pm

Mega 2560 + data logger shield problem

Post by Woodcutter »

Background: I have built up an Adafruit data logger shield and tested it with an Arduino Uno. I can run the CardInfo and Datalogger examples in the SD library and read the logged data files by plugging the SD card into my netbook. This gives me confidence that the shield and card are both OK.

Problem: For my project, I need more outputs than the Uno provides, so I'm using a Mega 2560. I've studied the other threads about getting the logger shield to work with the Mega without making any physical changes, but I just can't get it to recognise the card.

In software I have changed the line in the SD/utility/Sd2Card.h file to:
#define MEGA_SOFT_SPI 1 (from #define MEGA_SOFT_SPI 0)
In the CardInfo example sketch I've changed two linesto
const int chipSelect = 10;
and
pinMode(53, OUTPUT);
as advised in the coding comments.

Where am I going wrong? Any help much appreciated.

jsiebler
 
Posts: 4
Joined: Fri Feb 04, 2011 12:46 pm

Re: Mega 2560 + data logger shield problem

Post by jsiebler »

I have exactly the same problem. Data logger works great with the UNO, but not with the MEGA. Tried everything that has been suggested so far.

I am using the Adafruit GPS-Logger shield. Any help/idea would be very much appreciated.

Thanks a lot

fat16lib
 
Posts: 593
Joined: Wed Dec 24, 2008 1:54 pm

Re: Mega 2560 + data logger shield problem

Post by fat16lib »

To use software SPI on the Mega only change this line

Code: Select all

#define MEGA_SOFT_SPI 1
Do not change chipSelect from 10. Software SPI uses pins 10, 11, 12, and 13 on the Mega.

It is best to just delete this statement in hardware or software SPI:

Code: Select all

  pinMode(10, OUTPUT);
It serves no function since the SD library sets the correct mode for all of the pins that it uses.

jsiebler
 
Posts: 4
Joined: Fri Feb 04, 2011 12:46 pm

Re: Mega 2560 + data logger shield problem

Post by jsiebler »

I just tried this, but unfortunately this did not help either...

Woodcutter
 
Posts: 6
Joined: Wed Dec 14, 2011 3:27 pm

Re: Mega 2560 + data logger shield problem

Post by Woodcutter »

Also just tried this and it does not work for me either.

For clarification,I'm using the SD/RTC data logger shield (not the GPS sheild), Arduino v22 and the SD library from here: https://github.com/adafruit/SD.git

Following fat16libs advice I have only changed one line in the SD/utility/Sd2Card.h file to:
#define MEGA_SOFT_SPI 1 (from _SPI 0). I've left all other coding unchanged.

The error message I get when running CardInfo is:
Initializing SD card...initialization failed. Things to check:
* is a card is inserted?
* Is your wiring correct?
* did you change the chipSelect pin to match your shield or module?

Woodcutter
 
Posts: 6
Joined: Wed Dec 14, 2011 3:27 pm

Re: Mega 2560 + data logger shield problem

Post by Woodcutter »

I know software is the answer, but I just started looking at hard wiring changes to make some progress. With the data logger shield mounted on the Mega, I connected:
Mega pin 20 (SDA) to data logger shield pin 4(SDA)
Mega pin 21 (SCL) to data logger shield pin 5 (SCL)
The RTC functions of the data logger card now work fine with the Mega.

I'll try hard wiring so that I can talk to the SD card next.

fat16lib
 
Posts: 593
Joined: Wed Dec 24, 2008 1:54 pm

Re: Mega 2560 + data logger shield problem

Post by fat16lib »

I tried the latest SD.h from https://github.com/adafruit/SD. The default chipSelect in this version of of CardInfo is 4 so you need to make two changes:

in libraries\SD\examples\CardInfo\Cardinfo.pde

Code: Select all

// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
const int chipSelect = 10;   
and in libraries\SD\utility\Sd2Card.h

Code: Select all

/**
 * Define MEGA_SOFT_SPI non-zero to use software SPI on Mega Arduinos.
 * Pins used are SS 10, MOSI 11, MISO 12, and SCK 13.
 *
 * MEGA_SOFT_SPI allows an unmodified Adafruit GPS Shield to be used
 * on Mega Arduinos.  Software SPI works well with GPS Shield V1.1
 * but many SD cards will fail with GPS Shield V1.0.
 */
#define MEGA_SOFT_SPI 1
I then ran Cardinfo with a Mega 2560 and an unmodified Data Logging Shield and got this result:
Initializing SD card...Wiring is correct and a card is present.

Card type: SD2

Volume type is FAT16

Volume size (bytes): 2032271360
Volume size (Kbytes): 1984640
Volume size (Mbytes): 1938

Files found on the card (name, date and size in bytes):
DATALOG.TXT 2000-01-01 01:00:00 13416
TEST.TXT 2000-01-01 01:00:00 54
I designed software SPI so once MEGA_SOFT_SPI is set non-zero, a sketch will run on a 2560 or 328 Arduino without mods.

jsiebler
 
Posts: 4
Joined: Fri Feb 04, 2011 12:46 pm

Re: Mega 2560 + data logger shield problem

Post by jsiebler »

I already tried both of these changes and they do not work for me :-(

Woodcutter
 
Posts: 6
Joined: Wed Dec 14, 2011 3:27 pm

Re: Mega 2560 + data logger shield problem

Post by Woodcutter »

I deleted my old SD library and got a copy of the one in your link. I made the changes you suggest, but I still get an initialization failure.

Is SD the only additional library I need? Are there any other checks I could make to help diagnose the problem?

Thanks for continuing to provide help, fat16lib, it is much appreciated.

fat16lib
 
Posts: 593
Joined: Wed Dec 24, 2008 1:54 pm

Re: Mega 2560 + data logger shield problem

Post by fat16lib »

You only need an unmodified version of the Arduino IDE. On 1.0 use the provided SD library and on 0022 download the Adafruit SD library.

Make the two mods above. The CardInfo sketch should then work on both Uno and Mega 2560 boards without changes.

Did you try the modified library and sketch on an Uno or other 328 Arduino?

Edit:

Did you replace the existing SD library in The 0022 IDE libraries folder? Do not add it to the sketchbook libraries folder.

Woodcutter
 
Posts: 6
Joined: Wed Dec 14, 2011 3:27 pm

Re: Mega 2560 + data logger shield problem

Post by Woodcutter »

I deleted my old Arduino v22 IDE and got Arduino 1.0. I rechecked my shield and SD card with my Uno and everything was OK. I then changed the SPI value in Sd2Card.h from 0 to 1 and the chipSelect value in the CardInfo sketch to 10 and ...

Success!

Those tiny software tweaks and the addition of wire jumpers from shield pin 4 to Mega pin 20 (SDA) and from shield pin 5 to Mega pin 21 (SCL) now give me a fully functional SD & RTC data logger shield with a Mega. I'll look into the use of softi2c next to see if I can dispense with the jumpers.

Fat16lib - Thank you SO MUCH for your help and patience. The willingness of experts like yourself to help out bumbling amateurs like me makes the whole Arduino project something special.

jsiebler
 
Posts: 4
Joined: Fri Feb 04, 2011 12:46 pm

Re: Mega 2560 + data logger shield problem

Post by jsiebler »

Yes, this works also for me now. I completely reinstalled Arduino 1.0 made the changes and now it is working just fine. For some reason I must have gotten a SD library that does not work.

Thank you soo much for your help! I really appreciate this kind of support!!

tgmeiner
 
Posts: 40
Joined: Sun Jan 15, 2012 12:52 pm

Re: Mega 2560 + data logger shield problem

Post by tgmeiner »

Woodcutter wrote:Background: I have built up an Adafruit data logger shield and tested it with an Arduino Uno. I can run the CardInfo and Datalogger examples in the SD library and read the logged data files by plugging the SD card into my netbook. This gives me confidence that the shield and card are both OK..

I built a Adafruit data logger shield with an Aruduino Uno,I am using a EM-406A GPS module. I tested the module and it works. But When I run the GPStest_RMC code I get no data displaying.

Do you have any suggestions?

I would eventually like to collect and store in the SD data from the GPS and a BMP085 barometric pressure sensor so I can read to the SD card and make plots.

Any help is greatly appreciated.
Thanks:)
Attachments
Screen shot 2012-01-24 at 7.48.52 PM.png
Screen shot 2012-01-24 at 7.48.52 PM.png (26.87 KiB) Viewed 5848 times

tgmeiner
 
Posts: 40
Joined: Sun Jan 15, 2012 12:52 pm

Re: Mega 2560 + data logger shield problem

Post by tgmeiner »

Iam using Arduino 1.0.

User avatar
adafruit_support_bill
 
Posts: 85866
Joined: Sat Feb 07, 2009 10:11 am

Re: Mega 2560 + data logger shield problem

Post by adafruit_support_bill »

@tgmeiner - Don't post the same problem in multiple threads. It only confuses things. We are working this problem in your first thread.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”