Forum Rule: Always post complete source code & details to reproduce any issue!
Page 1 of 4 1 2 3 ... LastLast
Results 1 to 25 of 88

Thread: Teensy 3 MicroSD guide

  1. #1
    Senior Member ZTiK.nl's Avatar
    Join Date
    Dec 2012
    Location
    Amsterdam
    Posts
    179

    Teensy 3 MicroSD guide

    Hello everybody,

    I had some problems connecting/using the MicroSD adapter from PJRC with my Teensy 3.0 so I decided to make a small guide about it.
    First off, I am new to all this, so any corrections/tips/criticism is welcome


    The very first thing to do is solder the 3V pads on the bottom of the MicroSD adapter.
    This is because Teensy 3 = 3.3v, while other/older Teensy's are 5v.
    The MicroSD adapter can work at both voltages, all that is required is to connect 2 pads together to set it to 3.3v:
    Name:  sd_adaptor_bottom.jpg
Views: 30769
Size:  18.2 KB

    Here is my attempt (my first soldering ever!):
    Click image for larger version. 

Name:	MicroSD solder 3v pads together.jpg 
Views:	1808 
Size:	343.2 KB 
ID:	176


    After this has been done, you can start connecting the adapter to the Teensy.
    At this point I ran into some trouble until I found a post by pixelk explaining it quite well, thanks pixelk !

    Connections on the MicroSD adapter:
    Name:  sd_adaptor_pins.jpg
Views: 30083
Size:  11.5 KB
    +5V goes to 3.3V (100 mA max)
    Ground goes to GND
    MOSI goes to pin 11, DOUT
    MISO goes to pin 12, DIN
    SCLK goes to pin 13, SCK
    SS goes to pin 10, CS

    MicroSD wired up to Teensy:
    Click image for larger version. 

Name:	MicroSD connections to Teensy3.jpg 
Views:	3348 
Size:	96.7 KB 
ID:	178
    +5V goes to 3.3V (red wire)
    Ground goes to GND (black wire)
    MOSI goes to pin 11 (blue wire)
    MISO goes to pin 12 (green wire)
    SCLK goes to pin 13 (white wire)
    SS goes to pin 10 (yellow wire)

    Additional warning, with thanks to LarryP:
    When you connect the MicroSD adapter to the Teensy, take into account which direction the MicroSD card holder is facing!
    Take another look at the image above to make sure

    Once you have done this, you should be able to run the cardinfo example.
    Dont forget to set your Teensy to Serial and to set the ChipSelect variable in cardinfo example to 10 instead of 4.

    Code:
    Initializing SD card...Wiring is correct and a card is present.
    
    Card type: SDHC
    
    Volume type is FAT32
    
    Volume size (bytes): 3519021056
    Volume size (Kbytes): 3436544
    Volume size (Mbytes): 3356
    
    Files found on the card (name, date and size in bytes): 
    BENCH.DAT     2000-01-01 01:00:00 5000000

    To test all this I bought a spanking new MicroSD card, but I kept getting errors during initializing SD card.
    After a lot of checking code and rechecking my connections, I 'obtained' a MicroSD card from my mothers HTC mobile phone, and suddenly the cardinfo example started working automagically.

    In case you run into trouble during init phase, try another card, it seems not all are created equal.
    For what it is worth, the first MicroSD I used was a 2GB non-HC by Icidu, the one that did work was a Kingston SDHC 8gb.

    Additional tip with thanks to linuxgeek:
    If you are able to read but not write (or experience any similar issues), try to format the SD card using the SdFat SdFormatter example.

    This should be enough for this firstpost, in the next one I'll post a few benchmarks and how I improved read/write speed with a factor 10x !
    Last edited by ZTiK.nl; 03-06-2013 at 07:36 PM. Reason: added quote concerning orientation

  2. #2
    Senior Member ZTiK.nl's Avatar
    Join Date
    Dec 2012
    Location
    Amsterdam
    Posts
    179
    One of the things I was eager to try was a benchmark tool for MicroSD i read about on a few forums.
    It is included in the SdFat library two times, the first is benchSD.ino and this uses default libraries, the second is bench.ino which makes use of the new SdFat library itself.

    Download the SdFat file here, and extract the SdFat folder to your \arduino-1.0.x\libraries

    (re)start your Teensyduino and load the benchSD.ino.
    Since the first example takes a while, it is wise to shrink the size of the testfile to 0.2 (200KB)
    Upload the example and start the Serial Monitor

    benchSD.ino
    Code:
    Type any character to start
    File size 0.20MB
    Buffer size 100 bytes
    Starting write test.  Please wait up to a minute
    Write 12.68 KB/sec
    Maximum latency: 147815 usec, Minimum Latency: 17 usec, Avg Latency: 7830 usec
    
    Starting read test.  Please wait up to a minute
    Read 14.35 KB/sec
    Maximum latency: 69960 usec, Minimum Latency: 18 usec, Avg Latency: 6965 usec
    
    Done
    
    Type any character to start
    -----------------------------------------------
    Type any character to start
    File size 0.20MB
    Buffer size 500 bytes
    Starting write test.  Please wait up to a minute
    Write 12.65 KB/sec
    Maximum latency: 147922 usec, Minimum Latency: 59 usec, Avg Latency: 39236 usec
    
    Starting read test.  Please wait up to a minute
    Read 14.37 KB/sec
    Maximum latency: 69947 usec, Minimum Latency: 68 usec, Avg Latency: 34802 usec
    
    Done
    
    Type any character to start
    -----------------------------------------------
    Type any character to start
    File size 0.20MB
    Buffer size 1000 bytes
    Starting write test.  Please wait up to a minute
    Write 12.68 KB/sec
    Maximum latency: 207257 usec, Minimum Latency: 37806 usec, Avg Latency: 78297 usec
    
    Starting read test.  Please wait up to a minute
    Read 14.38 KB/sec
    Maximum latency: 105011 usec, Minimum Latency: 35003 usec, Avg Latency: 69536 usec
    
    Done
    
    Type any character to start
    read 14KB/s, write 12KB/s, with a 200KB testfile and buffersize 100/500/100

    Now lets make use of the new and improved SdFat library

    bench.ino:
    Code:
    Type any character to start
    Free RAM: 10691
    Type is FAT32
    File size 5MB
    Buffer size 100 bytes
    Starting write test.  Please wait up to a minute
    Write 147.78 KB/sec
    Maximum latency: 174475 usec, Minimum Latency: 10 usec, Avg Latency: 675 usec
    
    Starting read test.  Please wait up to a minute
    Read 517.01 KB/sec
    Maximum latency: 1834 usec, Minimum Latency: 9 usec, Avg Latency: 191 usec
    
    Done
    
    Type any character to start
    -----------------------------------------------
    
    Type any character to start
    Free RAM: 10291
    Type is FAT32
    File size 5MB
    Buffer size 500 bytes
    Starting write test.  Please wait up to a minute
    Write 150.13 KB/sec
    Maximum latency: 161796 usec, Minimum Latency: 19 usec, Avg Latency: 3328 usec
    
    Starting read test.  Please wait up to a minute
    Read 534.76 KB/sec
    Maximum latency: 1820 usec, Minimum Latency: 19 usec, Avg Latency: 933 usec
    
    Done
    
    Type any character to start
    -----------------------------------------------
    
    Type any character to start
    Free RAM: 9791
    Type is FAT32
    File size 5MB
    Buffer size 1000 bytes
    Starting write test.  Please wait up to a minute
    Write 150.74 KB/sec
    Maximum latency: 323792 usec, Minimum Latency: 1841 usec, Avg Latency: 6630 usec
    
    Starting read test.  Please wait up to a minute
    Read 542.77 KB/sec
    Maximum latency: 2872 usec, Minimum Latency: 794 usec, Avg Latency: 1840 usec
    
    Done
    
    Type any character to start
    read 150 KB/s, write 530 KB/s, with a 5MB testfile and buffersize 100/500/100

    Extra info: I ran these tests at 48MHz CPU speed
    Last edited by ZTiK.nl; 01-22-2013 at 04:28 PM. Reason: added CPU speed

  3. #3
    Senior Member ZTiK.nl's Avatar
    Join Date
    Dec 2012
    Location
    Amsterdam
    Posts
    179
    same test as before (bench.ino), but at 96MHz:
    Code:
    Type any character to start
    Free RAM: 8791
    Type is FAT32
    File size 5MB
    Buffer size 2000 bytes
    Starting write test.  Please wait up to a minute
    Write 261.78 KB/sec
    Maximum latency: 614550 usec, Minimum Latency: 2225 usec, Avg Latency: 7611 usec
    
    Starting read test.  Please wait up to a minute
    Read 875.96 KB/sec
    Maximum latency: 3996 usec, Minimum Latency: 1202 usec, Avg Latency: 2282 usec
    
    Done
    
    Type any character to start
    ------------------------------------------------------
    Type any character to start
    Free RAM: 6695
    Type is FAT32
    File size 5MB
    Buffer size 4096 bytes
    Starting write test.  Please wait up to a minute
    Write 762.34 KB/sec
    Maximum latency: 881809 usec, Minimum Latency: 3088 usec, Avg Latency: 5364 usec
    
    Starting read test.  Please wait up to a minute
    Read 1720.77 KB/sec
    Maximum latency: 3370 usec, Minimum Latency: 2178 usec, Avg Latency: 2378 usec
    
    Done
    
    Type any character to start
    I am definately happy with these results

  4. #4
    Senior Member ZTiK.nl's Avatar
    Join Date
    Dec 2012
    Location
    Amsterdam
    Posts
    179
    The maximum I can get out of it, also, the speed is quite stable

    Code:
    Type any character to start
    Free RAM: 551
    Type is FAT32
    File size 5MB
    Buffer size 10240 bytes
    Starting write test.  Please wait up to a minute
    Write 1070.05 KB/sec
    Maximum latency: 808693 usec, Minimum Latency: 5349 usec, Avg Latency: 9398 usec
    
    Starting read test.  Please wait up to a minute
    Read 2069.20 KB/sec
    Maximum latency: 6355 usec, Minimum Latency: 4556 usec, Avg Latency: 4949 usec
    
    Done
    
    Type any character to start
    ------------------------------------------------------
    Type any character to start
    Free RAM: 551
    Type is FAT32
    File size 25MB
    Buffer size 10240 bytes
    Starting write test.  Please wait up to a minute
    Write 1311.09 KB/sec
    Maximum latency: 915084 usec, Minimum Latency: 5350 usec, Avg Latency: 7805 usec
    
    Starting read test.  Please wait up to a minute
    Read 2036.65 KB/sec
    Maximum latency: 6852 usec, Minimum Latency: 4543 usec, Avg Latency: 5026 usec
    
    Done
    
    Type any character to start
    ------------------------------------------------------
    Type any character to start
    Free RAM: 551
    Type is FAT32
    File size 250MB
    Buffer size 10240 bytes
    Starting write test.  Please wait up to a minute
    Write 1392.32 KB/sec
    Maximum latency: 74300 usec, Minimum Latency: 5345 usec, Avg Latency: 7353 usec
    
    Starting read test.  Please wait up to a minute
    Read 1999.34 KB/sec
    Maximum latency: 6922 usec, Minimum Latency: 4539 usec, Avg Latency: 5120 usec
    
    Done
    
    Type any character to start

  5. #5
    Senior Member Wozzy's Avatar
    Join Date
    Jan 2013
    Location
    Philadelphia, Pennsylvania USA
    Posts
    307
    ZTiK.nl

    First, Thanks again for the SD card tutorial. I was able to use it to get mine up and running quickly.
    It probably would have worked the first time for me...
    but it took me a while to realize that the power bus strips in my breadboard were not continuous over the full length.

    As for the SDfat library,
    That's pretty impressive... over 2GBytes / second read speed. <Correction: over 2MBytes / second read speed.
    I'm definitely going to try out this library.
    What is the difference, between the different cases that you ran? Is it just the buffer size?

    Thanks,
    Bob W.
    Last edited by Wozzy; 01-25-2013 at 01:07 AM. Reason: Correct Error

  6. #6
    Senior Member ZTiK.nl's Avatar
    Join Date
    Dec 2012
    Location
    Amsterdam
    Posts
    179
    No problem at all, sorry for the inconvenience of it suddenly disappearing :x
    I wasn't aware that there were breadboards where the power lines are not continuous, learned something new as well...

    A small correction concerning the read speed, its +/- 2MB/s, not GB/s !
    Hope you still find it impressive :)

    The differences in my testcases:
    -The very first test was benchSD.ino which uses default arduino libraries
    200KB testfile, buffersizes 100/500/1000, Teensy @ 48MHz (12/14 KB/s)

    -The second test was bench.ino which uses the new SdFat libraries
    5MB testfile, buffersizes 100/500/1000, Teensy @ 48MHz (150/530 KB/s)

    -The third test was also bench.ino
    5MB testfile, buffersizes 2000/4096, Teensy @ 48MHz (200+/870+ KB/s)

    -The fourth/last test was also bench.ino
    5/25/250MB testfile, buffersize 10240, Teensy @ 96MHz (1350/2000 KB/s)
    Last edited by ZTiK.nl; 01-22-2013 at 10:25 PM. Reason: typo, buffersizes 100/500/1000 not 100/500/100

  7. #7
    Senior Member Wozzy's Avatar
    Join Date
    Jan 2013
    Location
    Philadelphia, Pennsylvania USA
    Posts
    307
    Oh yes... I'm not sure what I was thinking....2MB/Sec is still plenty fast for my application.

    Thanks for the additional information... I'll give it a try later tonight

  8. #8
    Senior Member ZTiK.nl's Avatar
    Join Date
    Dec 2012
    Location
    Amsterdam
    Posts
    179
    No problem at all
    I've seen other people post benchmarks a little higher than the 2MB/s I was able to get, but I think that was due to HQ SDcards, mine are simple 'non-industrial grade' from the local electronics-store.
    link to other benchmarks

  9. #9
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    15,943
    Thanks for writing this! I've added a link on the SD Adaptor page.

  10. #10
    Senior Member ZTiK.nl's Avatar
    Join Date
    Dec 2012
    Location
    Amsterdam
    Posts
    179
    Simply paying back for all the things I've been given

    I should be thanking you for giving us such a wonderful product and support most people can only dream of!
    Last edited by ZTiK.nl; 01-25-2013 at 05:22 AM.

  11. #11
    Junior Member
    Join Date
    Oct 2012
    Posts
    16
    @ZTiK.nl,

    Thank you for taking the time and effort to put together your Teensy 3 MicroSD guide!
    Having that really helped me get my SD_Card working with a Teensy3. Should you ever find yourself in the Boston area, I owe you beer.

    A caution to people wiring up one of PJRC's microSD adaptors for the first time:
    before applying power, double check the orientation of the adaptor, particularly with respect to which end of the adaptor the card slides into. I mistakenly assumed (without thinking about it enough) that the soldered connections to the card's socket must be opposite the side that the card slides into -- and wired it up wrong, coming closer than I'd like to damaging it.

    @Paul,
    If you revise the SD Adaptor pin diagram, you might add an arrow showing which side the card goes into.

    Thanks again ZTiK.nl !

  12. #12
    Senior Member ZTiK.nl's Avatar
    Join Date
    Dec 2012
    Location
    Amsterdam
    Posts
    179
    @LarryP: Free beer, woohoo!
    Like I said before, nothing worth mentioning, it was just gathering information that was already available.

    I've quoted your cautionary text in the initial post, so that others should be able to read it during the connecting, not afterwards!

    @BambooSam: I'm sorry, but I am not able to answer your question personally.
    By looking at the pinout diagram I would think you are right, and are referring to usable pins, only I cannot explain why the SPI description on these ports appears 'greyed out' on the pinout diag

    On the other hand, it should be easy for me to test it, just switch a few wires and see if the example still runs, to be continued...

  13. #13
    Senior Member ZTiK.nl's Avatar
    Join Date
    Dec 2012
    Location
    Amsterdam
    Posts
    179
    I tried to connect the MicroSD using the pins you supplied (while using the fast library, not the default slow one), but cannot get it working myself:

    I have changed line 12 in SoftSPI.h to:
    Code:
    template<uint8_t MisoPin = 8, uint8_t MosiPin = 7, uint8_t SckPin = 14, uint8_t Mode = 0>
    along with the CS pin in the example itself, but I keep receiving the following error:

    Code:
    Type any character to start
    Free RAM: 551
    Can't access SD card. Do not reformat.
    No card, wrong chip select pin, or SPI problem?
    SD errorCode: 0X1,0X0
    edit:
    Just noticed you also found thread Reassigning a pin (SPI SCK), if/when you get a solution, please post it/PM me, then I will add it to the first post.
    Last edited by ZTiK.nl; 01-30-2013 at 12:08 AM.

  14. #14
    Will do

  15. #15
    Senior Member ZTiK.nl's Avatar
    Join Date
    Dec 2012
    Location
    Amsterdam
    Posts
    179
    Something I read that could be considered useful:
    When a device's Slave Select pin is low, it communicates with the master. When it's high, it ignores the master. This allows you to have multiple SPI devices sharing the same MISO, MOSI, and CLK lines.
    quote from arduino.cc SPI reference

    This makes me believe that switching during runtime is not the way forward, but to keep them connected to the same pins and let the SS (Slave Select) decide which device is currently being read/written.
    Again, I have a very limited understanding of these matters, so I could be mistaken here...

  16. #16
    Yeah that would be the best way to go about it, but my issue is that the led strips ONLY use Mosi and SCK, it doesn't use a select pin - (fastSPI).

    Even easier: I am still new to electronics but is there an ic that can be used to switch the data line and stream it? and use a digital pin to toggle the sd and lpd8806?

    (I am going to move this issue into another thread)
    Last edited by BambooSam; 01-30-2013 at 07:24 PM.

  17. #17
    Senior Member ZTiK.nl's Avatar
    Join Date
    Dec 2012
    Location
    Amsterdam
    Posts
    179
    There is another update to the SdFat library

  18. #18
    Member
    Join Date
    Feb 2013
    Location
    Kansas City, Misery
    Posts
    43
    Thanks for writing this up. Came in very handy and got me right up and running.

  19. #19
    Senior Member ZTiK.nl's Avatar
    Join Date
    Dec 2012
    Location
    Amsterdam
    Posts
    179
    More than welcome, glad I did something useful for a change ;)

  20. #20
    Senior Member
    Join Date
    Feb 2013
    Posts
    153
    I have recently purchased this card and on reading about data logging it keeps saying that the SD card needs a lot of current while working. Can I hook this up and just use the usb power without any issues. I also have 2 optical slotted encoders hooked up to the teensy 3 that use 10mA each, which I am getting the power from the Vin pin. If it is an issue, how would I supply enough current to reduce this issue. Thanks in advance.

  21. #21
    Senior Member ZTiK.nl's Avatar
    Join Date
    Dec 2012
    Location
    Amsterdam
    Posts
    179
    Good question!

    As much as I want to tell you, I simply do not know

    I wouldn't expect the MicroSD to use 80mA while active though, sounds like quite a lot.
    The multimeter I ordered still has not arrived because another item in my order is currently out of stock, so I have no way to actually test usage during idletime/heavy use at the moment.



    Since I started my project I have been using a separate 3.3v+5v usb powersupply for all my modules with the exception of my speaker & MicroSD.
    -The speaker uses a digital pin along with GND and the MicroSD adapter is the only thing connected on the 3.3v out pin.
    -Then I have my TFT/GPS/Microphone/Humidity&Temp. sensor all powered by the 3.3v external power supply.

    Click image for larger version. 

Name:	powerconnections.jpg 
Views:	934 
Size:	78.3 KB 
ID:	256
    The powersupply is connected to the right-side (top in image) powerstrips with 5v, and with jumpers running from below the led all the way to the left-side powerstrip with 3.3v.
    (So far I have no devices on the 5v yet, but this will change soon I hope)


    I do hope someone is able to answer this question because I would like to know as well, and I don't know when I will be able to check myself :x

  22. #22
    Junior Member
    Join Date
    Nov 2012
    Posts
    16
    Off the top of my head I think the SD card spec says it should be 0.5mA in standby and 45mA max during 50MHz read or write. At 25MHz current draw is about half that. I have heard real world numbers of as high as 80mA during a read/write. Low quality cards probably.

    So how much the current draw over time really is depends on how how much time you spend doing each type of operation. So if you are continually reading/writing you use a lot of current. If you do a write once per minute you are probably good for a long time.

  23. #23
    Senior Member
    Join Date
    Feb 2013
    Posts
    153
    For my application I will be writing around 90-120 samples per minute for up to 3 hours continuous. So I will guess it will working pretty hard. This is my first teensy and well new to most of this, so I am wondering if I will need some sort of external power. If I do, do I cut that pad off and then just feed my new 5v supply into Vin and ground-ground?

  24. #24
    Junior Member
    Join Date
    Nov 2012
    Posts
    16
    If you are running for only 3 hours you should be able to power things without a problem. A set of plain old generic AA batteries fresh from the package should provide 400mAh or more. So even if your circuit draws 100mA on average you can run for 4+ hours. With better batteries such as good quality NiMH batteries you can get 1000 to 3000 mAh.

  25. #25
    Junior Member
    Join Date
    Feb 2013
    Posts
    10
    Hi!
    Just out of curiosity:
    Since Teensy 3 is 3.3V native, would it be possible to connect the microSD slot directly to its pins, without the 74cx125?
    If so, is there any downside to it?

    Thanks!

    Maujabur

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •