sd with serial communication, how do?

hi
I have find this (bottom) Sd card reader but it work with serial communication, I try it but don't work, someone can help me

regards
stefano

SD_UserManual.pdf (799 KB)

I try it but don't work, someone can help me

Not likely. You haven't posted any code. You haven't described how that reader is connected. You haven't said what expect the code you have to do, or what it actually does. You haven't described what is on the card, and whether you are trying to read from it or write to it.

There is so much missing from your post that it is impossible to help you.

ok
in the arduino's playground/storage I read SD reader examples with spi communication only and library about this, with serial communication can I use the statements's file (bottom)

thanks
stefano

with serial communication can I use the statements's file (bottom)

I'm not sure that I understand the question. You won't be able to use the SD library to communicate with your reader, since the SD library expects to use SPI to talk to the SD reader, and yours will not respond to SPI pin wiggling.

There are commands in the pdf file that you linked that let you communicate with the device. Presuming that the device is connected to the same pins that the Serial instance is talking to.

hi
this SD work with RX TX not SPI, then I am not sure I can use statements's file (bottom)

thanks
stefano

can I use the statements's file (bottom)

I am not sure I can use statements's file (bottom)

What 'statements's file (bottom)'? What does that mean?

hi
this is the sketch and file attachments

#include <SoftwareSerial.h>
SoftwareSerial mySerial(2,3);

void setup()  
{
  Serial.begin(9600);
  Serial.println("Goodnight moon!");

   mySerial.println("mode /m \r\n");
    if (mySerial.available())
    Serial.println((char)mySerial.read());
    
  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
}

void loop() // run over and over
{    
 mySerial.println("init \r\n");
 if (mySerial.available())
    Serial.println((char)mySerial.read());
    
  mySerial.println("fcreate test.txt \r\n");
  if (mySerial.available())
    Serial.println((char)mySerial.read());
 
}

thanks
stefano

SD_UserManual.pdf (799 KB)

You start by trying read and write to/from mySerial before the mySerial.begin().

   mySerial.println("mode /m \r\n");
    if (mySerial.available())
    Serial.println((char)mySerial.read());
    
  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);

Then you repeatedly initialise the card and open a new zero byte file.

void loop() // run over and over
{    
 mySerial.println("init \r\n");
 if (mySerial.available())
    Serial.println((char)mySerial.read());
    
  mySerial.println("fcreate test.txt \r\n");
  if (mySerial.available())
    Serial.println((char)mySerial.read());
 
}

I'll assume you have the card reader connected correctly to pins 2 and 3, and that the 5v and ground connections are correct. What are you getting back, if anything, in the serial monitor?

You do have the card formatted as fat16?

You start by trying read and write to/from mySerial before the mySerial.begin().

ops

I'll assume you have the card reader connected correctly to pins 2 and 3, and that the 5v and ground connections are correct. What are you getting back, if anything, in the serial monitor?

yes card reader connected correctly this is the new sketch

#include <SoftwareSerial.h>
SoftwareSerial mySerial(2,3);

void setup()  
{
  Serial.begin(9600);  // set the data rate for the Serial port
    mySerial.begin(9600);  // set the data rate for the SoftwareSerial port
  delay(50);
  Serial.println("Goodnight moon!");

   mySerial.println("mode /m \r\n");
   delay(50);
    if (mySerial.available())
    {
    Serial.println(mySerial.read());
    } 
}

void loop() 
{    
 mySerial.println("init\r\n");
 delay(50);
 
 while(mySerial.available())
  {
    Serial.println(mySerial.read());
  }  
 
  mySerial.println("fcreate test3.txt\r\n");
  delay(50);
  
 while(mySerial.available())
  {
    Serial.println(mySerial.read());
  }
  
  while(true){}
}

test3.txt is created and this is the output

Goodnight moon!
53
189
145
149
233
129
106
26
170
133
52
171
11
139
171
11
82
171
107
215
87
214
86
86
82
72
248
49
69
50
48

have you any idea?

thanks
stefano

 while(mySerial.available())
  {
    Serial.println(mySerial.read());
  }  
 
  mySerial.println("fcreate test3.txt\r\n");
  delay(50);

With this code you are sending "fcreate test3.txt" for every character recieved over mySerial. Is this really what you want to do?

 while(mySerial.available())
  {
    Serial.println(mySerial.read());
  }

You then exit the first loop when mySerial.available() returns false and enter try and enter the second loop above expecting mySerial.available() to return something different.

Can you explain what you are tyring to achieve, then maybe someone will be able to give you more helpful advice?

hi
I want read end write a SD card with serial communication, arduino use SPI only, see file attachment

this is the sketch

#include <SoftwareSerial.h>
SoftwareSerial mySerial(5,4);// pin 5 RX pin 4 TX
#include <String.h>

void setup()  
{
  Serial.begin(9600);  // set the data rate for the Serial port
    mySerial.begin(9600);  // set the data rate for the SoftwareSerial port
  delay(50);
  Serial.println("Goodnight moon!");
/*
mySerial.print("baud 9600 \r\n");
   delay(50);
    if (mySerial.available())
    {
    Serial.println(mySerial.read());
    } 
    */
   mySerial.println("mode /m");
   delay(50);
    while (mySerial.available())
    {
    Serial.println(mySerial.read());
    }
   mySerial.println("init");
 delay(50);
 
 while(mySerial.available())
  {
    Serial.println(mySerial.read());
  }  
}
 


void loop() 
{  
  mySerial.print("fcreate test.txt\r\n");
  delay(50);
  
 while(mySerial.available())
  {
    Serial.println(mySerial.read());
  } 
 
  while(true){}
}

and this is the output

Goodnight moon!
62
77
111
100
101
58
32
77
67
85
40
115
105
109
112
108
101
32
109
101
115
115
97
103
101
41
13
10
79
79

test.txt file is created but the output not match output datasheet

stefano

SD_UserManual.pdf (799 KB)

If you convert the ascii output to characters, it looks quite reasonable:

 62 >
 77 M
111 o
100 d
101 e
 58 :
 32 <space>
 77 M
 67 C
 85 U
 40 (
115 s
105 i
109 m
112 p
108 l
101 e
 32 <space>
109 m
101 e
115 s
115 s
 97 a
103 g
101 e
 41 )
 13 <carriage return>
 10 <line feed>
 79 O
 79 O

test.txt file is created but the output not match output datasheet

Not sure what you mean by that.

hi
from datasheet

mode /m
>Mode: MCU(simple message)init

my output is

Goodnight moon!
>Mode: MCU(simple message)
OO

init output is missing?

stefano

A capital O indicates that a command was successful. A return of 'O' from your init and fcreate calls seems ok.

hi

A capital O indicates that a command was successful. A return of 'O' from your init and fcreate calls seems ok.

ok knew

this is the new sketch

#include <SoftwareSerial.h>
SoftwareSerial sdSerial(5,4);// pin 5 RX pin 4 TX
#include <String.h>
char incoming_char=0;
int dato;
String datostringa,scrivistringa;

void setup()  
{
  Serial.begin(9600);  // set the data rate for the Serial port
    sdSerial.begin(9600);  // set the data rate for the SoftwareSerial port
  delay(50);//pausa
  Serial.println("SD start operation");

  Serial.println("mode");  //set mode
   sdSerial.print("mode /m \r\n");
   delay(100);
    while (sdSerial.available())  //check response
    {
    Serial.print(char(sdSerial.read()));    //print response
       }
  Serial.println();  //empty line
  
  Serial.println("init");  //set init
   sdSerial.print("init \r\n");
   delay(100);
  while(sdSerial.available())  //check response
  {
    Serial.print(char(sdSerial.read()));  //print response
    } 
 Serial.println();  //empty line
 
 Serial.println("create file");
 sdSerial.print("fcreate test.txt\r\n");
 delay(100);
  while(sdSerial.available())  //check response
  {
    Serial.print(char(sdSerial.read()));  //print response
    } 
  Serial.println();  //empty line
  
 Serial.println("write file first time");
sdSerial.print("fputs test.txt /w temp \r\n");
  delay(100);
 while(sdSerial.available())  //check response
  {
    Serial.print(char(sdSerial.read()));  //print response
    delay(50);
  }
Serial.println();  //empty line  
}
 
void loop() 
{ 
  
  for(dato=1;dato<=10;dato++)
 {
   datostring=String(dato);
   
 sdSerial.print("fputs test.txt /a "+datostring+" \r\n"); 
 
 delay(100);
 while(sdSerial.available())  //check response
  {
    Serial.print(char(sdSerial.read()));  //print response
    delay(50);
  }
Serial.println();  //empty line  
 }
 Serial.println("end write");
 while(true){}
}

now it work, then I can to continue with my datalogger

tanks dxw00d

stefano

Be careful using Strings as these are prone to causing memory problems - and many say best avoided.

Paul

hi
@countrypaul

Be careful using Strings as these are prone to causing memory problems - and many say best avoided.

can you tell me more?

stefano

There is a serious bug in the dynamic memory free() function that can cause String to crash.

http://arduino.cc/forum/index.php/topic,115552.0.html

Fixes are presented in the above topic.

The problem may also cause SD.h to crash if many files are opened an closed.