Pages: 1 [2]   Go Down
Author Topic: Problem with LCD code  (Read 2338 times)
0 Members and 1 Guest are viewing this topic.
Lancashire, UK
Offline Offline
Edison Member
*
Karma: 9
Posts: 1991
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset



What is imitation the sincerest form of ?  smiley-wink
Logged


London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Strange, the LCD display is functioning correctly for me using the code I posted. I have been running an enhanced version (uses the Ethernet shield to sync the time from an NTP time server) and its been working correctly for over an hour.

Are you sure you have replaced LiquidCrystal.cpp with the posted version?
Logged

Lancashire, England
Offline Offline
Newbie
*
Karma: 0
Posts: 41
Electronics Noob
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yup, as a quick test I added some completely random characters to the new LiquidCrystal.cpp and it failed to complile, removed them and it compiles fine. Just doesn't work. Weird yes, annoying yes, damned if I know how to fix it. :S
Logged

Lancashire, England
Offline Offline
Newbie
*
Karma: 0
Posts: 41
Electronics Noob
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@pluggy

Not quite, you're in Lancs UK, I'm in the one in England. smiley-grin

Plus if this is my imitation of you, it's probably not very flattering. :-[
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

did you try the sketch posted in reply #11 (using LiquidCrystal lcd(12, 11, 5, 4, 3, 2) or whatever you need for  your lcd wiring)

« Last Edit: December 03, 2009, 02:10:38 pm by mem » Logged

Lancashire, England
Offline Offline
Newbie
*
Karma: 0
Posts: 41
Electronics Noob
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yup, same result, it doesn't work.
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you put an lcd.print("hello world") in setup followed by a long delay, can you see the output on the LCD?

fwiw, the code I am running here is still working perfectly, so would be interested to find out what is different in your tests.
« Last Edit: December 03, 2009, 05:00:48 pm by mem » Logged

Lancashire, England
Offline Offline
Newbie
*
Karma: 0
Posts: 41
Electronics Noob
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, this is just mad.

First change, added:

Code:
lcd.print("hello world");
delay(10000);

to setup(). That was displayed just fine.

Next I removed the Serial.println("");, but now the "hello world" message gets displayed but the first two characters are corrupted, but the time gets displayed OK.

Almost seems like there is a buffer that is being created but not initialised correctly.

Here is the current state of my code:

Code:
#include <LiquidCrystal.h>
#include <WProgram.h>
#include <Wire.h>
#include <DS1307.h>

int rtc[7];

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

void setup()
{
// Uncomment these lines if you want to set the time on startup
/*
  RTC.stop();
  RTC.set(DS1307_SEC,0);
  RTC.set(DS1307_MIN,26);
  RTC.set(DS1307_HR,15);
  RTC.set(DS1307_DOW,6);
  RTC.set(DS1307_DATE,29);
  RTC.set(DS1307_MTH,11);
  RTC.set(DS1307_YR,9);
  RTC.start();
*/
  // set up the LCD's number of rows and columns:
  lcd.begin(16, 2);
  lcd.print("hello world");
  delay(10000);
}

char* dayOfWeek[] = {"xxx", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};

void loop()
{
  RTC.get(rtc,true);

  lcd.setCursor(0,0);
  //lcd.print(millis());
  printDigits(rtc[2],':');
  printDigits(rtc[1],':');
  printDigits(rtc[0],' ');
  
  lcd.print(dayOfWeek[rtc[3]]);
  
  lcd.setCursor(0,1);
  printDigits(rtc[4],'/');
  printDigits(rtc[5],'/');
  printDigits(rtc[6],' ');

  //Serial.println("");
  delay(100);
}

void printDigits(int digits, char delimiter)
{
  if(digits < 10) {
    lcd.print('0');
  }
  lcd.print(digits,DEC);
  lcd.print(delimiter);
}

If I change "hello world" to ".", it displays a double bar symbol for 10 seconds, then the dayOfWeek is corrupted and becomes a double bar. If I change it to ".,", then I get two corrupt characters for 10 seconds then the main loop displays mostly garbage which bears a slight resemblance to the time and date. ".,/" goes back to a basically blank screen. "hello" performs the same as "hello world".

This is insane!

I think I'm going to try using a different computer, I'm wondering if there is an incompatibility with W7x64 RC1 somewhere. I'll give it a go on my XP based netbook tomorrow sometime. The fact that adding or removing code from loop() is affecting code running in setup() just strikes me as ridiculous unless there is a compiler problem/incompatibility somewhere.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 650
Posts: 50833
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Since the code is being executed on an Arduino, and displayed on an LCD, I fail to see how compiling the code on a different computer will make any difference.

However, I will be interested in hearing whether that makes any difference.

The Serial.println should not do anything, because you don't have a Serial.begin statement. Serial.println should (but maybe doesn't) know whether or not Serial.begin was called, and do absolutely nothing if it wasn't.
Logged

Lancashire, England
Offline Offline
Newbie
*
Karma: 0
Posts: 41
Electronics Noob
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If there was a bug or incompatibility in the compiler/IDE/USB drivers then that could quite easily affect the way the code was compiled and uploaded to the Arduino. If the code is compiled wrong, then anything could happen.
Logged

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

I am new to this forum, i am building some stuff for home use.
One of the things i had troubles, was the LCD.
As i watch this topic, there is a similar problem i had too.

Quote
If I change "hello world" to ".", it displays a double bar symbol for 10 seconds, then the dayOfWeek is corrupted and becomes a double bar. If I change it to ".,", then I get two corrupt characters for 10 seconds then the main loop displays mostly garbage which bears a slight resemblance to the time and date. ".,/" goes back to a basically blank screen. "hello" performs the same as "hello world".

My LCD did not show anything, i also have the DS1307. My problem was simple the power of the LCD, if you get 00:00:00 time and date or garbage caracters, then it meant in my case that the needed power to the DS1307 is too short, because the LCD used too much.
I solved this with a second 7805 i added for the lcd and the trouble was gone. I had the same troubles, first a few seconds time and date and after some seconds garbage.
That is maybe, i think for 100% the trouble in this case.

I use this forum to get solutions.
I hope this will solve your LCD troubles.
« Last Edit: December 06, 2009, 04:44:28 am by sediek » Logged

Pages: 1 [2]   Go Up
Jump to: