Go Down

Topic: Displaying text from the Serial Monitor on and LCD (Read 1 time) previous topic - next topic

kabuki4774

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: [Select]
#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

johnwasser

Start with something simple like this:

Code: [Select]

#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.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

kabuki4774

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: [Select]
#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.

johnwasser


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: [Select]

void loop() {
    if(Serial.available()>0){
        int inputCharacter = Serial.read();
        lcd.write(inputCharacter);
        Serial.print(inputCharacter);
    }
}
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

floresta

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: [Select]
#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

Go Up