Hello,
I am trying to interface MKR1000 with SIM800L GSM module using the below code..
I have modified the software serial to serial1 and made connections accordingly.
#include <String.h>
int i=0;
void setup()
{
Serial1.begin(9600);
Serial.begin(9600);
while(!Serial)
{
;
}
delay(500);
}
void loop()
{
Serial.print("Loop count: ");
Serial.println(i);
i++;
SendTextMessage();
if (Serial1.available())
{
while(Serial1.available())
{
Serial.write(Serial1.read());
}
}
delay(10000);
}
void SendTextMessage()
{
Serial.println("Sending Text...");
Serial1.print("AT");
delay(1000);
Serial1.print("AT+CMGF=1"); // Set the shield to SMS mode
delay(1000);
Serial1.print("AT+CMGS=\"+91xxxxxxxxxx\"\r");
Serial1.print("Test message 1 ");
Serial1.print("\r"); //the content of the message
Serial1.print((char)26);//the ASCII code of the ctrl+z is 26 (required according to the datasheet)
delay(100);
Serial1.println();
Serial.println("Text Sent.");
delay(500);
}
But its sending error..
any help..
I have tried another code...
unsigned char buffer[64]; //port
int count=0;
int i = 0; //if i = 0, send SMS.
void setup() {
Serial1.begin(9600); // the GPRS baud rate
Serial.begin(9600);
while(!Serial)
{
;// the Serial port of Arduino baud rate.
}
Serial.println("I'm ready");
Serial.println("Hello?");
delay(1000);
}
void loop() {
if (Serial1.available()) {
// if date is coming from softwareserial port ==> data is coming from GPRS shield
while(Serial1.available()) {
// reading data into char array
buffer[count++]=Serial1.read();
// writing data into array
if(count == 64)
break;
}
Serial.write(buffer,count);
// if no data transmission ends, write buffer to hardware serial port
clearBufferArray();
// call clearBufferArray function to clear the stored data from the array
count = 0; // set counter of while loop to zero
}
if (Serial.available())
// if data is available on hardwareserial port ==> data is coming from PC or notebook
Serial1.write(Serial.read()); // write it to the GPRS shield
if(i == 0) {
Serial1.write("AT+CMGF=1\r"); //sending SMS in text mode
// delay(1000);
Serial.println("AT+CMGF=1\r");
Serial1.write("AT+CMGS=\"+91xxxxxxxxxx\"\r"); // phone number
//delay(1000);
Serial.println("AT+CMGS=\"+91xxxxxxxxxx\"\r");
Serial1.write("Hello how are you?\r"); // message
Serial.println("Hello how are you?\r");
// delay(1000);
Serial1.write(0x1A);
//send a Ctrl+Z (end of the message)
delay(1000);
Serial.println("SMS sent successfully");
i++;
}
}
void clearBufferArray(){
// function to clear buffer array
for (int j=0; j<count;j++){
buffer[j]='\0';
// clear all index of array with command NULL
}
}
Following is the output..
I'm ready
Hello?
AT+CMGF=1
AT+CMGS="+9100000000"
Hello how are you?
SMS sent successfully
AT+CMGF=1
AT+CMGS="+9100000000"
Hello how are you?
ERROR