Go Down

Topic: won't print (Read 950 times) previous topic - next topic

haemse

Oct 11, 2009, 12:02 pm Last Edit: Oct 11, 2009, 12:04 pm by haemse Reason: 1
I've connected a 40x4 LCD to my arduino and i use the LiquidCrystal library. While the LCD acts as 2 40x2 displays and i didn't figure out how the LiquidCrystal lib would handle that i've written my code so it should handle it. In the loop i wanted to Serial.println the running integer i. However when i put in that line it prints nothing and at the display it just shows the first character ... no more than this. Why does the arduino strike to Serial.println(i); ????

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
LiquidCrystal lcd2(12, 10, 5, 4, 3, 2);

void setup(){
   // set up the LCD's number of rows and columns:
 lcd.begin(40, 2);
 lcd2.begin(40, 2);
 // initialize the serial communications:
 Serial.begin(9600);
}

void loop()
{
 int cha;
 int i=1;
 // when characters arrive over the serial port...
 if (Serial.available()) {
   // wait a bit for the entire message to arrive
   delay(100);
   // clear the screen
   lcd.clear();
   lcd2.clear();;
   // read all the available characters
   while (Serial.available() > 0) {
     // display each character to the LCD
     cha=Serial.read();
     if (i<=80){
       lcd.write(cha);
     }else{
       lcd2.write(cha);
     }
     i++;
     [size=12][size=10]Serial.println(i);[/size][/size]
   }
 }
}

mem

You initialize the variable i each time through the loop so it never changes, move int i=1; outside loop to the top of the sketch.

You will also need to add code that resets i back to 0 after 80 characters. This is complicated because if you use cursor addressing then the number of characters written no longer corresponds to which logical LCD you should write to. It may be easier to implement this by modifying the library.

Do you have a link to the datasheet for your LCD, Perhaps there is a mode that allows it to be controlled without all these complications.

haemse

#2
Oct 11, 2009, 01:22 pm Last Edit: Oct 11, 2009, 01:23 pm by haemse Reason: 1
Hmmm ... the Serial.print is in the while loop, when the variable i is already intialized ...
However thx ... your tip was right and it works now ...
The Dataheet of the LCD is here: http://www.datasheetcatalog.org/datasheets2/19/191918_1.pdf

haemse

and ... you are right i'll have to reset i ... i thought about writing a function writeChar which stores the actual number of chars written to the LCD in a static variable ... but modifying the lib would be much better although i've never done this ... but should not be to complicated ...

Go Up