Go Down

Topic: RTC to 4Bit LCD (Read 2 times) previous topic - next topic

Vancouver Reefer

Hi All,

Im in need of some help as im tearing my hair out!!!!

I have a 2 wire RTC and a 4x16 4Bit LCD.

I have been trying to alter every single bit of serial.print source code i can find to allow me to show the time and date on my LCD.

Everything i try and everything i read just is not working. Ive been on this for about 5 days now and i just wish i had bought a serial LCD ( Newb Mistake!!! )

Here is what i have so far:

I have been trying to alter Maurice Ribble's code:

#include <LCD4Bit.h>
#include "Wire.h"
#define DS1307_I2C_ADDRESS 0x68
LCD4Bit lcd = LCD4Bit(2);

// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
 return ( (val/10*16) + (val%10) );
}

// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
 return ( (val/16*10) + (val%16) );
}

// Stops the DS1307, but it has the side effect of setting seconds to 0
// Probably only want to use this for testing
/*void stopDs1307()
{
 Wire.beginTransmission(DS1307_I2C_ADDRESS);
 Wire.send(0);
 Wire.send(0x80);
 Wire.endTransmission();
}*/

// 1) Sets the date and time on the ds1307
// 2) Starts the clock
// 3) Sets hour mode to 24 hour clock
// Assumes you're passing in valid numbers
void setDateDs1307(byte second,        // 0-59
                  byte minute,        // 0-59
                  byte hour,          // 1-23
                  byte dayOfWeek,     // 1-7
                  byte dayOfMonth,    // 1-28/29/30/31
                  byte month,         // 1-12
                  byte year)          // 0-99
{
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.send(0);
  Wire.send(decToBcd(second));    // 0 to bit 7 starts the clock
  Wire.send(decToBcd(minute));
  Wire.send(decToBcd(hour));      // If you want 12 hour am/pm you need to set
                                  // bit 6 (also need to change readDateDs1307)
  Wire.send(decToBcd(dayOfWeek));
  Wire.send(decToBcd(dayOfMonth));
  Wire.send(decToBcd(month));
  Wire.send(decToBcd(year));
  Wire.endTransmission();
}

// Gets the date and time from the ds1307
void getDateDs1307(byte *second,
         byte *minute,
         byte *hour,
         byte *dayOfWeek,
         byte *dayOfMonth,
         byte *month,
         byte *year)
{
 // Reset the register pointer
 Wire.beginTransmission(DS1307_I2C_ADDRESS);
 Wire.send(0);
 Wire.endTransmission();

 Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

 // A few of these need masks because certain bits are control bits
 *second     = bcdToDec(Wire.receive() & 0x7f);
 *minute     = bcdToDec(Wire.receive());
 *hour       = bcdToDec(Wire.receive() & 0x3f);  // Need to change this if 12 hour am/pm
 *dayOfWeek  = bcdToDec(Wire.receive());
 *dayOfMonth = bcdToDec(Wire.receive());
 *month      = bcdToDec(Wire.receive());
 *year       = bcdToDec(Wire.receive());
}

void setup()
{
 lcd.init();
 byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
 Wire.begin();
 Serial.begin(9600);

 // Change these values to what you want to set your clock to.
 // You probably only want to set your clock once and then remove
 // the setDateDs1307 call.
 second = 45;
 minute = 15;
 hour = 12;
 dayOfWeek = 3;
 dayOfMonth = 21;
 month = 1;
 year = 9;
 setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
}

void loop()
{
 byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

 getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
 Serial.print(":");
 Serial.print(minute, DEC);
 Serial.print(":");
 Serial.print(second, DEC);
 Serial.print("  ");
 Serial.print(month, DEC);
 Serial.print("/");
 Serial.print(dayOfMonth, DEC);
 Serial.print("/");
 Serial.print(year, DEC);
 Serial.print("  Day_of_week:");
 Serial.println(dayOfWeek, DEC);

 delay(1000);
}


Every time i try to alter any of the Serial.print to lcd.print i get compiler errors.

Please could someone take a look and help me alter this code from serial to show on my LCD. I swear im going bald and im only 29!!!!   :o

VR

Anachrocomputer

Could you post the exact wording of the compiler error message, please?

Vancouver Reefer

So here is where i try to later the sketch to output the time and date to my lcd:

lcd.clear();
lcd.print(":");
Serial.print(minute, DEC);
Serial.print(":");
Serial.print(second, DEC);
Serial.print("  ");
Serial.print(month, DEC);
Serial.print("/");
Serial.print(dayOfMonth, DEC);
Serial.print("/");
Serial.print(year, DEC);
Serial.print("  Day_of_week:");
Serial.println(dayOfWeek, DEC);

And this is the compiler error im getting:

In function 'void loop()':
error: invalid conversion from 'const char*' to 'int

This is my first lcd and rtc project and its really hurting my head!  

VR

mem

I was able to compile the code in your first post without any compiler error. I did comment out the lcd calls - you may want to try doing that to see if the problem is in that code. I use the liquidCrystal library that is distributed with version 0012, any reason you aren't using that?

Vancouver Reefer

#4
Jan 27, 2009, 01:01 am Last Edit: Jan 27, 2009, 01:19 am by Vancouver_Reefer Reason: 1
Ok so have i got my wires crossed here somewhere?

Im a newb and this is my first programming project so excuse my niaevety.

I have downloaded the 4 bit lcd library after following ladyada's post on lcds, that then allowed me to get my lcd using 4 bits instead of 8.

The above post does work fine when you compile it but all i can do is see the time and date on the serial monitor. I was trying to adjust the code to allow it to show on my lcd instead.

if im making some real newb errors i can understand. I got the rest of the things working on my LCD but then the time and date has been impossible!!!


Ok so now i have just gone to anrduino on my laptop and opened up the "hello world" from the liquidcrystal lib and it wont compile??? same with any of the other example sketches from the liquid lib??

what am i doing wrong? The libs are stored on the arduino/hardware/library files on my hard drive???????

The compiler error reads:

error: no matching function for call to 'LiquidCrystal::LiquidCrystal(int, int, int, int, int, int, int)'hardware\libraries\LiquidCrystal/LiquidCrystal.h:8: note: candidates are: LiquidCrystal::LiquidCrystal()


hardware\libraries\LiquidCrystal/LiquidCrystal.h:6: note:                 LiquidCrystal::LiquidCrystal(const LiquidCrystal&)


In function 'void setup()':



Go Up