Pages: [1]   Go Down
Author Topic: 20x4 LCD Screen for Debugging?  (Read 1189 times)
0 Members and 1 Guest are viewing this topic.
Wrexham, North Wales
Offline Offline
Full Member
***
Karma: 0
Posts: 143
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

Code:
//  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);
 
}
Logged

M

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 34724
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You could precede each message with an lcd.clear() call
http://arduino.cc/en/Reference/LiquidCrystal?from=Tutorial.LCDLibrary
Logged

Wrexham, North Wales
Offline Offline
Full Member
***
Karma: 0
Posts: 143
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You could precede each message with an lcd.clear() call
http://arduino.cc/en/Reference/LiquidCrystal?from=Tutorial.LCDLibrary

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.. 
Logged

M

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 34724
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

Wrexham, North Wales
Offline Offline
Full Member
***
Karma: 0
Posts: 143
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

M

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 34724
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

And have you put the cursor back to zero before you print your message?
Logged

Wrexham, North Wales
Offline Offline
Full Member
***
Karma: 0
Posts: 143
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

And have you put the cursor back to zero before you print your message?

I haven't no.  Should it be like this:

Code:
if(dataFile) {
    dataFile.println(dataString);
    dataFile.close();
    lcd.setCursor(0,0);
    lcd.print("             ");
    lcd.print("Rec Data!");
  }
  else {
    lcd.setCursor(0,0);
    lcd.print("                          ");
    lcd.print("Error with SD Card!");
  }
Logged

M

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 34724
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

No like this:-
Code:
if(dataFile) {
    dataFile.println(dataString);
    dataFile.close();
    lcd.setCursor(0,0);
    lcd.print("             ");
    lcd.setCursor(0,0);
    lcd.print("Rec Data!");
  }
  else {
    lcd.setCursor(0,0);
    lcd.print("                          ");
    lcd.setCursor(0,0);
    lcd.print("Error with SD Card!");
  }
or after the data

Code:
if(dataFile) {
    dataFile.println(dataString);
    dataFile.close();
    lcd.setCursor(0,0);
    lcd.print("Rec Data!");
    lcd.print("             "); // to wipe out the old stuff
  }
Logged

Wrexham, North Wales
Offline Offline
Full Member
***
Karma: 0
Posts: 143
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks  smiley

I'll give that a try when I fire up my screen next.  Had to send it back due to a fault  smiley-cry
Logged

M

Somerset, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

For what it is worth, you may get some ideas from this snippet of code that I am using on my LCD2004 (20 characters, 4 lines)

Code:
/*
BUTTON PRESS COUNTER test for motorized camera dolly project
Code written by Donald Gray 13 May 2013
Utilise a SainSmart LCD2004 4 row 20 char display
*/

#include <Bounce.h> //debounce library
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>  // F Malpartida's NewLiquidCrystal library

#define I2C_ADDR    0x3f  // Define PCF8574A's I2C Address (address of the 2004)
#define BACKLIGHT_PIN     3
#define En_pin  2
#define Rw_pin  1
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5
#define D6_pin  6
#define D7_pin  7
#define  LED_OFF  0
#define  LED_ON  1
LiquidCrystal_I2C  lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

int button4 = 12;
int button3 = 11; //button pins
int button2 = 10;
int button1 = 8;
int delayTime = 100; //delay after pressed button

// --------------------------------------------------------------
void setup() {
     // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
 
  pinMode(button1, INPUT); //button as inputs
  pinMode(button2, INPUT);
  pinMode(button3, INPUT);
  pinMode(button4, INPUT);
 
  lcd.begin (20,4);  // initialize the lcd
  // Switch on the backlight
  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  lcd.setBacklight(LED_ON);
  lcd.home();

  lcd.setCursor(0,0); // select line 1
  lcd.print("Camera Dolly Control");
 
  lcd.setCursor(0,1); // select line 2
  lcd.print("By Donald Gray"); 

  lcd.setCursor(0,2); // select line 3
  lcd.print("www.websilk.co.uk"); 

  lcd.setCursor(0,3); // select line 4
  lcd.print("                    "); // clear line

  delay(2000); // hold display for 2 seconds
  lcd.clear();     // clear the screen

  lcd.setCursor(0,0);
  lcd.print("Btn1 cycles Menu");

  lcd.setCursor(0,1);
  lcd.print("Btn2 SETS selection");

  lcd.setCursor(0,2);
  lcd.print("Btn3 = Reset");

  lcd.setCursor(0,3); // select line 4
  lcd.print("                    "); // clear line

  delay(1000);
    lcd.clear();     // clear the screen
}
Logged

Wrexham, North Wales
Offline Offline
Full Member
***
Karma: 0
Posts: 143
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks again  smiley

Will look at it again when I get my replacement screen.
Logged

M

Pages: [1]   Go Up
Jump to: