Problem with data types?

Hi there

I have a Duemilanove hocked up to a LCD03 from robot electronics via I2C and a I2C RTC. The RTC works great along with the LCD. I can view the times view the serial port and put stuff on the LCD.

I now want to be able to display the time on the LCD. I am using the following to try and display the data on the LCD - "Wire.write(daynow);". I have played around with the data types but nothing I try works. If I use "Wire.write("04")"; Then it will work but does not seem to work with a variable.

I am using the following tutorial/libary to get the RTC to work - DS1307 RTC tutorial

  DateTime now = RTC.now();
   
   
  unsigned int hournow;
  unsigned int minutenow;
  unsigned int secondnow;
  char daynow;
  unsigned int monthnow;
  unsigned int yearnow;

  hournow = (now.hour(), DEC);
  minutenow = (now.minute(), DEC);
  secondnow = (now.second(), DEC);
  
  daynow = (now.day(), DEC);
  monthnow = (now.month(), DEC);
  yearnow = (now.year(), DEC);

Wire.beginTransmission(address);
  Wire.write(0);
  Wire.write(2);
  Wire.write(5);
  delay(50);
  Wire.write("Current time");
  Wire.write(2);
  Wire.write(47);
  delay(50);
  Wire.write(daynow);
  Wire.endTransmission();
  delay(50);

you have daynow as a char. this will only hold one asscii symbol. it needs to be a string i haven't used them on arduino so i'm not 100% on how to implemented them.

Hi

Yes I was just playing round with the Char. I would have thought that having it as an unsigned int should work though, but it does not.

David

If Wire.write("04") show 04 on the LCD, then:

char time[] = "04";
Wire.write(time);

will, too. If that works, then so will:

char time[12];
sprintf(time, "%02d:%02d:%02d", hournow, minutenow, secondnow);
Wire.write(time);

Hi there

Thanks for the help! Getting closer but still got a problem.

If I use the code you suggested it prints 10:10:10 on the screen. I have just been playing around with it just now and found that the code below works great.

    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();

But the code below (which is what I am using does not) - It just gives 10:10:10.

  hournow = (now.hour(), DEC);
  minutenow = (now.minute(), DEC);
  secondnow = (now.second(), DEC);

  Serial.print(hournow);
  Serial.print(":");
  Serial.print(minutenow);
  Serial.print(":");
  Serial.println(secondnow);
 hournow = (now.hour(), DEC);

If you assign the value 10 (aka DEC) to a variable, and then print the variable, then 10 is the value you'd hope to see.

Try

 hournow = now.hour();

Thanks for that!

That's is going now.

Thank you!

David