Join makers around the world sharing their projects! Watch the show-and-tell LIVE right now!

Mega 2560 + data logger shield problem
Moderators: adafruit_support_bill, adafruit

Mega 2560 + data logger shield problem

by Woodcutter on Wed Dec 14, 2011 4:26 pm

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.
Woodcutter
 
Posts: 6
Joined: Wed Dec 14, 2011 3:27 pm

Re: Mega 2560 + data logger shield problem

by jsiebler on Wed Dec 14, 2011 9:41 pm

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
jsiebler
 
Posts: 4
Joined: Fri Feb 04, 2011 12:46 pm

Re: Mega 2560 + data logger shield problem

by fat16lib on Wed Dec 14, 2011 10:08 pm

To use software SPI on the Mega only change this line
Code: Select all | TOGGLE FULL SIZE
#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 | TOGGLE FULL SIZE
  pinMode(10, OUTPUT);


It serves no function since the SD library sets the correct mode for all of the pins that it uses.
fat16lib
 
Posts: 593
Joined: Wed Dec 24, 2008 1:54 pm

Re: Mega 2560 + data logger shield problem

by jsiebler on Wed Dec 14, 2011 11:39 pm

I just tried this, but unfortunately this did not help either...
jsiebler
 
Posts: 4
Joined: Fri Feb 04, 2011 12:46 pm

Re: Mega 2560 + data logger shield problem

by Woodcutter on Thu Dec 15, 2011 7:03 am

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

by Woodcutter on Thu Dec 15, 2011 9:34 am

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.
Woodcutter
 
Posts: 6
Joined: Wed Dec 14, 2011 3:27 pm

Re: Mega 2560 + data logger shield problem

by fat16lib on Thu Dec 15, 2011 9:44 am

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 | TOGGLE FULL SIZE
// 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 | TOGGLE FULL SIZE
/**
 * 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.
fat16lib
 
Posts: 593
Joined: Wed Dec 24, 2008 1:54 pm

Re: Mega 2560 + data logger shield problem

by jsiebler on Thu Dec 15, 2011 10:20 am

I already tried both of these changes and they do not work for me :-(
jsiebler
 
Posts: 4
Joined: Fri Feb 04, 2011 12:46 pm

Re: Mega 2560 + data logger shield problem

by Woodcutter on Thu Dec 15, 2011 10:28 am

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.
Woodcutter
 
Posts: 6
Joined: Wed Dec 14, 2011 3:27 pm

Re: Mega 2560 + data logger shield problem

by fat16lib on Thu Dec 15, 2011 10:46 am

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.
fat16lib
 
Posts: 593
Joined: Wed Dec 24, 2008 1:54 pm

Re: Mega 2560 + data logger shield problem

by Woodcutter on Thu Dec 15, 2011 2:29 pm

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.
Woodcutter
 
Posts: 6
Joined: Wed Dec 14, 2011 3:27 pm

Re: Mega 2560 + data logger shield problem

by jsiebler on Thu Dec 15, 2011 8:28 pm

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!!
jsiebler
 
Posts: 4
Joined: Fri Feb 04, 2011 12:46 pm

Re: Mega 2560 + data logger shield problem

by tgmeiner on Tue Jan 24, 2012 10:21 pm

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 3105 times
tgmeiner
 
Posts: 40
Joined: Sun Jan 15, 2012 12:52 pm

Re: Mega 2560 + data logger shield problem

by tgmeiner on Tue Jan 24, 2012 10:22 pm

Iam using Arduino 1.0.
tgmeiner
 
Posts: 40
Joined: Sun Jan 15, 2012 12:52 pm

Re: Mega 2560 + data logger shield problem

by adafruit_support_bill on Wed Jan 25, 2012 6:48 am

@tgmeiner - Don't post the same problem in multiple threads. It only confuses things. We are working this problem in your first thread.
User avatar
adafruit_support_bill
 
Posts: 32571
Joined: Sat Feb 07, 2009 10:11 am