Go Down

Topic: sd with serial communication, how do? (Read 1 time) previous topic - next topic

stefa24

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
https://sites.google.com/site/agritronica/
https://sites.google.com/site/t3chconcrete/
arduino UNO rev 3
ide 105

PaulS

Quote
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.

stefa24

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
https://sites.google.com/site/agritronica/
https://sites.google.com/site/t3chconcrete/
arduino UNO rev 3
ide 105

PaulS

Quote
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.

stefa24

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

thanks
stefano
https://sites.google.com/site/agritronica/
https://sites.google.com/site/t3chconcrete/
arduino UNO rev 3
ide 105

dxw00d

Quote
can I use the statements's file (bottom)

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


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

stefa24

#6
Aug 23, 2012, 08:06 pm Last Edit: Aug 23, 2012, 08:08 pm by stefa24 Reason: 1
hi
this is the sketch and file attachments

Code: [Select]
#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
https://sites.google.com/site/agritronica/
https://sites.google.com/site/t3chconcrete/
arduino UNO rev 3
ide 105

dxw00d

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

Code: [Select]
   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.

Code: [Select]
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?

stefa24

Code: [Select]
You start by trying read and write to/from mySerial before the mySerial.begin().
ops

Code: [Select]
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
Code: [Select]

#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

Code: [Select]
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
https://sites.google.com/site/agritronica/
https://sites.google.com/site/t3chconcrete/
arduino UNO rev 3
ide 105

Code: [Select]
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?

Code: [Select]
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?

stefa24

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

this is the sketch
Code: [Select]

#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

Code: [Select]
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
https://sites.google.com/site/agritronica/
https://sites.google.com/site/t3chconcrete/
arduino UNO rev 3
ide 105

dxw00d

If you convert the ascii output to characters, it looks quite reasonable:
Code: [Select]
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


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


Not sure what you mean by that.

stefa24

hi
from datasheet
Code: [Select]

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


my output is
Code: [Select]

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


init output is missing?

stefano

https://sites.google.com/site/agritronica/
https://sites.google.com/site/t3chconcrete/
arduino UNO rev 3
ide 105

dxw00d

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

stefa24

hi
Code: [Select]

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
Code: [Select]

#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
https://sites.google.com/site/agritronica/
https://sites.google.com/site/t3chconcrete/
arduino UNO rev 3
ide 105

Go Up