Pages: [1]   Go Down
Author Topic: Newbie problem with SD card, need guidance  (Read 886 times)
0 Members and 1 Guest are viewing this topic.
Ontario, Canada
Offline Offline
Jr. Member
**
Karma: 1
Posts: 55
Arduino, what a good excuse to really dig into electronics!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

Basically I want to know if I am headed in the right direction or am I screwing up right off the bat?

I bought 2 SD card reader modules from ebay
http://www.ebay.ca/itm/400497455183?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649

I connected the reader as per the diagram on the seller's product page. (see attached pic)

I understand that it is using the resistors as a voltage divider to supply 3.3V to the inputs of the SD card. I read on some articles that you need to supply 3.3 V inputs (MOSI, CS, CLK) or you can burn your card.
I measured the voltage level going into the card on some of those pins and it is 3.3V
The diagram says to use 3.3k with 1.8k on MOSI and CS, 1k with 2.2k with SCK. I did not have exactly those so I used 1.5k and 3k everywhere which gives me the almost exact 3.3V as mentionned above.

I am using pin 10 for slave select, reflected in my code.
I know some people have used a level shifter instead for this in certain articles.

The setup section fails on init, I tried 2 cards on it.
I checked my wiring, and I find nothing wrong with it so far.
I still have some troubleshooting  to do, but want to know if this setup has a shot at working or not.


Code:
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <SD.h>

#define I2C_ADDR 0x27
#define BACKLIGHT_PIN 3
#define En_Pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7

int BTN1_pin = 4;
int LED_1_pin = 13;
int SD_SS_pin = 10;

byte BTN_Val, PREV_BTN_Val = LOW;
int num_pressed=0;

File myFile;

LiquidCrystal_I2C lcd (I2C_ADDR, En_Pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin);
void setup()
{
 
  Serial.begin(9600);
 
  pinMode(BTN1_pin, INPUT);
  pinMode(LED_1_pin, OUTPUT);
  digitalWrite(LED_1_pin, LOW);
 
  lcd.begin(20,4);
  lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.home();
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("SD Test");
  //lcd.setCursor(0,1);
  //lcd.print("Button to work");
  //delay(2000);
 
  delay(4000);
 
 
  Serial.print("Initializing SD card...");
  pinMode(10, OUTPUT);
 
  if (!SD.begin(SD_SS_pin)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done."); 
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("test.txt", FILE_WRITE);
 
  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println("testing 1, 2, 3.");
    // close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
 
  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");
   
    // read from the file until there's nothing else in it:
    while (myFile.available()) {
        Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }

 

 




}




void loop()
{
 
  //lcd.clear();
  //lcd.setCursor(0,1);
  //lcd.print(ii++,DEC);
  //lcd.setBacklight(LOW);
  //delay(3000);
  //lcd.setBacklight(HIGH);
  //delay(3000);
 
  if ( BTN_Val == HIGH && PREV_BTN_Val == LOW )
  {
    delay(25);
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Send #");
    lcd.print(++num_pressed,10);


     // tx msg
    //startM = millis();
   
  }
 
  PREV_BTN_Val = BTN_Val;
  //delay(1000);
 
 
 
 
}





* stepping_down_outputs_to_3.3v.png (31.23 KB, 508x541 - viewed 31 times.)
Logged

Arduino, what a good excuse to really dig into electronics!

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 525
Posts: 26493
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Does the SD module have a 3.3V regulator on it for power?
(I can't open the link from here)
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Ontario, Canada
Offline Offline
Jr. Member
**
Karma: 1
Posts: 55
Arduino, what a good excuse to really dig into electronics!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes it does have a 3.3V regulator, but that is for its operating voltage as far as I understand, but the inputs coming from the MCU are 5V and those, the card does not regulate. This is what I read so far is the issue.

Logged

Arduino, what a good excuse to really dig into electronics!

Offline Offline
Edison Member
*
Karma: 64
Posts: 2488
The last thing you did is where you should start looking.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is the SD card formatted?
Quote
For the Arduino library we'll be discussing, and nearly every other SD library, the card must be formatted FAT16 or FAT32.

http://www.ladyada.net/products/microsd/#formatting_notes
Logged

Ontario, Canada
Offline Offline
Jr. Member
**
Karma: 1
Posts: 55
Arduino, what a good excuse to really dig into electronics!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

Found one problem, I could not get it to work with my arduino mini. Tried my uno and a 128m card and it worked fine, but a 1gig sd micro card with sd adapter never worked.

Based on the good ladyada article, I need a logic level converter to get it to work properly I think. That or get a better card reader. What do you expect for a 2$ sd card reader module? Resistor dividers are clearly nfot ideal for that setup according to the article.

Adafruit's reader has a logic level converter.

Is looking at it this way good?: as long as you know exactly what you are getting, ebay is fine?


Logged

Arduino, what a good excuse to really dig into electronics!

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7171
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I never buy those cheap ones. What if it stops working when you're saving important data (like temperature of your bathroom smiley-wink )

There are many resistors on the board. I can't see their markings but suspect they each connect to an SPI pin to prevent damage. If you want reliable results, use level shifters. Adafruit sells an sd module for like $15 (I know it's expensive). I use their sd logger shields. Didn't seem to have failed yet. I have dozen of them.
Logged


Ontario, Canada
Offline Offline
Jr. Member
**
Karma: 1
Posts: 55
Arduino, what a good excuse to really dig into electronics!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My understanding is that the adafruit one does not need a level shifters as they are built in.

Are you saying that mine will be fine with some level shifters?

I will be more careful about ebay stuff now that I am starting to learn. Easy to make those mistakes if you don't know smiley

Logged

Arduino, what a good excuse to really dig into electronics!

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7171
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Right, adafruit modules have level shifters. Yours doesn't have. There's no circuit diagram so I can't say for sure what's on your board. I guess if you use a level shifter it will work fine.
Logged


Pages: [1]   Go Up
Jump to: