Greetings Ladies and Gents.
I have jambed myself up trying to get this to work. I have an SD card that had 30 somthing .TXT files on it that I am going to read from the SD card and print on to one of two LCD screens. I have been able to read the files from the SD card and print them to the serial monitor. I have been able to lcd.print(" "); to both of the lcd displays elsewhere in the code and they work so I know that my hardware is correct. I placed a lcd1.print(dataFile); right below the Serial.write(dataFile.read()); and i get gibberish on the LCD screen. I tried a lcd1.print(dataFile.read()); in the same spot and I got a rapidly changing series of numbers and letters in the first two segments and then it stopped on 31. What the colorful cussword is going on here? >:( What am I missing. Ive been banging my head on the desk so long I have a flat spot. Is there a way for me to read the SD card file into a variable and then print to the LCD screens from that variable. If so what would that variable be and how would I set it up? An array? A string? Ive read so much that I have information overload and I am not sure what to use where. Your kindly patient assistance would be most welcome. (code attached)
Amachinetech
#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd1(0x26, 20, 4);//change the address, width and height here to match the LCD screen you are using.
LiquidCrystal_I2C lcd2(0x27, 20, 4);//change the address, width and height here to match the LCD screen you are using.
const int chipSelect = 4;
void setup() {
lcd1.begin();
lcd2.begin();
// Open serial communications and wait for port to open:
Serial.begin(9600);
lcd1.print("starting up"); //<----these print to the LCD screens just fine
lcd2.print("me too");
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
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:
while (1);
}
Serial.println("card initialized."); //<--card initializes correctly and I can read all of the files.
// 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("001.txt");
// if the file is available, write to it:
if (dataFile) {
while (dataFile.available()) {
Serial.write(dataFile.read()); //<------if either one of the below is present then I get giberish on the serial monitor
//lcd1.print(dataFile); <-------this doesn't work, just prints a two digit number on the screen
//lcd1.print(dataFile.read()); <-----this displays a stream of 1s over most of the LCD screen
}
dataFile.close();
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening datalog.txt");
}
}
void loop() {
}