Pages: [1]   Go Down
Author Topic: Sending message using GSM/GPRS shield without delay  (Read 309 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm new in arduino world.. I have a project using arduino uno, SD card shield, Serial LCD display, and GSM/GPRS shield..

what I'm trying to do is to read data from a sensor and display it to Serial LCD display, save it into SD card and every 10mins it will send the current data using GSM/GPRS shield...

I'm done with reading data from sensor, Display in Serial LCD display, saving into SD card and Sending message every 10mins..

The problem is every time the the timer is equal to 10mins it send message but the timer and reading data from the sensor stops until sending is done and then the timer resumes and reading data from the sensor....

What should I do about this? I want to send message without stopping the timer and reading data from the sensor..
Logged

Offline Offline
Full Member
***
Karma: 3
Posts: 114
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The canonical answer to this is to see the Blink Without Delay example, and to see:

http://forum.arduino.cc/index.php?topic=223286.0

Also, I am going to guess that the problem is on line 42 of the code that you didn't show us.  If you change your mind, please use the # button to properly display the code.

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you for your reply sir..


so here is my code sir..

Code:
#include "SIM900.h"
#include <SoftwareSerial.h>
#include "sms.h"
#include <SD.h>
#define  MODEPIN  2


SMSGSM sms;
File myFile;
int a = 4;

const int switchPin = 7;     //     // Reed switch to digital pin 7
int counter;
int infinite; // (/)
int tipped;
int nt;
float perTipped; // (/)
int numdata;
//boolean started=false;
char smsbuffer[160];
char n[20];
//---------------------
char val1[25];
char asa[10];

//---------------------
void setup(){
Serial.begin(9600);
delay(1500);          // Allow time for Serial LCD to set up
digitalWrite(MODEPIN, HIGH);
pinMode(switchPin, INPUT);        // switchPin is an input
digitalWrite(switchPin, HIGH);    // Activate internal pullup resistor
Serial.write(0x02);
Serial.print("F");
Serial.write(0x03);

Serial.write(0x02); //STX code
Serial.print("c"); //c – Clear LCD function
Serial.write(0x03); //ETX code

while (!Serial) {
    ; // wait for serial port to connect.
  }
 
  Serial.write(0x02);
  Serial.print("1");
  Serial.print("Starting SD card");
  Serial.write(0x03);
 
   pinMode(10, OUTPUT);
   
  if (!SD.begin(4)) {
  Serial.write(0x02);
  Serial.print("2");
  Serial.print("Starting failed");
  Serial.write(0x03);
  return;
  }
  Serial.write(0x02);
  Serial.print("2");
  Serial.print("Starting done.");
  Serial.write(0x03);

//---------------------------------------------------
delay(3000);
Serial.write(0x02); //STX code
Serial.print("c"); //c – Clear LCD function
Serial.write(0x03); //ETX code

Serial.write(0x02);
Serial.print("1");
Serial.print("GSM Shield testing.");
Serial.write(0x03);

  if (gsm.begin(2400)){
  Serial.write(0x02);
  Serial.print("2");
  Serial.print("status=READY");
  Serial.write(0x03);
  //started=true; 
  }
  else
  Serial.write(0x02);
  Serial.print("2");
    Serial.print("status=IDLE");
  Serial.write(0x03);
  //myFile = SD.open("ronin.txt", FILE_WRITE);
delay(5000);
Serial.write(0x02); //STX code
Serial.print("c"); //c – Clear LCD function
Serial.write(0x03); //ETX code

};

void loop(){
  tipped = digitalRead(switchPin); 
  delay(70);
 
  if(tipped == 0){
  mainfunction();
  }

  if(nt==11){
  send_sms();
  }
 
};



//-----------------------------------------
void send_sms(){
itoa(nt,val1,10);
dtostrf(perTipped, 5, 2, asa);
sms.SendSMS("09071026556", asa);

};
//------------------------------------------
void mainfunction(){

  perTipped += 0.50;
  nt += 1;
  myFile = SD.open("robin.txt", FILE_WRITE);

  myFile.print(perTipped);
  myFile.print("    ");
  myFile.println(nt);
  myFile.close();
 
  Serial.write(0x02);      //STX
  Serial.print(">");      // Send position info
  Serial.print(a);
  Serial.write(0x03);    //ETX
  Serial.write(0x02); //STX
  Serial.print("3");
  Serial.print(perTipped);
  Serial.write(0x03); //ETX
//---------------------------------------
  Serial.write(0x02);      //STX
  Serial.print(">");      // Send position info
  Serial.print(a);
  Serial.write(0x03);    //ETX
  Serial.write(0x02); //STX
  Serial.print("4");
  Serial.print(nt);
  Serial.write(0x03); //ETX
  //-------------------------------
};

Logged

Johannesburg, South Africa
Offline Offline
Full Member
***
Karma: 0
Posts: 180
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The GSM libraries have a lot of delay statements. It might be worthwhile to edit the libraries and change the delays to a better timer. Look at the blink without delay example
Logged

Pages: [1]   Go Up
Jump to: