SD card module with Arduino Mega not working. [SOLVED]

SOLVED: solution in reply #12

Hello everyone,

I know i am not the first person with the problem, but I cant figure it out. Hopefully you can help me out.

I have an Arduino Mega and an SD-shield with an voltage regalutor. (Linked) I could not find this in the documentation but i think the small device i see is the regulator. I added my setup in the picture. SD card is microSD16GB via microSD to SD adapter. SD card works fine in PC.

The weird thing is that i got it working fine after some troubles and now it just completely stops working. I did rewire it because i needed to put it in a box but i am certain that this is correct, as I made a schematic overview of it before disassemble. Now even the CardInfo and Datalogger examples are not working.

When it worked it was in CSpin 4. other pins where 50,51,52 as mentioned in previous posts. I did format it with the formatting tools form the sticky. I did put pinmode and digitalwrite correct as discussed in previous posts. I also used the 3.3V supply.

I also tried pin 10 and 53, but that made no difference.

More stuff was attached to the Arduino (LED, Sensor, etc) but that was also the case when it worked. Can provide the schematic for this if requested.

My question now is:
What am I doing wrong, is it the wiring or software?
Is the voltage regulator on the shield maybe only for the power and not for the com-pins? If that is the case I probably broke it, but cant see the connections on the shield.

Hopefully you can help me, I could not find a proper working example on this forum for Mega, and could not understand the SDfat library, which is also suggested.

Sorry for the german:

Another question/solution:

I am considering to switch to the Adafruit datalogger shield, as i am also using RTC. Is the Datalogger shield compatible with the Mega? It says so in the product description, but i am a bit reserved about that as i also read that about this shield. Is there anyone with experience with the Mega and Datalogger shield? Does it have the same problems?

lucashoed:
I also used the 3.3V supply.

I also tried pin 10 and 53, but that made no difference.

The site you link to is far too difficult to use.
Mega's 3.3v supply doesn't have much power and, if the SD module has a 5v pin, you would be better off using that.
You should only use the SDFat library when you have a very good reason, and I bet you haven't.
You use pin 53 as output with a Mega, You can't see any difference because of other problems.
IF the Adafruit shield is specifically made for Mega, and thereby not compatible with Uno, AND it has a DS3231 on board, go for it. If not, it is probably more trouble than it is worth, and you are a lot better off making your own on a Mega proto board. This is because both the SPI and I2C busses use different pins on a Mega and are not in the reach of a Uno board. At very least, Ada's board would need to use the ICSP pins, and it probably doesn't.

Nick_Pyner:
IF the Adafruit shield is specifically made for Mega, and thereby not compatible with Uno, AND it has a DS3231 on board, go for it. If not, it is probably more trouble than it is worth, and you are a lot better off making your own on a Mega proto board. This is because both the SPI and I2C busses use different pins on a Mega and are not in the reach of a Uno board. At very least, Ada's board would need to use the ICSP pins, and it probably doesn't.

If the OP is looking at Adafruit Data Logging Shield it is made to use the ICSP pins and SCL/SDA header pins (as opposed to the A4/A5 header pins), so should work with a Mega without modification. The RTC is a PCF8523, which is not as accurate as the DS3231, and the battery used is the less common CR1220. Nice that they actually made it compatible with the Mega, I have taken the time to modify a similar generic board that used the D11/D12/D13 & A4/A5 pins so know what that's like.

The board the OP linked appears to have power options for both 3.3V and 5V, and probably should run off 5V with a 5V Arduino board. I've not familiar with that particular design which does not use a buffer chip.

Ah well, there you go - we all learn. I guess others are around, but I have never seen a commercial Uno-size board with ICSP pins other than the WizNet family. That said, I fail to see how the RTC gets to Mega's I2C bus on pins 20,21. I have modified homebrew Uno boards to use Mega I2C, but I wouldn't entertain that with a storebought board. So is that RTC on another bus? That would explain a lot.....

Nick_Pyner:
I fail to see how the RTC gets to Mega's I2C bus on pins 20,21. I have modified homebrew Uno boards to use Mega I2C, but I wouldn't entertain that with a storebought board. So is that RTC on another bus? That would explain a lot.....

The UNO and Mega both route the I2C to the SDA & SCL header pins at the top of the same connector as D8 through D13. Most UNO shields use the A4 & A5 header connections, but Adafruit opted to use the SDA & SCL connections, with the option to use A4 & A5 by soldering a couple of jumper pads on the PC board, for boards that lack the specific SDA & SCL header pins.

Ah yes, that makes sense. It appears that that board is good for both I2C and SPI on Mega, and I withdraw my comment. I had completely forgotten that newer Megas have those extra pins. I hope OP's looks like this.

Mega latest iscp.jpg

Mega latest iscp.jpg

Hello,

Sorry for the late reply.

My board looks like that in reply #6. Those pins I am currently using for my DS3231 RTC.

I am know considering ordering the micro SD shield by adafruit, linked below. This shield has a level-shifter, so should work with 5V on MOSI, MISO, SCK and CS.

This what I understand from reply #2, from reply #4 and further you kinda lost me.

Hopefully you could reply with your opinion on this solution.

Thanks for your elaborated replies,
Lucas

lucashoed:
and further you kinda lost me.

Possibly because I put you on the wrong tram.

Megas are made to take shields. If you have a Mega, it is always best to use a shield.

If you have a Mega with the pins as shown in my reply #6, the Adafruit shield linked in reply #3 will fit, even though it is "Uno-size". You have never said what you are actually trying to do, but the word "datalogger" was in there somewhere and that shield should serve you well, as I think it comes from a reliable supplier, has a prototyping area to handle the stuff you are not yet talking about, and is a sensible package. Its great advantage is that you should be confident Lady Ada knows what is needed to be known about SD cards. You can safely ignore all that stuff about volts, buffers, diodes, and levels - just plug the shield in, and use it.

The full-size SD card module like the one linked by the OP is suitable for use only with 3.3V processors. While it has a 3.3V regulator to provide power to the SD card, the MOSI, SCK and CS lines coming in from the processor only have pullup resistors to 3.3V on the module, not level shifters. But those lines coming from a Mega would be 5V lines, which probably exceeds the absolute maximum voltage you can apply if the card is running at 3.3V. The 10K pullups would have no significant effect on the 5V level coming in. A possible fix is to insert diodes into the three lines so the processor can only bring the lines low, and the pullups bring them high. There would probably be some speed penalty with this fix because the pullups are 10K.

But I should say - some cards work just fine with the 5V lines. So this isn't necessarily the cause of the OPs problems.

Thanks Sherman for your solution, but i am looking for something with a bit more elegance.

I already ordered the Adafruit microSD module, which will come in today. This has level shifters and the documentation explicitly mentioned the Mega.

I will report back when this is in, with a complete solution for my problem.

I am just wondering now, just for the fun of it, these 2 things:
Why do boards like the Mega have digital 5V connections dedicated to SPI communication? Would the practical solution not be to put a level shifter on the board? There is plenty of space as I can see.

Why are SD modules so unclear about wheter or not they work with 3.3V or 5V. Finding out that SD cards are 3.3V devices even took me a while. But then i thought my module was ok with 5 & 3.3V, as it has both those Vcc inputs. Nowhere did I find a clear documentation about the presence of voltage regulators or level shifter.

Now I am not saying that you should not do research when working with these projects, but it was exceptionally difficult to find info on this. All the post on this forum suggest the same.

Thanks for the help everybody, will post elaborate solution this afternoon or tomorrow for people from the future! :slight_smile:
Lucas

lucashoed:
Why do boards like the Mega have digital 5V connections dedicated to SPI communication? Would the practical solution not be to put a level shifter on the board? There is plenty of space as I can see.

The SPI pins are not dedicated to the SPI bus, they are simply the 5v digital pins you must use if you want to use the SPI bus.

Why are SD modules so unclear about wheter or not they work with 3.3V or 5V. Finding out that SD cards are 3.3V devices even took me a while. But then i thought my module was ok with 5 & 3.3V, as it has both those Vcc inputs. Nowhere did I find a clear documentation about the presence of voltage regulators or level shifter.

Who knows? Probably just laziness. Also, these modules may be for use on devices other than Arduino, hence my comment above. An SD slot on an Arduino shield leaves you in no doubt about what it is intended to be used on.

Okay here I am,

I order the Adafruit MicroSD breakout board, and it works like a charm.

Same layout as before and CardInfo and Datalogger example work perfectly.

For everybody struggling with this in the future: check if your SD module has a level shifter when using it with a 5V Arduino. Although many people say that it may work without this, I think you're asking for trouble. Mine worked first and then suddenly stopped. Hopefully this will help you.

Who knows? Probably just laziness. Also, these modules may be for use on devices other than Arduino, hence my comment above. An SD slot on an Arduino shield leaves you in no doubt about what it is intended to be used on.

But still, working voltage of the pins of your device should be clear right? Especially when it give such hard to solve problems.

I guess that's right. I just use Ethernet shields. I haven't used Ethernet in years, but the card slot is bulletproof. If you are referring to the datalogging example by Igoe included in the IDE, I would be very suss about it as it uses Strings, and quite unncessarily too, I suspect. These may eventually cause you grief and are best avoided. I'm sure that example was not always that way, but I think Igoe originally did it in collaboration with somebody else.

lucashoed:
Okay here I am,

I order the Adafruit MicroSD breakout board, and it works like a charm.

Same layout as before and CardInfo and Datalogger example work perfectly.

For everybody struggling with this in the future: check if your SD module has a level shifter when using it with a 5V Arduino. Although many people say that it may work without this, I think you're asking for trouble. Mine worked first and then suddenly stopped. Hopefully this will help you.
But still, working voltage of the pins of your device should be clear right? Especially when it give such hard to solve problems.

I'm glad it's working for you. Now if you have three diodes in your junque box, you could try out the mod of the original SD module and see if it then works perfectly. That would pin down the lack of shifting as the cause of the problem, and give you a full size SD module that works with either 3.3V or 5V, in case you every need it.

If I ever have time on my hands, I will defenitly try it out, sounds like fun.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.