Pages: [1]   Go Down
Author Topic: Displaying text from the Serial Monitor on and LCD  (Read 991 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My overall goal seemed simple, allow the user to write, to the serial monitor, the text they wanted to have displayed on the LCD.

My code is as follows:
Code:
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);


String stringUsed = "Hello world";
int i=0;
//char wordOfTheWise[16];

void setup() {
  Serial.begin(9600);
  lcd.begin(16,2);
}

void loop() {
 
if(Serial.available()>0) {
//  i=0;
  stringUsed = String(Serial.read());
  Serial.print(stringUsed);
  do{
    stringUsed= String(stringUsed + Serial.read());
    lcd.print(stringUsed);
   
//    i++;
  } while (Serial.peek()!='\n');
 
}

lcd.print(stringUsed);

lcd.autoscroll();
}

The problem that occur at the moment:
  • -text displays gibberish (i believe this is on account of the autoscroll feature and the fact that it is writing more then just one letter at a time)
  • -serial input displays improperly as well

I appreciate any help. thanks
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8669
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Start with something simple like this:

Code:
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  Serial.begin(9600);
  lcd.begin(16,2);
  lcd.autoscroll();
}

void loop() {
    if(Serial.available())
        lcd.write(Serial.read());
}

Then it will be easier to understand how incoming characters are displayed.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So I tried out the above, and nothing appears on the LCD.

also tried it this out.. just to get some type of response:
Code:
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  Serial.begin(9600);
  lcd.begin(16,2);
  lcd.autoscroll();
}

void loop() {
    if(Serial.available()>0){
        lcd.write(Serial.read());
        Serial.print(Serial.read());
    }

Guess what, the serial monitor displayed -1 for every input.
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8669
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Guess what, the serial monitor displayed -1 for every input.

Probably because you are trying to read each character twice.  Read it once and store it to use twice:
Code:
void loop() {
    if(Serial.available()>0){
        int inputCharacter = Serial.read();
        lcd.write(inputCharacter);
        Serial.print(inputCharacter);
    }
}
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 32
Posts: 4255
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
-text displays gibberish (i believe this is on account of the autoscroll feature and the fact that it is writing more then just one letter at a time)
Why are you using autoscroll?

After you finish with John's exercises then try this one to get an idea how the LCD works.  Don't get impatient, let it run for a while. Then follow the LCD Addressing link at http://web.alfredstate.edu/weimandn to find out why the LCD works that way.


Code:
#include <LiquidCrystal.h>

//LiquidCrystal lcd(rs,en,d4,d5,d6,d7);
  LiquidCrystal lcd(12, 11, 5, 4, 3, 2);       // put your pin numbers here

void setup()
  {
    lcd.begin(20, 4);                          // put your LCD parameters here
    for (char i=47; i<127; i++)                // send 80 consecutive displayable characters to the LCD
      {
        lcd.print(i);
        delay(100);                            // this delay allows you to observe the addressing sequence
      }
  }


void loop()
  { 
  }

You could try adding lcd.autoscroll (just after the lcd.begin) to see what that does as well.  I haven't tried it but it should be interesting.

Don
Logged

Pages: [1]   Go Up
Jump to: