Jump to content

How to print variable on arduino LCD screen.

Go to solution Solved by fizzlesticks,

edit 2: The strange character is the arduino trying to print 'enter'. I don't know how to stop that.

Just check for a newline character and ignore it.

#include <LiquidCrystal.h>  LiquidCrystal lcd(12, 11, 5, 4, 3, 2);  char c = 'c';    void setup() {        lcd.setCursor(0, 0);    Serial.begin(9600);    lcd.begin(16,2);    lcd.clear();    }        void loop() {    while(Serial.available() == 0);    char dMes = Serial.read();    if(dMes == c){      lcd.clear();      lcd.setCursor(0,0);    }    else if(dMes != '\n'){                lcd.print(dMes);    }     delay(30);   }     

I am using the serial monitor to type a word and it will (in theory) be displayed on my LCD. The problem is, the word is flashing one letter at a time on the first cursor spot (0,0) like a slide show. The code is as shown:

 

#include <LiquidCrystal.h>

  LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
 
  void setup() {
    
    Serial.begin(9600);
  }
    
 
  void loop() {
    while(Serial.available() == 0);
    char dMes = Serial.read();
        lcd.clear();
        lcd.begin(16,2);
        lcd.setCursor(0, 0);
        lcd.print(dMes);
        delay(1000);
      
  }

 

Any help to display the whole word would be great. :)

Space is pretty awesome.

Link to comment
Share on other sites

Link to post
Share on other sites

I don't know Arduino (or whatever this may be) but from the looks of it you're reading in 1 character per loop and also resetting the cursor position each time.

What happens if you move the lcd.setCursor(0,0) to setup instead of calling it each loop?

edit: The lcd.clear() and lcd.begin probably need to be taken out of the loop too.

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

I don't know Arduino (or whatever this may be) but from the looks of it you're reading in 1 character per loop and also resetting the cursor position each time.

What happens if you move the lcd.setCursor(0,0) to setup instead of calling it each loop?

edit: The lcd.clear() and lcd.begin probably need to be taken out of the loop too.

I moved it and the lcd.begin(16,2); but nothing changed.

Space is pretty awesome.

Link to comment
Share on other sites

Link to post
Share on other sites

I don't know Arduino (or whatever this may be) but from the looks of it you're reading in 1 character per loop and also resetting the cursor position each time.

What happens if you move the lcd.setCursor(0,0) to setup instead of calling it each loop?

edit: The lcd.clear() and lcd.begin probably need to be taken out of the loop too.

The problem is fixed! Thank you so much!

Space is pretty awesome.

Link to comment
Share on other sites

Link to post
Share on other sites

I don't know Arduino (or whatever this may be) but from the looks of it you're reading in 1 character per loop and also resetting the cursor position each time.

What happens if you move the lcd.setCursor(0,0) to setup instead of calling it each loop?

edit: The lcd.clear() and lcd.begin probably need to be taken out of the loop too.

New problem, since I took lcd.clear() out of the loop, it won't clear so a new message can't be entered.

Space is pretty awesome.

Link to comment
Share on other sites

Link to post
Share on other sites

New problem, since I took lcd.clear() out of the loop, it won't clear so a new message can't be entered.

You'll need some way of determining that it should get ready to display a new word, like if a certain character is entered, something like:

void loop() {    while(Serial.available() == 0);    char dMes = Serial.read();    if(dMes == '\n')    {        lcd.clear();        lcd.setCursor(0,0);    }    else    {        lcd.print(dMes);    }        delay(1000);  }

So if you input a newline (enter key) it will clear the current word.

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

You'll need some way of determining that it should get ready to display a new word, like if a certain character is entered, something like:

void loop() {    while(Serial.available() == 0);    char dMes = Serial.read();    if(dMes == '\n')    {        lcd.clear();        lcd.setCursor(0,0);    }    else    {        lcd.print(dMes);    }        delay(1000);  }

So if you input a newline (enter key) it will clear the current word.

It now clears the screen one second (the delay amount) after it finishes writing the word(s).

Space is pretty awesome.

Link to comment
Share on other sites

Link to post
Share on other sites

It now clears the screen one second (the delay amount) after it finishes writing the word(s).

 

That will be because you're (I would guess) typing out your word(s) and then hitting enter which will send a '\n' telling the arduino to clear the LCD screen (after the 1 second delay after printing the previous character). Just don't hit enter/send '\n' and the word(s) will remain there.

 

Am I right?

Link to comment
Share on other sites

Link to post
Share on other sites

That will be because you're (I would guess) typing out your word(s) and then hitting enter which will send a '\n' telling the arduino to clear the LCD screen (after the 1 second delay after printing the previous character). Just don't hit enter/send '\n' and the word(s) will remain there.

 

Am I right?

The problem is I need to press enter for it to assign what I typed as dMes

Space is pretty awesome.

Link to comment
Share on other sites

Link to post
Share on other sites

The problem is I need to press enter for it to assign what I typed as dMes

You can change the character to anything, just go for something uncommon in normal typing '~' or ';' maybe.

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

You can change the character to anything, just go for something uncommon in normal typing '~' or ';' maybe.

I did that and everything is fine and dandy but a weird symbol appears after the word, even when I clear the screen the symbol stays there. The symbol looks like this:

 

(five pixels)

(four Pixels)

(five pixels)

(four pixels)

 

and that is in one character spot

 

edit: This is the current code:

#include <LiquidCrystal.h>  LiquidCrystal lcd(12, 11, 5, 4, 3, 2);  char c = 'c';    void setup() {        lcd.setCursor(0, 0);    Serial.begin(9600);    lcd.begin(16,2);    lcd.clear();    }        void loop() {    while(Serial.available() == 0);    char dMes = Serial.read();    if(dMes == c){      lcd.clear();      lcd.setCursor(0,0);    }    else{                lcd.print(dMes);    }     delay(30);   }     

edit 2: The strange character is the arduino trying to print 'enter'. I don't know how to stop that.

Space is pretty awesome.

Link to comment
Share on other sites

Link to post
Share on other sites

edit 2: The strange character is the arduino trying to print 'enter'. I don't know how to stop that.

Just check for a newline character and ignore it.

#include <LiquidCrystal.h>  LiquidCrystal lcd(12, 11, 5, 4, 3, 2);  char c = 'c';    void setup() {        lcd.setCursor(0, 0);    Serial.begin(9600);    lcd.begin(16,2);    lcd.clear();    }        void loop() {    while(Serial.available() == 0);    char dMes = Serial.read();    if(dMes == c){      lcd.clear();      lcd.setCursor(0,0);    }    else if(dMes != '\n'){                lcd.print(dMes);    }     delay(30);   }     

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×