Hello everyone, hope you might forgive me while taking up a well discussed issue - "using SD cards on Arduino is sometimes less than straightforward".
I have probably read every single post on the web, and while taking several actions in the meantime, I ended up spending almost two months uselessly. Long introduction to beg you being easy on me, please...
I'll reward with full gratitude from the Verona, the city of Romeo & Juliet :) for those who heard of it..
For the records, I found these two post quite interesting and close to the topic, nevertheless not applicable to my case:
http://forum.arduino.cc/index.php?PHPSESSID=cb2ocm9h166jhq2fi366rgfdf7&topic=218098.0
http://forum.arduino.cc/index.php?topic=144813.0
MY REAL SIMPLE SETUP: a bare Arduino UNO, no frills, no further shields except SD card module (this --> http://www.lctech-inc.com/Hardware/Detail.aspx?id=0c3b6f7a-d101-4a60-8b56-3abfb7fd818d).
CS pin is 4.
REAL SIMPLE MATTER: it never works, not even the example code.
Cards on the bench are two SanDisk (capacity of 128MB used, formatted and fully working and another 2GB absolutely new and intact) and one Maxell 2GB (used and commonly used in my digital camera. i.e. "working").
Code is "anything" in the example that does some sort of *writing*. Reading is generally fine.
Example SdInfo is working fine. ReadWriteSdFat is not.
My own code used to work for a while until it decided, spontaneously, to quit. Absolutely no chance to attempt a StressTest (as the example provided) neither with the brand new card.
SdFormatter works, but creates an unformatted disk (as reported by ReadWriteSdFat), thus unusable.
Sometimes ReadWriteSdFat makes some written 0Bytes file while returning:
error: opening test.txt for write failed
SD errorCode: 0X13,0X0
Question about pins. Every example reports different pins according to which shield one's using. Not using any shield whatsoever I wonder whether an arbitrary PIN can be chosen. Again, my preferred number is "4" but I tried with other numbers with no luck.
I thought hooking a card to Arduino was way more straightforward but apparently is seems out of my reach.
Any recommendation before throwing everything off the window? :)
[I swear: my next project is to plant a tree...]
Show us the schematics of the sdcard module.. (or datasheet)
Thank you Pito for quick answer... I think trying to find schematics could be a little more harder than I might expect having been the purchase done over eBay and... you know...
Nevertheless I'll try (tomorrow, now I have to take classes). Will keep you informed on my discoveries! :)
Have a good day/night, depends on where you are!
Have you tried the SDfat library that forum member fat16lib maintains?
I think you will have better luck.
http://code.google.com/p/sdfatlib/
Your SD card needs a solid 3.3V supply, they can draw 200-250mA.
The SCK, MOSI, and SS signals should be buffered thru an active device and not just thru resistor dividers.
Let us wait on the schematics. From the picture it seems there are just 4x10k pullups at the signals to 3V3. So it seems a tough decisions waiting on Romeo:
1. trash the module and go with planting the trees
2. go with properly designed dividers
3. go with a buffer
4. trash the module and ask Juliet to help with searching for a better module..
:P
Thank you Pito and CrossRoads, slight bad news here.
Schematics are unavailable, the best I could do is to take closer picture to the soon-to-be trashed item (4).
As for the tree (1), I'm way ahead and done excavation already. Truck on the way home will get the tree here; on the way back the garbage. You could guess the content. Juliet is driving.
2. Unaware of what properly designed dividers are (not that I haven't any clue of, but hardware electronic is still sort of magic for me) there's an AMS1117 3.3 HT315E component, quite likely THE voltage regulator you mention (the only component on board - you know, smart guys comes from northern Italy :)).
Sdfatlib in use is already the latest one, the Christmas' one (20131225).
Hope to find a way out.
Apparently hooking up a wireless card and broadcast bit-after-bit seems a more viable solution... :smiley-roll-sweat:
Thank you!
Still asleep I found this. Can you confirm somehow we talk the same?
If you confirm we talk the same - then you may add a 5th point to your "to-be-decided-list":
5. whether to trash all those SDcards used..
An Sdcard is a 3.3V gadget, it means any signal feeding the card must be below 3.3V.
Arduino Uno itself is 5V - all the signals are 5V.
It may happen the cards survived your experiments.
The shield we discussed is intended for 3V3 powered -inos (I do prefer that since ever, no messing with translators, more time for planting the trees).
What you need to do is to build a level translator from 5V (Arduino) -> 3V3 (Sdrcard's inputs).
You can do it in several ways.
Many SD breakouts and shields use a 74HC4050N. See attached diagram. This part is available in a DIP package http://www.digikey.com/product-detail/en/74HC4050N,652/568-7814-5-ND/1230396 (http://www.digikey.com/product-detail/en/74HC4050N,652/568-7814-5-ND/1230396).
The Adafruit Data logging shield and a number of other products use a 74AHC125N http://www.digikey.com/product-detail/en/SN74AHC125N/296-4531-5-ND/375724 (http://www.digikey.com/product-detail/en/SN74AHC125N/296-4531-5-ND/375724). This also available in DIP.
Here is the circuit for the Adafruit shield http://www.ladyada.net/make/logshield/design.html (http://www.ladyada.net/make/logshield/design.html). The 74AHC125N is a nice cheap part but a little more complex.
http://www.instructables.com/id/Arduino-DIY-SD-Card-Logging-Shield/?ALLSTEPS
Probably with your shield and 4050...
You may try the resistive dividers as well (stick with the resistor values). The power consumption will be higher than with the buffer chips.
pito,
Great article, I get a lot of mail about the LC Studio card. It is one of the worst and now I have a link for replies.
Too bad the people that produce these cheap modules don't just use a buffer, in volume a 4050 SMD is $0.15.
It seems "it is the responsibility of the end user to decide on how the specific shield fits the purpose" :).
The "LC shield is ok" with 3.3V arduinos/clones. Maybe the happy users just replaced 5V regulator for 3V3 one on the arduino uno and they are happy with the LC shield now.
Frankly, I personally never had 5V system so the topics on the voltage level translators is something I do not care.. :)
It seems "it is the responsibility of the end user to decide on how the specific shield fits the purpose" smiley.
The "LC shield is ok" with 3.3V arduinos/clones. Maybe the happy users just replaced 5V regulator for 3V3 one on the arduino uno and they are happy with the LC shield now.
This is true but the seller should not claim the module works on 5 V Arduino. Most ebay ads have this statement:
Support 5V/3.3V input
Update: One trend I like, is more products are combining an SD with some other function.
Here is a module I use when I need a display and SD http://www.adafruit.com/products/358 (http://www.adafruit.com/products/358). $20 for a great 128X160 color display and SD. This type product solves the voltage problem and sharing the SPI bus.
This class product seems to generally be well designed.
@fat16lib:
My personal remark to "4050" topic (maybe worth of rising it separately):
1. I would NOT recommend to use 4050
2. 3V3 Vcc is off the 4050 spec
3. 4050 is not intended for messing with SPI signals at 8MHz (50y old gadget)
4. the rising/falling times plus prop delay is not defined at 3.3V, but I would estimate (try to extrapolate from 5V numbers) it is bigger that the 8MHz clock period at 3.3V
5. it may not harm if driving something unidirectionally with it - but you are reading the SPI with the same clock and MISO does not pass such "delay line" - so if the stuff works it is just a matter of luck
6. it originates probably from the author of 4k7/10k divider..
Worth of a measurement.. :)
None of the DIP buffers are great but the data sheets give times for 50 pf. Transition time at 4.5 V and 50 pf is 7 ns but at 2 V it is 25 ns. So what is the number for 3.3V and 15 pf?
They do work in the various modules that use them, probably due to less capacitance. Their key advantage is DIP.
I have never had a user contact me with problem with products that use them
My remark is related to "4050" - the old cmos one. The 74HCT and friends are an another story.
Thanks for clarification..
;)
Found the 4050 "fix" prototype. This is with the a 1k resistor to the 50 ohm terminator. Remember my scope is old and has a 2-3 ns rise time. I set the scope at 20 X
Wow. Thank you guys for the overnight support!
Pito, apparently the current schematic is pretty much what you've posted. I found this very picture too, but my limited knowledge doesn't let me to confirm to be the carbon copy of my current board. Seems real close, though. :smiley-sweat:
I've also got the idea of buffering, but it's probably beyond my current project, time and capabilities.
Thank you fat16lib for information, too.
Having seen the schematics and components you both recommended, though, while I agree that it's everyone's responsibility to decide what one's need to fit his/her purpose as a newbie I still hold a very straightforward unanswered question (definitively unasked :)) that I believe others might be advantaged as well:
"Which cheap and easy to be handled by software SD module would you guys recommend to start with an Arduino UNO board? Does truly the Adafruit Assembled Data Logging Shield worth those $5 more of the Arduino board itself?"
I might sound cheap, but the Raspberry PI, although a different device, seems to me a better bargain with included SD and pin in/out. Now, shoot on me :)
[for the records: the SD module has been trashed]
Here is a cheap card that seems to work. It has level shifters. I worry about sharing with other SPI devices since I think it buffers MISO and may not release MISO when chip select goes high.
http://www.ebay.com/itm/Micro-SD-Storage-Board-Mciro-SD-TF-Card-Memory-Shield-Module-SPI-For-Arduino-D9-/370990470595?pt=LH_DefaultDomain_2&hash=item5660c155c3 (http://www.ebay.com/itm/Micro-SD-Storage-Board-Mciro-SD-TF-Card-Memory-Shield-Module-SPI-For-Arduino-D9-/370990470595?pt=LH_DefaultDomain_2&hash=item5660c155c3)
If you are using only the SD on SPI is works. Some of these cards have a newer version /date so may be different.
On my way 8)
Thank you, I'll try once it gets here...
A couple of months later, and few trees planted I realized that., apparently, in my house no Arduinos are allowed to write on a SD card.
Fat16lib, I've got the "Micro SD Storage Board Mciro SD TF Card Memory Shield Module SPI For Arduino D9" as recommended, with no result other than much, much frustration.
Tried to format the card using SDformatter4, tried to format using Arduino, tried shamanic and tribal rites with no success.
What could be, for instance, the issue related to:
SD error: c,ff
upon formatting a microSD using the very standard SdFormatter provided with SdFat library?
Thanks in advance...
Edited:
This following is SdInfo printout, I might suspect the microSD to be defective.
Quite strange though, as it's apparently functional for my daily basis needs. I might invest $10 for a new one.
init time: 3 ms
Card type: SDHC
Manufacturer ID: 0X1C
OEM ID: SV
Product: USD
Version: 1.0
Serial number: 2013932036
Manufacturing date: 10/2008
readCSD failed
SD errorCode: 0X10
SD errorData: 0X3F
type any character to start
Quite strange though, as it's apparently functional for my daily basis needs.
This is can happen. SD cards function in two entirely different modes. , SPI mode and SDIO mode. 1-bit SPI mode uses a different protocol than 4-bit SDIO mode. Few people use cards in SPI mode and a few cards just don't work correctly in SPI mode.
You problem is not a formatting problem. SD error: c,ff is at the lowest SPI protocol level.
Thank you fat16lib, you're precious as always. Really.
Now I believe is just a matter of buying some other cards and test them all.
By any chance, don't you have any brand/model to recommend? (you know... just to make sure I won't go buying clueless, as I am...)
Greetings from northern Italy ;)
I Have good luck with SanDisk and Transcend micro SD cards. I don't like Kingston but I haven't tried recent cards.
Don't spend a lot on high end cards. They are optimized for the 4-bit mode of phones. Only SPI mode matters.
I use this 8 GB class 4 card www.amazon.com/gp/product/B000WH6H1M (http://www.amazon.com/gp/product/B000WH6H1M). Here is a benchmark.
Type is FAT32
File size 5MB
Buffer size 100 bytes
Starting write test. Please wait up to a minute
Write 174.54 KB/sec
Maximum latency: 303804 usec, Minimum Latency: 84 usec, Avg Latency: 567 usec
Starting read test. Please wait up to a minute
Read 310.96 KB/sec
Maximum latency: 2812 usec, Minimum Latency: 84 usec, Avg Latency: 315 usec
Here is a 4GB class 6 Transcend card http://www.amazon.com/Transcend-Class-microSDHC-Memory-TS4GUSDHC6/dp/B0013DXVYK/ (http://www.amazon.com/Transcend-Class-microSDHC-Memory-TS4GUSDHC6/dp/B0013DXVYK/). This is an old card so you may want to buy a newer class 10 card.
Here are performance numbers
Type is FAT32
File size 5MB
Buffer size 100 bytes
Starting write test. Please wait up to a minute
Write 201.74 KB/sec
Maximum latency: 197332 usec, Minimum Latency: 84 usec, Avg Latency: 490 usec
Starting read test. Please wait up to a minute
Read 308.20 KB/sec
Maximum latency: 2888 usec, Minimum Latency: 84 usec, Avg Latency: 318 usec
I plan on trying this card http://www.amazon.com/Transcend-Class-microSDHC-Memory-TS16GUSDHC10/dp/B004TA0AZM (http://www.amazon.com/Transcend-Class-microSDHC-Memory-TS16GUSDHC10/dp/B004TA0AZM) in 8 and 16 GB.
Here is the result for a 4 GB class 4 micro SD Kingston card..
Type is FAT32
File size 5MB
Buffer size 100 bytes
Starting write test. Please wait up to a minute
Write 70.97 KB/sec
Maximum latency: 188880 usec, Minimum Latency: 84 usec, Avg Latency: 1403 usec
Starting read test. Please wait up to a minute
Read 210.81 KB/sec
Maximum latency: 4472 usec, Minimum Latency: 84 usec, Avg Latency: 468 usec
I worry that the problem may not be your micro SD card. It is very rare for a card to work in 4-bit mode and fail in SPI mode.
To make things clear, I'd rather plant a tree other than playing with these tiny cards :) but, being the nowaday world quite techie, I have to face the inevitable and deal with these matters time to time :~
Card reader is NOW:
http://item.taobao.com/item.htm?spm=a1z10.1.w4004-3029786962.14.e9DiMp&id=19306030373
sorry for the specs in chinese.
while the tested card is a Transcend MicroSD class 4, 8GB.
For the records, the above configuration apparently does NOT the job.
Might the Force be with you.
Please, PLEASE, wish me the same :) :)
Here is a photo of a Catalex breakout with a 4 GB class 4 Transcend micro SD. Red and black to 5V and gnd.
White pin 13, blue pin 12, yellow pin 11, and green pin 10.
Here is SdInfo output with no mods to the sketch.
SdFat version: 20131225
type any character to start
init time: 756 ms
Card type: SDHC
Manufacturer ID: 0X74
OEM ID: JE
Product: USD
Version: 1.0
Serial number: 168927237
Manufacturing date: 4/2011
cardSize: 4035.97 MB (MB = 1,000,000 bytes)
flashEraseSize: 128 blocks
eraseSingleBlock: true
SD Partition Table
part,boot,type,start,length
1,0X0,0XB,8192,7874560
2,0X0,0X0,0,0
3,0X0,0X0,0,0
4,0X0,0X0,0,0
Volume is FAT32
blocksPerCluster: 64
clusterCount: 122912
freeClusters: 121151
freeSpace: 3969.88 MB (MB = 1,000,000 bytes)
fatStartBlock: 14462
fatCount: 2
blocksPerFat: 961
rootDirStart: 2
dataStartBlock: 16384
type any character to start
Uh fat16lib, thank you!
First at all, congratulations for the picture, very well taken. You're probably an enthusiast photographer as well.
As for my setup, while at first failing on the pin 10 connection (WAS mistakenly wired to pin number 4) is NOW perfectly resembling your* and, not surprisingly, it finally works!
(*) Except for colors, but Arduino works on a 10bit basis, and I assume it will see on gray levels anyway :)
So, shame on me but good to be reported for further references, and to make sure no one will be stressed on the same point.
1. Card readers have to be buffered. Don't ask me why, but make sure there's a little extra component between an Arduino port and the microSD card whatsoever. Spare much frustration and get that reader.
2. IF you connect your microSD board straight onto Arduino, pin have to be 10-11-12-13 while some examples specifically set pin 4 as chipSelect (ReadWriteSdFat is among those). Forget pin number 4, that's apparently to be used with some other shields on the way; make sure to connect 10~13, set up the code properly and off you go.
3. Have a beer.