Hi,
I am trying to receive sms and then stock them in a sd card. The initialization of the card is working but then my code stop just before the "Waiting for messages" serial!
I would be so grateful if someone already tried to do this or have some tips for me.
#include <SoftwareSerial.h> // Needed by the EMIC2 library
#include <SD.h> // Needed by the EMIC2 library, though not utilized in this example
#include "EMIC2.h"
// include the GSM library
#include <GSM.h>
// PIN Number for the SIM
#define PINNUMBER ""
// for the available pins on your board
#define RX_PIN 9 // Connect SOUT pin of the Emic 2 module to the RX pin
#define TX_PIN 6 // Connect SIN pin of the Emic 2 module to the TX pin
EMIC2 emic; // Creates an instance of the EMIC2 library
File myFile;
// initialize the library instances
GSM gsmAccess;
GSM_SMS sms;
// Array to hold the number a SMS is retreived from
char senderNumber[20];
void setup()
{
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
//Initializing card
Serial.println("Initializing SD card...");
pinMode(10, OUTPUT);
if (!SD.begin(10)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
// myFile = SD.open("test.txt", FILE_WRITE);
//SMS
Serial.println("SMS Messages Receiver");
// connection state
boolean notConnected = true;
// Start GSM connection
while(notConnected)
{
if(gsmAccess.begin(PINNUMBER)==GSM_READY)
notConnected = false;
else
{
Serial.println("Not connected");
delay(1000);
}
}
Serial.println("GSM initialized");
Serial.println("Waiting for messages");
// Initializes the EMIC2 instance
// The library sets up a SoftwareSerial port
// for the communication with the Emic 2 module
emic.begin(RX_PIN, TX_PIN);
emic.setVoice(8); // Sets the voice (9 choices: 0 - 8)*/
}
void loop()
{
char c;
// If there are any SMSs available()
if (sms.available()){
Serial.println("Message received from:");
// Get remote number
sms.remoteNumber(senderNumber, 20);
Serial.println(senderNumber);
// An example of message disposal
// Any messages starting with # should be discarded
if(sms.peek()=='#')
{
Serial.println("Discarded SMS");
sms.flush();
}
String textToSay = "";
// Read message bytes and print them
while(c=sms.read()){
Serial.print(c);
textToSay = textToSay + String(c);
}
// emic.setRate(100);
// emic.speak(textToSay);
// emic.resetRate();
Serial.println("\nEND OF MESSAGE");
// Delete message from modem memory
sms.flush();
Serial.println("MESSAGE DELETED");
myFile = SD.open("test.txt", FILE_WRITE);
// if the file opened okay, write to it:
if (myFile) {
Serial.print("Writing to test.txt...");
myFile.print(textToSay);
myFile.println("/");
// close the file:
myFile.close();
Serial.println("done.");
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
delay(1000);
}
}