[code]hi forum members
I have a ds 1307 I can not get it to set the time properly. I have tried the example sketch as follows
[code#include <WProgram.h>
#include <Wire.h>
#include <DS1307.h>
void setup()
{
Serial.begin(9600);
pinMode(13, OUTPUT);
pinMode(9,OUTPUT);
RTC.stop();
RTC.set(DS1307_SEC,1); //set the seconds
RTC.set(DS1307_MIN,50); //set the minutes
RTC.set(DS1307_HR,1); //set the hours
RTC.set(DS1307_DOW,4); //set the day of the week
RTC.set(DS1307_DATE,15); //set the date
RTC.set(DS1307_MTH,9); //set the month
RTC.set(DS1307_YR,11); //set the year
RTC.start();
}
void loop()
{
Serial.print(RTC.get(DS1307_HR,true)); //read the hour and also update all the values by pushing in true
Serial.print(":");
Serial.print(RTC.get(DS1307_MIN,false));//read minutes without update (false)
Serial.print(":");
Serial.print(RTC.get(DS1307_SEC,false));//read seconds
Serial.print(" "); // some space for a more happy life
Serial.print(RTC.get(DS1307_DATE,false));//read date
Serial.print("/");
Serial.print(RTC.get(DS1307_MTH,false));//read month
Serial.print("/");
Serial.print(RTC.get(DS1307_YR,false)); //read year
Serial.println();
delay(1000);
if (RTC.get(DS1307_HR, false) == 1 &&
RTC.get(DS1307_MIN, false) == 50 &&
RTC.get(DS1307_SEC, false) == 30){
digitalWrite (13, HIGH);
digitalWrite (9, HIGH);
}
if (RTC.get(DS1307_HR, false) == 1 &&
RTC.get(DS1307_MIN, false) == 55 &&
RTC.get(DS1307_SEC, false) == 00){
digitalWrite (13, LOW);
digitalWrite (9, LOW);
}
}]
it uploads fine but all I get in the serial monitor is 12:23:0 45/21/2009 over and over
it worked fine for awhile. after I hooked up my led array that im using the uno to switch on and off the rtc would time out and show all 0 in every value spot. I did some research and found out that when my leds turned on it pulled to much current so I unhooked it from the sensor shield and wired it up scl to a5 sda to a4and vs to 5v out on supply rail and ground to ground of supply rail....now it shows the wrong values for date and time but I also can not set them even with the second sketch.
I also found this code here but I get the same results
[code
#include "Wire.h"
#define DS1307_ADDRESS 0x68void setup(){
Wire.begin();
Serial.begin(9600);
}void loop(){
printDate();
delay(1000);
}byte bcdToDec(byte val) {
// Convert binary coded decimal to normal decimal numbers
return ( (val/16*10) + (val%16) );
}void printDate(){
// Reset the register pointer
Wire.beginTransmission(DS1307_ADDRESS);byte zero = 0x00;
Wire.write(zero);
Wire.endTransmission();Wire.requestFrom(DS1307_ADDRESS, 7);
int second = bcdToDec(Wire.read());
int minute = bcdToDec(Wire.read());
int hour = bcdToDec(Wire.read()); //24 hour time
int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
int monthDay = bcdToDec(Wire.read());
int month = bcdToDec(Wire.read());
int year = bcdToDec(Wire.read());//print the date EG 3/1/11 23:59:59
Serial.print(month);
Serial.print("/");
Serial.print(monthDay);
Serial.print("/");
Serial.print(year);
Serial.print(" ");
Serial.print(hour/12);
Serial.print(":");
Serial.print(minute);
Serial.print(":");
Serial.println(second);}
][/code]
any thought or ideas you can give me would be awesome thx guys
and I cant figure out why the first code did not copy properly but it came from the examples used with 0022