0
#include <Wire.h>
#include "RTClib.h"
#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
#define Serial SerialUSB
#endif
RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
void setup () {
#ifndef ESP8266
while (!Serial); // for Leonardo/Micro/Zero
#endif
Serial.begin(9600);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
}
void loop () {
DateTime now = rtc.now();
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" (");
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
Serial.print(" since midnight 1/1/1970 = ");
Serial.print(now.unixtime());
Serial.print("s = ");
Serial.print(now.unixtime() / 86400L);
Serial.println("d");
// calculate a date which is 7 days and 30 seconds into the future
DateTime future (now + TimeSpan(7,12,30,6));
Serial.print(" now + 7d + 30s: ");
Serial.print(future.year(), DEC);
Serial.print('/');
Serial.print(future.month(), DEC);
Serial.print('/');
Serial.print(future.day(), DEC);
Serial.print(' ');
Serial.print(future.hour(), DEC);
Serial.print(':');
Serial.print(future.minute(), DEC);
Serial.print(':');
Serial.print(future.second(), DEC);
Serial.println();
Serial.println();
delay(3000);
}

enter image description here

If i use 57600 i'll get random symbols in one line 1 line. I have connected PIN5 IN1307N to A4, PIN4 IN1307N to A5

enter image description here

asked Sep 5, 2016 at 12:11
6
  • What about pull-ups on SDA/SCL? Commented Sep 5, 2016 at 12:18
  • yup applied. 10k to vcc Commented Sep 5, 2016 at 12:21
  • Maybe try to use 4k7 (or two 10k in parallel) and shorter wires but it's a wild guess. And you can try I2C scanner if RTC is even found. BTW value 165 is not so random as you think. It's 0xF*10 + 0xF e.g. 0xFF to BCD code. Commented Sep 5, 2016 at 12:39
  • Scanning... No I2C devices found Commented Sep 5, 2016 at 12:46
  • Check your wiring: A4 = SDA -> PIN5, A5 = SCL -> PIN6 (PIN4 is GND terminal) Commented Sep 5, 2016 at 12:56

1 Answer 1

0

enter image description here

Following this circuitry solved my issue but still i've not understand the difference between DS1307 and IN1307N.

answered Sep 5, 2016 at 15:57
1
  • There shouldn't be any difference. Just different factory making the chip. Commented Sep 5, 2016 at 19:02

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.