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:
#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
Start with something simple like this:
#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.
So I tried out the above, and nothing appears on the LCD.
also tried it this out.. just to get some type of response:
#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.
kabuki4774:
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:
void loop() {
if(Serial.available()>0){
int inputCharacter = Serial.read();
lcd.write(inputCharacter);
Serial.print(inputCharacter);
}
}
-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.
#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