user11285: This is a part of my program which reads data from file stored in SD card and displays that on an LCD screen.
  File dataFile = SD.open("1165.txt");


  if (dataFile) {
    Serial.println("File Opened");
    lcd.clear();
       delay( 5 );  //LCD-specific M
       lcd.setCursor( 0,0 );


  while (dataFile.available()) {
      Serial.write(dataFile.read());
      lcd.write(dataFile.read());
      lcd.print(dataFile.read());
    }
  dataFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error");
  }

When I look at the serial monitor it prints the contents of that file but none of these commands print what is printed in the serial monitor,
lcd.write(dataFile.read());
lcd.print(dataFile.read());

Any ideas?

user14238: You could also implement a readLine routine, similar to:
void _readLine(File f, char *line)
{
    boolean cr_found = false;
    int p = 0;
    while (f.available()) {
        char b = f.read();
        if(b!='\r' && b!='\n')
            line[p++] = b;

        if(b == '\r') cr_found = true;
        if((b == '\n') && cr_found) break;
    }
    line[p] = '\0';
}

And read the SD file line by line, processing each one of them by its own.
char buffer[32];

while(dataFile.available()) {
    _readLine(dataFile, buffer);
    // do something with buffer
}


user2742: When you call dataFile.read(), the file pointer is advanced, so you always read different bytes in each read call. Imagine the file like a book with many lines: Each time you read, you advance the current line, so with multiple calls, you never get the same data. The solution is to currently store the last read byte:
while (dataFile.available()) {
  char readByte = dataFile.read();
  Serial.write(readByte);
  lcd.write(readByte);
  lcd.print(readByte);
}

You have two calls for displaying data in the LCD, but be careful that the second call (print) might interpret your data as a number, so just remove the lcd.print(readByte) call altogether to be sure it's printing the raw character.

11285: 

<p>This is a part of my program which reads data from file stored in SD card and displays that on an LCD screen.</p>

<pre class="lang-C++ prettyprint-override"><code>  File dataFile = SD.open("1165.txt");


  if (dataFile) {
    Serial.println("File Opened");
    lcd.clear();
       delay( 5 );  //LCD-specific M
       lcd.setCursor( 0,0 );


  while (dataFile.available()) {
      Serial.write(dataFile.read());
      lcd.write(dataFile.read());
      lcd.print(dataFile.read());
    }
  dataFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error");
  }
</code></pre>

<p>When I look at the serial monitor it prints the contents of that file but none of these commands print what is printed in the serial monitor,</p>

<pre class="lang-C++ prettyprint-override"><code>lcd.write(dataFile.read());
lcd.print(dataFile.read());
</code></pre>

<p>Any ideas?</p>
 14238: <p>You could also implement a readLine routine, similar to:</p>

<pre><code>void _readLine(File f, char *line)
{
    boolean cr_found = false;
    int p = 0;
    while (f.available()) {
        char b = f.read();
        if(b!='\r' &amp;&amp; b!='\n')
            line[p++] = b;

        if(b == '\r') cr_found = true;
        if((b == '\n') &amp;&amp; cr_found) break;
    }
    line[p] = '\0';
}
</code></pre>

<p>And read the SD file line by line, processing each one of them by its own.</p>

<pre><code>char buffer[32];

while(dataFile.available()) {
    _readLine(dataFile, buffer);
    // do something with buffer
}
</code></pre>
 2742: <p>When you call <code>dataFile.read()</code>, the file pointer is advanced, so you always read different bytes in each <code>read</code> call. Imagine the file like a book with many lines: Each time you read, you advance the current line, so with multiple calls, you never get the same data. The solution is to currently store the last read byte:</p>

<pre><code>while (dataFile.available()) {
  char readByte = dataFile.read();
  Serial.write(readByte);
  lcd.write(readByte);
  lcd.print(readByte);
}
</code></pre>

<p>You have two calls for displaying data in the LCD, but be careful that the second call (<code>print</code>) might interpret your data as a number, so just remove the <code>lcd.print(readByte)</code> call altogether to be sure it's printing the raw character.</p>
