I've got a bit of a problem trying to read the time from the RTC from a SIM900 shield and was hoping someone on here might have an answer. Its probably very obvious but as a fairly inexperienced hobbyist it is driving me mad.
I'll give you some background even though it might be boring it could be helpful.
I've had the SIM900 based GPRS shield from Maplin (Linksprite) for some time but only now started to include it into a project idea I have.
I want to build a monitoring system for my narrow boat and want it to send text messages if there is a problem or to receive text messages to turn things on / off.
Part of the project was using a cheap RTC module and I found that it kept time about as good as my 5 euro Rolex I brought from some dodgy bloke on Tenerife beach.
As the Sim900 has a RTC built and also get the time from the network its seemed a good idea to ditch the cheap RTC.
I managed to change the setting so the SIM900 gets the network time and during test this has proved to be very accurate so a big plus on that one.
The problem I have is reading the time back into my Arduino and after hours spent trawling forums came to the conclusion that everyone had given up.
So I spent some time trying to work it out and have had some success but its not perfect and I can't seem to work out the problem.
My set up for testing is very basic. Arduino Mega, GPRS shield (but not placed on top of the mega) connected to serial 1. Once I work out the problems I will build it into my project.
The time is accessed by the command AT+CCLK? this returns a long string with the date and time (plus all the other rubbish that they send back)
The code below basically sends the command to get the time then using parseInt to put the date and time into number of strings.
The strings are Year, Months, Days, Hours, Mins, Sec and Nu. Nu is not used and is only there to put the time zone code in. If I don't have this the next read is out.
The date and time is then sent to the Serial Monitor on the PC, this is repeated every 10 seconds. I've tried longer delays but doesn't make any difference.
The code I'm using is:-
void setup() {
Serial.begin(19200);
Serial1.begin(19200);
}
void loop() {
Serial1.print("AT+CCLK?\r");
while (Serial1.available() > 0) {
int Years = Serial1.parseInt();
int Months = Serial1.parseInt();
int Days = Serial1.parseInt();
int Hours = Serial1.parseInt();
int Mins = Serial1.parseInt();
int Secs = Serial1.parseInt();
int Nu = Serial1.parseInt();
Serial.print(Years);
Serial.print("/");
Serial.print(Months);
Serial.print("/");
Serial.print(Days);
Serial.print(" ");
Serial.print(Hours);
Serial.print(":");
Serial.print(Mins);
Serial.print(":");
Serial.print(Secs);
Serial.println();
}
delay(10000);
}
What I get is two good reads, a delay then all zeros and this repeats. There does seem to be a delay and puts the timing out of sequence by about 7 seconds.
15/3/25 20:41:30
15/3/25 20:41:40
0/0/0 0:0:0
15/3/25 20:41:57
15/3/25 20:42:7
0/0/0 0:0:0
15/3/25 20:42:24
15/3/25 20:42:34
0/0/0 0:0:0
15/3/25 20:42:51
15/3/25 20:43:1
0/0/0 0:0:0
15/3/25 20:43:18
15/3/25 20:43:28
0/0/0 0:0:0
15/3/25 20:43:45
15/3/25 20:43:55
0/0/0 0:0:0
Going to need a wig at this rate so any help will be greatly appreciated.