piacenza
Offline
Sr. Member
Karma: 0
Posts: 496
prima della pazzia c'è la passione
|
 |
« on: August 23, 2012, 04:32:13 am » |
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
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 312
Posts: 35483
Seattle, WA USA
|
 |
« Reply #1 on: August 23, 2012, 06:31:30 am » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
piacenza
Offline
Sr. Member
Karma: 0
Posts: 496
prima della pazzia c'è la passione
|
 |
« Reply #2 on: August 23, 2012, 07:20:35 am » |
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
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 312
Posts: 35483
Seattle, WA USA
|
 |
« Reply #3 on: August 23, 2012, 07:39:12 am » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
piacenza
Offline
Sr. Member
Karma: 0
Posts: 496
prima della pazzia c'è la passione
|
 |
« Reply #4 on: August 23, 2012, 07:47:52 am » |
hi this SD work with RX TX not SPI, then I am not sure I can use statements's file (bottom)
thanks stefano
|
|
|
|
|
Logged
|
|
|
|
|
Gosport, UK
Offline
Faraday Member
Karma: 19
Posts: 3118
|
 |
« Reply #5 on: August 23, 2012, 07:57:25 am » |
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?
|
|
|
|
|
Logged
|
|
|
|
|
piacenza
Offline
Sr. Member
Karma: 0
Posts: 496
prima della pazzia c'è la passione
|
 |
« Reply #6 on: August 23, 2012, 01:06:44 pm » |
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
|
|
|
|
« Last Edit: August 23, 2012, 01:08:53 pm by stefa24 »
|
Logged
|
|
|
|
|
Gosport, UK
Offline
Faraday Member
Karma: 19
Posts: 3118
|
 |
« Reply #7 on: August 24, 2012, 02:07:36 am » |
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?
|
|
|
|
|
Logged
|
|
|
|
|
piacenza
Offline
Sr. Member
Karma: 0
Posts: 496
prima della pazzia c'è la passione
|
 |
« Reply #8 on: August 24, 2012, 01:37:08 pm » |
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
|
|
|
|
|
Logged
|
|
|
|
|
Leeds, UK
Offline
Newbie
Karma: 0
Posts: 29
|
 |
« Reply #9 on: August 24, 2012, 06:06:23 pm » |
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?
|
|
|
|
|
Logged
|
|
|
|
|
piacenza
Offline
Sr. Member
Karma: 0
Posts: 496
prima della pazzia c'è la passione
|
 |
« Reply #10 on: August 25, 2012, 11:06:56 am » |
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
|
|
|
|
|
Logged
|
|
|
|
|
Gosport, UK
Offline
Faraday Member
Karma: 19
Posts: 3118
|
 |
« Reply #11 on: August 25, 2012, 11:27:42 am » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
piacenza
Offline
Sr. Member
Karma: 0
Posts: 496
prima della pazzia c'è la passione
|
 |
« Reply #12 on: August 25, 2012, 11:45:12 am » |
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
|
|
|
|
|
Logged
|
|
|
|
|
Gosport, UK
Offline
Faraday Member
Karma: 19
Posts: 3118
|
 |
« Reply #13 on: August 25, 2012, 11:59:10 am » |
A capital O indicates that a command was successful. A return of 'O' from your init and fcreate calls seems ok.
|
|
|
|
|
Logged
|
|
|
|
|
piacenza
Offline
Sr. Member
Karma: 0
Posts: 496
prima della pazzia c'è la passione
|
 |
« Reply #14 on: August 25, 2012, 04:07:28 pm » |
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
|
|
|
|
|
Logged
|
|
|
|
|
|