Arduino Forum

Forum 2005-2010 (read only) => Software => Troubleshooting => Topic started by: haemse on Oct 11, 2009, 12:02 pm

Title: won't print
Post by: haemse on Oct 11, 2009, 12:02 pm
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:

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
   // clear the screen
   // read all the available characters
   while (Serial.available() > 0) {
     // display each character to the LCD;
     if (i<=80){
Title: Re: won't print
Post by: mem on Oct 11, 2009, 12:33 pm
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.
Title: Re: won't print
Post by: haemse on Oct 11, 2009, 01:22 pm
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:
Title: Re: won't print
Post by: haemse on Oct 11, 2009, 01:27 pm
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 ...