Tuesday, May 21, 2013

Logging to an SD Card with Arduino - the Hardware

The Arduino can make a lot of readings every second.  If you want to do some complicated processing with those observations you will be limited by the speed of the processor.  You can upload them in real time via the serial interface, or an add-on shield doing WLAN or Bluetooth.  If you want to run disconnected, logging to an SD Card could be the solution.  I don't have shields for either WLAN or Bluetooth but I suspect that logging to an SD Card would be the faster of the logging strategies.

In any case, I bought one for three quid from eBay now available even cheaper on Amazon!   The one that I bought is not integrated into a shield and so requires a little wiring...but it was cheap!  SD Cards use SPI, or Serial Peripheral Interface, to communicate.   This is provided on the Uno by pins 11, 12, and 13.   On the Mega it will be 50, 51, and 52.  The pin connections that are needed are shown below and by the included pictures:

SD Card
Breakout Pin
Function Arduino Pins -
Uno / Mega
Comments
GND Ground GND Only one ground is needed
+3.3 Power on 3.3v system +3.3 Only one power source is needed
+5 Power on a 5v system +5
CS Chip Select 10 or 53 This pin may wander while the lower three are confined to where the board puts SPI.  Make sure your sketch reflects the right pin!
MOSI (sometimes called DO) Master Output - Slave Input 12 or 50
SCK (sometimes call CLK) System Clock 13 or 52
MISO (sometimes called I) Master Input - Slave Output 11 or 51
GND Ground Ground

There is also a Card Detect pin on some cards (though not mine). It shorts to ground when a card is inserted. You should connect a pull up resistor (10K or so) and wire this to another pin if you want to detect when a card is inserted.


The testbed shown above consists of an Arduino Uno with a Keypad LCD Shield riding on a handy Screwshield Terminal Expansion Board for the Uno.  The SD Card is pretty power hungry, as is the LCD, so we are connected to a wall power dongle.   The breadboard in the foreground has a variable resistor as part of a voltage dividing circuit so I can vary my "readings" for test purposes.

In my next post I will talk about the software.

1 comment:

  1. Nice blog and the content seems very useful about cheap sd cards devices. The blog is really very helpful. Thanks for sharing such informative post.

    ReplyDelete