如何使用arduino从sim900模块的RTC读取日期和时间数据? [英] How can I read date and time data from RTC of sim900 module using arduino?
本文介绍了如何使用arduino从sim900模块的RTC读取日期和时间数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include "SIM900.h"
#include <SoftwareSerial.h>
#include "sms.h"
SMSGSM sms;
boolean started=false;
int count = 0;
void setup()
{
pinMode(5, INPUT); // input pin for switch
Serial.begin(9600);
if (gsm.begin(2400))
{
Serial.println("\nstatus=READY");
started=true;
}
else Serial.println("\nstatus=IDLE");
delay(1000);
}
void loop()
{
if (digitalRead(5)==1)
{
delay(500);
if (digitalRead(5)==1)
{
count = count+1;
/*if(started)
{
if (sms.SendSMS("+12345678", "ALARM"))
Serial.println("\nSMS sent OK");
}*/
Serial.println("Count = ");
Serial.println(count);
readtime();
Serial.println(content);
}
}
else
{
Serial.println("Normal");
}
}
我使用带有 arduino 的 sim 900 来检测输入引脚 5 的变化,然后向用户发出警报.我有几个问题需要您的帮助
I use sim 900 with arduino to detect change of input pin 5 and then ALARM to user. I have a few question that need your help
- 我如何知道 sim 900 使用哪个引脚来发送短信?我在 D2 和 D3 处使用跳线.是用了这两个引脚吗?因为在我的程序中我使用了一个 .h 包含文件,我不知道里面的细节.
- 如何从 sim 900 模块中的 RTC 读取日期和时间数据并将其存储在变量中,然后将它们用于数据记录器?我知道如果我已经在 RTC 中设置了日期和时间,则可以通过AT+CCLK?"读取.并返回日期和时间数据.但是我如何在我的程序中使用这个命令?
推荐答案
我找到了这段代码并且对我有用.首先你询问时间,然后期待答案并解析它.
I found this code and work for me. First you ask for time and then expect answers and parse it.
const char* const SIM900::getTimeStamp(){
Serial2.print("AT+CCLK?"); //SIM900 AT command to get time stamp
Serial2.print(13,BYTE);
delay(2000);
if (Serial2.available()>0){
int i = 0;
while (Serial2.available()>0){
timeStamp[i]=(Serial2.read());
i++;
}
}
int years = (((timeStamp[25])-48)*10)+((timeStamp[26])-48);
int months = (((timeStamp[22])-48)*10)+((timeStamp[23])-48);
int days = (((timeStamp[19])-48)*10)+((timeStamp[20])-48);
int hours = (((timeStamp[28])-48)*10)+((timeStamp[29])-48);
int mins = (((timeStamp[31])-48)*10)+((timeStamp[32])-48);
int secs = (((timeStamp[34])-48)*10)+((timeStamp[35])-48);
//YOUR CODE HERE
}
这篇关于如何使用arduino从sim900模块的RTC读取日期和时间数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文