Show Posts
Pages: [1]
1  Using Arduino / Networking, Protocols, and Devices / Re: Realtime clock running not correct on: April 08, 2013, 09:22:57 pm
I think arduino didn't write time parameter to ds1307 !  smiley-confuse
2  Using Arduino / Networking, Protocols, and Devices / Re: Realtime clock running not correct on: April 06, 2013, 07:57:20 am
Yes , i have battery 3V for DS1307, but i think when the power off, battery should be backup time . is that right ?
3  Using Arduino / Networking, Protocols, and Devices / Realtime clock running not correct on: April 05, 2013, 09:15:15 pm
hi every body ! i found a source code to use RTC DS1307 and display time on LCD1602. When i upload code to arduino. The time on LCD is correct. But when i unplug USB cable and then plug it to computer again. the time is not correct. Please help me correct it ! Thanks
here is my code :

*
Quote
by Leocarbon @leocrbn@gmail.com
* @http://twitter.com/mangodaniel
* @http://leocarbon.oa.to
* @http://electronicmango.blogspot.com
* @http://youtube.com/newelectricmango
* @http://youtube.com/leocrbn
*
*Verison History (last updated 12.24.12)
* 1.0.0.0.r2 (compile 0145)
*
* 1.0.0.0.r2 (12.24.12)
* - Uses Adafruit's RTClib @https://github.com/adafruit/RTClib
* - Updates DS1307's time each and every upload
* - Backlight
* - LCD compatible
* - Eye-soothing 30 fps (33.33 millisecond frame delay)
* - Friendly code commenting lol
* - Thanks to Adafruit & Ladyada
*
*
*
* RTC is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
*/
#include <Wire.h>
#include <LiquidCrystal.h>
#include <RTClib.h>
 
RTC_Millis RTC; //New DS1307 RTC

LiquidCrystal LCD(3,4,5,6,7,8); //New Liquid Crystal Display
int backlightOut = 9; //LCD backlight pin
int backlightIn = 2; //
unsigned long backlightTiming; //backlight ON timing (millis())
byte backlightState;

void setup(){
  RTC.begin(DateTime(__DATE__,__TIME__)); //Start RTC
  Wire.begin(); //Start Serial
  LCD.begin(2,16); //Start LCD
  LCD.clear(); //Clear LCD just in case
  pinMode(backlightOut,OUTPUT); //LCD backlight
  //pinMode(backlightIn,INPUT_PULLUP); //LCD backlight trigger switch signal input pin
  //digitalWrite(backlightOut,HIGH); //Turn on backlight on start
}

void loop(){
  backlightTiming = millis(); //Backlight timing
  backlightState = digitalRead(backlightIn); // Read the LCD backlight trigger switch signal input pin
  if(backlightTiming >= 3000){
    digitalWrite(backlightOut,LOW); //Turn LCD backlight off if 3 seconds (3000 milliseconds) has passed since the start of the code
  }
  if(backlightState == 1){
    digitalWrite(backlightOut,HIGH); //Turn LCD backlight on on tilt (for tilt switches (poorman's gyroscope))
  }
  DateTime now = RTC.now(); //update the DS1307's time (you should do this every year; at least)
  //Time - Screen position filtering
  if (now.month() < 10 && now.day() < 10){
    LCD.setCursor(4,0);
  }
  else {
    LCD.setCursor(3,0);
  }
  LCD.print(now.day());
  LCD.print("/");
  LCD.print(now.month());
  LCD.print("/");
  LCD.print(now.year());
  LCD.print(" ");
  //Time - Screen position filtering
  if (now.hour() < 10 && now. minute() < 10){
    LCD.setCursor(5,1);
  }
  else if (now.hour() < 10 && now.second() < 10){
    LCD.setCursor(5,1);
  }
  else if (now.second() < 10 && now. minute() < 10){
    LCD.setCursor(5,1);
  }
  else if (now.hour() < 10 && now. minute() < 10 && now.second() < 10){
    LCD.setCursor(5,1);
  }
  else {
    LCD.setCursor(4,1);
  }
  LCD.print(now.hour());
  LCD.print(':');
  LCD.print(now.minute());
  LCD.print(':');
  LCD.print(now.second());
  delay(33.33); //30 fps
  LCD.clear(); //update screen
}
Pages: [1]