gantner_street:
This complete sketch prints to the serial monitor showing "CR" and "LF", and also displays just the "human" characters on line 1 of the LCD:
//this version displays one line at a time with their CRs and LFs
// button from thePin to ground, with input pullup
// this one has I2C LCD
/*
SD card file dump
This example shows how to read a file from the SD card using the
SD library and send it over the serial port.
The circuit:
SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4 (for MKRZero SD: SDCARD_SS_PIN)
created 22 December 2010
by Limor Fried
modified 9 Apr 2012
by Tom Igoe
This example code is in the public domain.
*/
#include <SPI.h>
#include <SD.h>
const int chipSelect = 4;
char theChar;
byte thePin = 2;
//lcd stuff
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
pinMode(thePin, INPUT_PULLUP);
while (!Serial)
{
; // wait for serial port to connect. Needed for native USB port only
}
// initialize the LCD
lcd.begin();
// Turn on the blacklight and print a message.
lcd.backlight();
lcd.setCursor(0, 0); //move along and down
lcd.print(" Hello");
lcd.setCursor(0, 1); //move along and down
lcd.print(" World");
delay(1000);
lcd.clear();
Serial.print("Initializing SD card...");
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");
Serial.println("Press button to see each line");
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("DATALOG1.TXT");
// if the file is available, raed it:
if (dataFile)
{
while (dataFile.available())
{
theChar = dataFile.read();
if (theChar == '\n')
{
Serial.print("LF");
while (digitalRead(thePin)) {} //wait until button pressed
delay(500); //poor man's debounce
lcd.setCursor(0, 0);
}
else if (theChar == '\r')
{
Serial.print("CR");
}
else lcd.print(theChar); //ignores the cr and lf
Serial.write(theChar); //honours the cr and lf
}
Serial.println("End Of File");
lcd.print(" End Of File ");
dataFile.close();
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening datalog1.txt");
}
}
void loop() {
}
This WORKS! only problem now is the LCD backlight wont turn ON.. maybe a LCD I2C address issue?