Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi, I try to read file from SD card using arduino + ethernet shiled.
I have login.txt with content:
41001662
41001536
41001324
.....
I can read all file, but I want to read line by line of login.txt
How can I read 41001662 to data1, 41001365 to data2? read line by line?
Here is my code. How can I fix it?
///////////////////
C#
#include <SD.h>
File myFile;
void setup()
{
  Serial.begin(9600);
  Serial.print("Initializing SD card...");
  pinMode(10,OUTPUT);

  if(!SD.begin(4))
  {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
  myFile = SD.open("login.txt");
  if(myFile)
  {
    Serial.println("login.txt: ");
    while(myFile.available())
    {
      Serial.write(myFile.read());
    }
    myFile.close();
  }
  else
  {
    Serial.println("error opening test.txt");
  }
}
void loop()
{

}
Posted
Updated 15-Sep-14 5:52am
v2

1 solution

From File class documentation[^]:
read()

Read a byte from the file.


Hence, in order to read line by line you have to detect the end-of-line character (could be, for instance '\n'). Note you can do that either on Arduino side or on the PC one.
 
Share this answer
 
Comments
Member 10390715 15-Sep-14 12:42pm    
Thanks, for your help. Because I try to read RFID tag and compare with database store in SD card using arduino so try read SD card first.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900