How to use an SD Card Module with an LCD Keypad Shield?

Hello,

I'm using Arduino Uno, my problem is related to an SD Card Module with an LCD Keypad Shield.

On my SD card is currently a test.txt file, with a text 'tsp'. I can read it and print it on my Serial Monitor, but when I write it in my code that I want to print it on my LCD I get '-1' on the LCD Display and 'tp' (without the 's' in the middle) on my Serial Monitor.

On the beginning of my sketch you can see how I wired the SD:

/*
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS  - pin 3
 */
#include <LiquidCrystal.h>
#include "LCDKeypad.h"
#include <SPI.h>
//#include <SD.h>
#include "SdFat.h"
SdFat SD;

LiquidCrystal lcd(8,9,4,5,6,7);  

#define SD_CS_PIN 3
File myFile;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
    lcd.begin(16,2);  //Initialize a 2x16 type LCD


  Serial.print("Initializing SD card...");

  if (!SD.begin(SD_CS_PIN)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

  // open the file. note that only one file can be open at a time,

  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      Serial.write(myFile.read());
      
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

void loop() {
  // nothing happens after setup
}

Thanks in forward for the help,

David

I too am having issues using an Arduino Uno variant with LCD displays and an Adafruit datalogger shield. I will detail all in a new post.

Scott

try 'write' to lcd (instead of 'print')

knut_ny:
try 'write' to lcd (instead of 'print')

Hi knut_ny, thanks to your response.
When I try to use write instead print I get a black square.
I also tried to put out rows with Serial.print inside if(myFile) and for lcd.print I get '10' and for write also undefined character.