I'm trying to get my SD card debugging messages to output all messages such as "initialising", "card ready" all on 1 line. I've tried adding lcd.setCursor(0,0) after every print statement, but everything seems to be cramming in on top of each other. Is there a way that when the next message is about to output, the previous message disappears?
Here is my code so far:
// include the library code:
#include <LiquidCrystal.h>
// Include SD library
#include <SD.h>
int CS_pin = 4; // CS SD
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 7, 6, 5, 3, 2);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 4);
lcd.println("Initializing card");
lcd.setCursor(0,0);
// CS pin as output
pinMode(CS_pin, OUTPUT);
// Check if card is ready
if(!SD.begin(CS_pin)) {
lcd.println("Card Failed");
return;
}
lcd.println("Card Ready");
lcd.setCursor(0,0);
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
// lcd.setCursor(0, 1);
String dataString = "Darryl!";
File dataFile = SD.open("log.txt", FILE_WRITE);
if(dataFile) {
dataFile.println(dataString);
dataFile.close();
// To keep track lets print the string to the console.
lcd.println("Working");
lcd.setCursor(0,0);
}
else {
lcd.println("Couldn't access file");
lcd.setCursor(0,0);
}
delay(5000);
}
Thanks, yes I have just come across that method in that tutorial.
The problem is now that I don't see any of the messages at the beginning from the setup i.e. "initializing", etc. I just see "working". Although this seems fine I'm worried that lcd.clear() will clear the whole 4 lines, as this will be showing sensor data such as temp, humidity, etc..
Although this seems fine I'm worried that lcd.clear() will clear the whole 4 lines,
Yes it will.
If you want to clear just a line then do a lcd.print(" "); after your print to wipe out anything else on the line. If you keep track on what was on the line you can add just the number of spaces you need.
Although this seems fine I'm worried that lcd.clear() will clear the whole 4 lines,
Yes it will.
If you want to clear just a line then do a lcd.print(" "); after your print to wipe out anything else on the line. If you keep track on what was on the line you can add just the number of spaces you need.
Thanks for the reply.
Strange, now I've changed it what you said, I've got text sitting on top of each other again, hmm, I have put lcd.print(" "); just before each new message kicks in.
if(dataFile) {
dataFile.println(dataString);
dataFile.close();
lcd.setCursor(0,0);
lcd.print("Rec Data!");
lcd.print(" "); // to wipe out the old stuff
}