Pages: [1]   Go Down
Author Topic: 20x4 lcd question  (Read 269 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i have this new lcd ive been playing with that i bought from ebay and it came with the I2C converter. i have it working like it should sending messages from my android using a bluetooth serial terminal using this sketch:
Code:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); 

void setup()
{
  Serial.begin(9600);
  lcd.begin(20,4);
{
lcd.backlight();
}
lcd.backlight();
}

void loop()
{
  if (Serial.available())
  {
    delay(100);
    lcd.clear();
    while (Serial.available() > 0)
    {
      lcd.write(Serial.read());
    }
  }
}

my question is there a way to attach this sketch to other sketches that have Serial.print functions such as this:

Code:
char val;
const int buttonPin1 = 2;   
const int buttonPin2 = 3;


int buttonState1 = 0;
int buttonState2 = 0;

void setup() {

  pinMode(buttonPin1, INPUT); 
  pinMode(buttonPin2, INPUT); 
 
 Serial.begin(9600);
 
}

  void loop(){
 
   {
  if( Serial.available() )       
  {;}
   
    buttonState1 = digitalRead(buttonPin1);

  if (buttonState1 == HIGH) {     
    Serial.print("1");
  }
   buttonState2 = digitalRead(buttonPin2);

  if (buttonState2 == HIGH) {     
    Serial.print("2");
  }
   }
  }
 

I will be using it to read serial data over bluetooth and when a certain pin goes high or low i want the lcd to display whatever is in the Serial.print line
Logged

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

also, how can i impliment this into my sketches to fix the text wrapping problem so that whenever it reads the serial.print it will wrap to the second line instead of the third? or is there a way to make the sketch read the serial data then use lcd.setCursor and know to print the first 20 characters on the first line then set the cursor to the second line to finish typing what comes over serial.print?
for example if my line that is in serial.print is longer than 20 characters is there a way to make the code know how many characters to put on which line?
Code:
//-------- Write characters on the display ----------------
// NOTE: Cursor Position: CHAR, LINE) start at 0 
  lcd.setCursor(3,0); //Start at character 4 on line 0
  lcd.print("Line 1");
  delay(1000);
  lcd.setCursor(2,1);
  lcd.print("Line 2");
  delay(1000); 
  lcd.setCursor(0,2);
  lcd.print("Line 3");
  lcd.setCursor(0,3);
  delay(2000);   
  lcd.print("Line 4");
  delay(2000);
}
Logged

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

Quote
also, how can i impliment this into my sketches to fix the text wrapping problem so that whenever it reads the serial.print it will wrap to the second line instead of the third? or is there a way to make the sketch read the serial data then use lcd.setCursor and know to print the first 20 characters on the first line then set the cursor to the second line to finish typing what comes over serial.print?
for example if my line that is in serial.print is longer than 20 characters is there a way to make the code know how many characters to put on which line?

All of this can be done ... BUT not inherently by either the LCD controller or by any existing library that I know of.  Therefore you have a nice programming project ahead of you.

You have to understand that these LCD modules were never intended to be used as a replacement for a computer monitor or even to display long (multi-line) messages.  They were designed to be installed in equipment such as laser printers to give short messages like "add toner" or "add paper".


Don
Logged

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

is there some sort of "if" statement i can put into my sketch that tells the arduino if the characters coming over serial are longer than 20 chars to seperate them and set the LCD cursor?
Logged

Sydney, Australia
Offline Offline
Edison Member
*
Karma: 27
Posts: 1189
Big things come in large packages
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You need to keep count of the characters you receive until the end of line character '\n' (or just accumulate the chars and then get the length with strlen()). If that is bigger than 20 then you print the first 20 on the first line and the rest one the second line.

So there is an 'if' statement that will do it but there is a lot more you need besides that.
Logged

Arduino libraries http://arduinocode.codeplex.com
Parola hardware & library http://parola.codeplex.com

Pages: [1]   Go Up
Jump to: