LCD wraps output to 1 or 2 columns

void loop()
{
  LCD.print("world");
}

You are trying to print the word "world" over and over again. The serial interface is relatively slow but the LCD controller is even slower. The LCD controller can't keep up and you get garbage. Since the LCD memory does not have to be refreshed, put this code in setup.

void loop()
{
  lcd_clear();
  lcd_goto(0,0);
  LCD.print("world");
  delay(1000);
}

This one has an additional problem. The instruction to clear the LCD takes much more time to execute than most of the other instructions so the aforementioned problem gets even worse. You do not have to reset the cursor the 0,0 since the clear instruction does that. Again, none of this belongs in loop.

Don

I know this does not need to be in a loop; I just wanted to answer your question:

Does it work properly when you enter the actual column and row numbers as opposed to trying to calculate that information?

(To my understanding, the single print in a loop should write "worldworldworld..." etc., not just "world". But this is not really important.)

However moving the code to the setup does not change the result significantly.

void setup()
{
  pinMode(2, OUTPUT);
  LCD.begin(9600);
  lcd_clear();
  delay(1000);
  LCD.print("world");
}

void loop()
{
}
d _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
l _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

Concerning the timing: I added a (probably excessive) delay of one second after the clear command above. It also did not help. Thanks for the idea though!

(What length of delay would you consider appropriate? The HD44780 document linked above specifies the execution times of most commands as 37 microseconds, the "return home" as 1.52 milliseconds, but omits the value for the "clear display" command on page 24. I originally used a delay of 5 milliseconds as you can see in the code of lcd_do in the original post.)

I guess I am confused, but I haven't done much with serial LCDs and then only in assembly language with a different serial board.

The SoftwareSerial.h library allows you to communicate on pins other than 0 and 1 etc (see below). It has nothing to do with the LCD other than the fact that you are using it to communicate with what we now know is a Sparkfun serial interface device. You have to send that device commands that it understands and it converts those commands to the standard HD44780 commands that the LCD module understands.

SoftwareSerial LCD = SoftwareSerial(0, 2);

This is telling the SoftwareSerial library to use pins 0 and 2, probably not a good idea since pin 0 is used by the hardware serial interface..

I still don't see where you have involved any library that deals with the LCD commands themselves. For example, where does lcd_goto() come from?

Don

I think the library is intentionally missing, direct control seems to be the word (two words) of the day.

no245,
Do you have the correct sequency for the display, to initialize it properly?
Iwould like to see and test that too. I'm just too lazy to look for it myself, too much english in the instructions.

Cheers,
Kari

I'm not aware of any LCD libraries that I am/should/could be using. I more or less followed the SparkFunSerLCD article here on arduino.cc.

That's also where the pin 0 comes from:

SoftwareSerial LCD = SoftwareSerial(0, txPin);
// since the LCD does not send data back to the Arduino, we should only define the txPin

Do you think I should use SoftwareSerial(2, 2)? Or some other unused input pin?

lcd_goto() is defined in the original post above. It's a generalization of selectLineOne(), selectLineTwo() and goTo() from SparkFunSerLCD

GaryP,

Do you have the correct sequency for the display, to initialize it properly?

I'm not sure what you mean. There's no initialization code beyond what I posted above. I closely followed SparkFunSerLCD, which doesn't really do anything besides setting up the SoftwareSerial. The HD44780 datasheet mentions on page 23:

An internal reset circuit automatically initializes the HD44780U when the power is turned on.

too much english in the instructions.

I'm not sure what instructions you are referring to.

Thanks for your input.

too much english in the instructions.

I'm not sure what instructions you are referring to.

Thanks for your input.
[/quote]

Never mind, seems like an ability to read between the lines is not common...
:wink:

Well, should you try to google and look for "Arduino" + "LCD-libraries"? I bet you save many hours of valuable time with the answer.

Try this: arduino lcd library +"serial lcd" - Google Search

Cheers,
Kari

ooook... :roll_eyes:
Top three results for that are:

I guess I'm not reading between the lines again...

(Keep in mind the code used to work perfectly fine. I suspect there's some hardware setting I accidentally set or whatever. But I don't see one that could explain the observed behavior.)

Cheers

no245:
I guess I'm not reading between the lines again...

Well, there was nothing between the lines this time.
:slight_smile:

I think I tried to help in a matter that I know nothing about, never tried serial LCD, and perhaps those libraries don't help a bit. So my first assume was close enough, no libraries needed, just direct control like you were already doing.

Anyway, I'm looking forward to learn more about little details of serial LCD's.

Kari

Yeah, I have been crossthinking different topics. Just red this topic again from the beginning. Sorry!

Cheers,
Kari

That's ok.

Thanks for trying to help anyway!

I more or less followed the SparkFunSerLCD article here on arduino.cc.

With all due respect anyone can post anything in the Arduino playground. Do you want proof that the moon is made from blue cheese? Just give me a few minutes and then check Wikipedia.

Do you think I should use SoftwareSerial(2, 2)? Or some other unused input pin?

No, Yes. I wouldn't use the same pin number for both Tx and Rx. It looks like the playground code is doubling up on the receive pin knowing that the Sparkfun controller won't be sending anything there.

lcd_goto() is defined in the original post above. It's a generalization of selectLineOne(), selectLineTwo() and goTo() from SparkFunSerLCD

OK I found it! Are you sure that the compiler is doing the logical operations the way that you expect it to? I would start out by sending the specific numbers that the Sparkfun controller is expecting. After you get that working then you can see if you can calculate values that give you the same results.

Do you have the correct sequency for the display, to initialize it properly?

This is done by the Sparkfun controller.

An internal reset circuit automatically initializes the HD44780U when the power is turned on.

Don't bet on it. Read the datasheet - including the notes.

Don

How about this one:
http://www.arduino.cc/playground/Code/SLCD

Kari

Don,
Hmm, this doesn't belong here really, but is that playground full of not well tested and possibly bad instructions? Anybody can send their creations there and look like it's made by someone who looks like he/she knows what they are saying? That's not good...

Cheers,
Kari

And anyone can post anything in the Arduino forum. :wink:

I wouldn't use the same pin number for both Tx and Rx.

Ok, I'll try that later. (I doubt it will help, since this used to work fine. But it's worth a try I guess.)

Are you sure that the compiler is doing the logical operations the way that you expect it to?

Why, is the arduino compiler known for such bugs? I didn't check the generated assembly (is there an easy way to do that with the Arduino tools?) if you mean that. I'm fairly certain the code is correct though.

I would start out by sending the specific numbers that the Sparkfun controller is expecting.

I already did that in the second post (after you asked me to ;)) and it made no difference.

Don't bet on it. Read the datasheet - including the notes.

That quote is from the datasheet actually. I don't see any other information about initialization. (But I'm not sure what I would be looking for.)

How about this one:
Arduino Playground - SLCD

Well, apparently that site is unreliable. :wink:
Also the code in that library looks really equivalent, except that it uses HardwareSerial.h instead of SoftwareSerial.h.

Are you sure that the compiler is doing the logical operations the way that you expect it to?

Why, is the arduino compiler known for such bugs? I didn't check the generated assembly (is there an easy way to do that with the Arduino tools?) if you mean that. I'm fairly certain the code is correct though.

They aren't bugs, they are more like quirks. The people who coded the compiler meant one thing and the people using it interpret things differently. Kind of like operating system menus or error messages. Take a look through the avrfreaks forum sometimes and see how many of the professional programmers there are beating their brains out trying to get the compiler to do what they intended.

Don't bet on it. Read the datasheet - including the notes.

That quote is from the datasheet actually. I don't see any other information about initialization. (But I'm not sure what I would be looking for.)

Find the quote in the datasheet (p.23) and then look at the note directly below it, in the middle of the page.

Note:    If the electrical characteristics conditions listed under the table Power Supply Conditions Using 
         Internal Reset Circuit are not met, the internal reset circuit will not operate normally and will fail to 
         initialize   the   HD44780U.   For   such   a   case,   initial-ization   must   be   performed   by   the   MPU   as 
         explained in the section, Initializing by Instruction.

Follow the LCD initialization link at http://web.alfredstate.edu/weimandn for a complete explanation.

Don

GaryP:
Don,
Hmm, this doesn't belong here really, but is that playground full of not well tested and possibly bad instructions? Anybody can send their creations there and look like it's made by someone who looks like he/she knows what they are saying? That's not good...

Cheers,
Kari

It's not bad either - you just have to be skeptical. It would be nice if only experienced programmers who have thoroughly tested their projects posted them in the playground but I don't think that is always the case. I believe that with a resource like this they are relying on the Arduino community as a whole to make any necessary corrections but most of the playground readers probably do not feel that they are experienced enough to correct something that has been posted there by someone else.

Don

I think I didn't really get the structure of the playground, I realized that it has ton of links around, where code actually are, and there's a chance to comment them pros and cos.

So, just have to be patient and test the code that might be usable for your application, if problems exists, then the forum is here waiting.
:slight_smile:

Cheers,
Kari

Do you think I should use SoftwareSerial(2, 2)? Or some other unused input pin?

People normally use SoftwareSerial(255, 2) or some other large value that will never be used by an output pin.

A few suggestions

  • change to the newsoftserial library rather than the software serial one.
  • have you tried resetting the serial LCD (as far as I can remember - there is a command for this or is it just to reset to 9600 baud?)
  • have you asked Sparkfun about it as they wrote the code on the pic chip which controls the display so they might have a better idea (I presume it is a Sparkfun one - did I miss this somewhere?)

Follow the LCD initialization link at http://web.alfredstate.edu/weimandn for a complete explanation.

Interesting, thanks.

I tried to implement that initialization as follows:

  delay(110);   // Step 1: > 100ms
  
  lcd_do(0x30); // Step 2: Function Set
  delay(5);     // > 4.1ms
  
  lcd_do(0x30); // Step 3: Function Set
  delay(1);     // > 100us
  
  lcd_do(0x30); // Step 4: Function Set
  delay(1);     // > 100us
  
  lcd_do(0x38); // Step 5: Function Set D=1 N=1 F=0
  delay(1);     // > 53us

  lcd_do(0x08); // Step 6: Display off
  delay(1);     // > 53us
  
  lcd_do(0x01); // Step 7: clear
  delay(5);     // > 3ms
  
  lcd_do(0x38); // Step 8: Entry Mode set: I/D=1, S=0
  delay(1);     // > 53us

  // step 9 = nothing  

  lcd_do(0x0C); // Step 10: Display on D=1, C=0, B=0
  delay(1);     // > 53us

Unfortunately this did not help. Any ideas?

People normally use SoftwareSerial(255, 2) or some other large value that will never be used by an output pin.

Ok, thanks. I changed this now, but unfortunately it did not change anything.

change to the newsoftserial library rather than the software serial one.

Ok, I tried this as well. No change either.

have you tried resetting the serial LCD (as far as I can remember - there is a command for this or is it just to reset to 9600 baud?)

There is a command to set the baud rate. I don't think there is a reset command.

I presume it is a Sparkfun one - did I miss this somewhere?

Yes it is. (see first page in this topic)