发送短信1的时间与Arduino的GPRS SIM900如果iput是HIGH [英] send SMS for 1 time with arduino GPRS SIM900 if an iput is HIGH

查看:385
本文介绍了发送短信1的时间与Arduino的GPRS SIM900如果iput是HIGH的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面对发送短信1如果输入为高一个问题,如果它是低==>没有SMS发送,如果低到高==>发送短信1。
这code不工作,只是发来的短信,当我打开GPRS,并没有什么发生了。

mclopez帮助我,谢谢你,但没有工作:(,这是新的code,我的延迟()■写的,但同样的问题。

感谢您的帮助提前。

 的#include< SoftwareSerial.h>
   #包括TimerOne.h   const int的DI = 2;
   const int的DT = 3;
   const int的DGP1 = 4;
   const int的DGP2 = 5;
   常量间隔长= 100000; //微秒   INT值1 = 0;
   INT值2 = 0;
   INT值3 = 0;
   INT值4 = 0;   INT value1_old = 0;
   INT value2_old = 0;
   INT value3_old = 0;
   INT value4_old = 0;   布尔changed1 = FALSE;
   布尔changed2 = FALSE;
   布尔changed3 = FALSE;
   布尔changed4 = FALSE;   SoftwareSerial SIM900(7,8);   无效SIM900power(){
     digitalWrite(9,高);
     延迟(1000);
     digitalWrite(9,低);
     延迟(5000);
   }  无效初始(){
  SIM900.print(AT + CMGF = 1 \\ r);
  延迟(100);
  SIM900.println(AT + CMGS = \\XXXXXXXXXX \\);
  延迟(100);
  }  无效Send_SMS(){
  SIM900.println((char)的26);
  延迟(100);
  SIM900.println();
  延迟(5000); }  无效isr_timer(){
    如果(changed2){
    初始();
    SIM900.println(站85:Defaut ELECTRIQUE);
    延迟(100);
    Send_SMS();
    value2_old =值2;
    changed2 = FALSE;
  }  如果(changed3){
    初始();
    SIM900.println(站85:DefautGP1);
    延迟(100);
    Send_SMS();
    value3_old =值3;
    changed3 = FALSE;
   }   如果(changed4){
     初始();
     SIM900.println(站85:DD> 1000);
     延迟(100);
     Send_SMS();
     value4_old =值4;
     changed4 = FALSE;
    }
 }  无效设置(){
   pinMode(DI,输入);
   pinMode(DT,输入);
   pinMode(DGP1,输入);
   pinMode(DGP2,输入);   SIM900.begin(19200);
   Timer1.initialize(间隔);
   Timer1.attachInterrupt(isr_timer);
  } 空隙环(){
   值1 = digitalRead(DI);
   值2 = digitalRead(DT);
   值3 = digitalRead(DGP1);
   值4 = digitalRead(DGP2);   如果(值= value1_old和放大器;!&放大器;值1 == HIGH)changed1 = TRUE;
   如果(值2 = value2_old和放大器;!&放大器;值2 == HIGH)changed2 = TRUE;
   如果(VALUE3 = value3_old和放大器;!&安培; VALUE3 == HIGH)changed3 = TRUE;
   如果(值4 = value4_old和放大器;!&安培; VALUE4 == HIGH)changed4 = TRUE;   value1_old =值;
   value2_old =值2;
   value3_old =值3;
   value4_old =值4; }


解决方案

试着放慢对中断的时间间隔。这可能是由于在运行isr_timer()主回路的可以如果语句EM>被锁定。我有一个鬼鬼祟祟的怀疑你正在尝试做的太过分了!


  

要小心试图以过高的频率来执行太复杂的中断,或CPU可能永远不会进入主循环,你的程序将锁定。 参考


话说,并检查您的主循环实际上是运行为什么不能在主循环()的底部添加一个简单的调试闪烁板载领导。

  INT onBoardLED = 13;无效设置()
 {
    pinMode(onBoardLED,OUTPUT);    //和所有其余的
 }无效循环()
 {
    //做的东西    如果(onBoardLED == LOW)digitalWrite(ledPin,HIGH);
    其他digitalWrite(ledPin,LOW);
 }

至少这样,你就会知道,如果主循环()甚至实际执行。
它是你与后告诉其猜测的没有别的办法通过,但真正获得一个单一的短信明明运行一次...

如果一切看起来很好的尝试将周围的地方一些进一步的标志只是为了看什么得到执行,哪些不是。除此之外,建议我不能再发现什么,但有兴趣了解一下!祝您好运。

更新结果
刚挖出这个环节我的书签。您可能会发现它很有用。结果
- 尼克金门 - 中断

I faced a problem to send 1 SMS if an input is HIGH,and if it is LOW==> no SMS to send,if LOW to HIGH==> send 1 SMS. this code not working,just sent SMS when I turn the GPRS on,and after nothing is happened.

mclopez helped me,thank you,but not working :( , this is the new code that I wrote with the delay()s,but the same problem.

Thank you for helping in advance.

   #include <SoftwareSerial.h>
   #include "TimerOne.h"

   const int DI = 2;
   const int DT = 3;
   const int DGP1 = 4;
   const int DGP2 = 5;
   const long interval = 100000; // in microseconds

   int value1 = 0;
   int value2 = 0;
   int value3 = 0;
   int value4 = 0;

   int value1_old = 0;
   int value2_old = 0;
   int value3_old = 0;
   int value4_old = 0;

   boolean changed1 = false;
   boolean changed2 = false;
   boolean changed3 = false;
   boolean changed4 = false;

   SoftwareSerial SIM900 (7, 8);

   void SIM900power(){
     digitalWrite(9, HIGH);
     delay(1000);
     digitalWrite(9, LOW);
     delay(5000);
   }

  void initia(){
  SIM900.print("AT+CMGF=1\r");
  delay(100);
  SIM900.println("AT + CMGS = \"xxxxxxxxxx\"");
  delay(100);
  }

  void Send_SMS(){
  SIM900.println((char)26);
  delay(100);
  SIM900.println();
  delay(5000);

 }

  void isr_timer(){
    if (changed2) {
    initia();
    SIM900.println("Station 85: Defaut electrique");
    delay(100);
    Send_SMS();
    value2_old = value2;
    changed2 = false;
  }  

  if (changed3) {
    initia();
    SIM900.println("Station 85: DefautGP1");
    delay(100);
    Send_SMS();
    value3_old = value3;
    changed3 = false;
   }

   if (changed4) {
     initia();
     SIM900.println("Station 85:DD>1000");
     delay(100);
     Send_SMS();
     value4_old = value4;
     changed4 = false;
    }
 }

  void setup() {
   pinMode(DI, INPUT);
   pinMode(DT, INPUT);
   pinMode(DGP1, INPUT);
   pinMode(DGP2, INPUT);

   SIM900.begin(19200);
   Timer1.initialize(interval);
   Timer1.attachInterrupt(isr_timer);
  }

 void loop() {
   value1 = digitalRead (DI);
   value2 = digitalRead (DT);
   value3 = digitalRead (DGP1);
   value4 = digitalRead (DGP2);

   if (value1 != value1_old && value1 == HIGH) changed1 = true;
   if (value2 != value2_old && value2 == HIGH) changed2 = true;
   if (value3 != value3_old && value3 == HIGH) changed3 = true;
   if (value4 != value4_old && value4 == HIGH) changed4 = true;

   value1_old = value1;
   value2_old = value2;
   value3_old = value3;
   value4_old = value4;

 }

解决方案

Try slowing down the interval on the interrupt. It is possible that due to several if statements running under isr_timer()that the main loop may be locking up. I have a sneaking suspicion you are trying to do too much!

Be careful about trying to execute too complicated of an interrupt at too high of a frequency, or the CPU may never enter the main loop and your program will 'lock up'. Reference

Saying that and to check that your main loop is actually running why not add a simple debug at the bottom of the main loop() to flash the on board led..

int onBoardLED = 13;

void setup()
 {
    pinMode(onBoardLED, OUTPUT);

    // And all the rest
 } 

void loop()
 {
    // Doing stuff

    if (onBoardLED == LOW) digitalWrite(ledPin, HIGH);
    else digitalWrite(ledPin, LOW);
 }

At least then you will know if the main loop() is even actually executing. It obviously runs once as you are getting a single SMS through but really with no other way of telling its a guess after that...

If all looks good try adding some further flags around the place just to see whats getting executed and what is not. Other than that suggestion i cant spot anything further but interested to find out! Best of luck

Update
Just dug this link out of my bookmarks. You may find it useful.
- Nick Gammon - Interrupts

这篇关于发送短信1的时间与Arduino的GPRS SIM900如果iput是HIGH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆