Go Down

Topic: Single digit, Seven segment Numitron program and pcb design needed. (Read 19664 times) previous topic - next topic

Daddyfredregill

So will the ds1307 rtc library work for my 1340. The 1340 can do 12h time, I thought the 1307 could only do 24h format? :o

EDIT- the 1307 does 12H as well. I will try the adafruit RTC in the IED library and see if that works.

Daddyfredregill

So i installed the RTClib folder found in manage libraries. I hooked up my RTC with super cap and crystal. I went to sketches and clicked on RTClib but nothing came up. The text in the code says, #include <RTClib.h>. That is it. Do I have to load the library somewhere else.

Daddyfredregill

Just ran a I2C scanner sketch and my rtc device was found at address 0x86. So My RTC is showing up.

Daddyfredregill

I figured out where all the libraries go and examples. So I think I am connected. Just need a sketch and understanding how RTC work.

wvmarle

Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Daddyfredregill

I found an RTC library for a ds3231 and it has a Test sketch and a settime sketch. When i load the test sketch i can open up the serial monitor and it shows the rtc reading every second. So it seems like they are working.

When i load the set time sketch. The serial monitor is blank. Do i need to set the time within the Arduino IDE or within the serial monitor?

wvmarle

I don't know the sketch - my best guess is that it'll ask you for the time, you can probably see that in the source.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Daddyfredregill

Here is the sketch, I know I am supposed to set the time in YYMMDDwHHMMSSx format. Just not sure where. I was following this tutorial. https://youngxotaniemi.wordpress.com/2014/10/16/arduino-20-jeelabs-rtc-ds1340-tutorial-for-dummies/

Daddyfredregill

Code: [Select]
/*
DS3231_set.pde
Eric Ayars
4/11

Test of set-time routines for a DS3231 RTC

*/

#include <DS3231.h>
#include <Wire.h>

DS3231 Clock;

byte Year;
byte Month;
byte Date;
byte DoW;
byte Hour;
byte Minute;
byte Second;

void GetDateStuff(byte& Year, byte& Month, byte& Day, byte& DoW,
byte& Hour, byte& Minute, byte& Second) {
// Call this if you notice something coming in on
// the serial port. The stuff coming in should be in
// the order YYMMDDwHHMMSS, with an 'x' at the end.
boolean GotString = false;
char InChar;
byte Temp1, Temp2;
char InString[20];

byte j=0;
while (!GotString) {
if (Serial.available()) {
InChar = Serial.read();
InString[j] = InChar;
j += 1;
if (InChar == 'x') {
GotString = true;
}
}
}
Serial.println(InString);
// Read Year first
Temp1 = (byte)InString[0] -48;
Temp2 = (byte)InString[1] -48;
Year = Temp1*10 + Temp2;
// now month
Temp1 = (byte)InString[2] -48;
Temp2 = (byte)InString[3] -48;
Month = Temp1*10 + Temp2;
// now date
Temp1 = (byte)InString[4] -48;
Temp2 = (byte)InString[5] -48;
Day = Temp1*10 + Temp2;
// now Day of Week
DoW = (byte)InString[6] - 48;
// now Hour
Temp1 = (byte)InString[7] -48;
Temp2 = (byte)InString[8] -48;
Hour = Temp1*10 + Temp2;
// now Minute
Temp1 = (byte)InString[9] -48;
Temp2 = (byte)InString[10] -48;
Minute = Temp1*10 + Temp2;
// now Second
Temp1 = (byte)InString[11] -48;
Temp2 = (byte)InString[12] -48;
Second = Temp1*10 + Temp2;
}

void setup() {
// Start the serial port
Serial.begin(9600);

// Start the I2C interface
Wire.begin();
}

void loop() {

// If something is coming in on the serial line, it's
// a time correction so set the clock accordingly.
if (Serial.available()) {
GetDateStuff(Year, Month, Date, DoW, Hour, Minute, Second);

Clock.setClockMode(false); // set to 24h
//setClockMode(true); // set to 12h

Clock.setYear(Year);
Clock.setMonth(Month);
Clock.setDate(Date);
Clock.setDoW(DoW);
Clock.setHour(Hour);
Clock.setMinute(Minute);
Clock.setSecond(Second);

// Test of alarm functions
// set A1 to one minute past the time we just set the clock
// on current day of week.
Clock.setA1Time(DoW, Hour, Minute+1, Second, 0x0, true,
false, false);
// set A2 to two minutes past, on current day of month.
Clock.setA2Time(Date, Hour, Minute+2, 0x0, false, false,
false);
// Turn on both alarms, with external interrupt
Clock.turnOnAlarm(1);
Clock.turnOnAlarm(2);

}
delay(1000);
}

Daddyfredregill

I found another library and tried it. I get the same results. The test sketch loads in correctly. The when i open the serial monitor it gives you the date and time and refreshes every second. But the time never changes. It is like the clock is not being accessed or the clock is not working.

wvmarle

Probably the DS1340 uses different commands to set it.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Go Up