10 years, 2 months ago.

send SMS with SIM 900

Hi to all, i use a Sim900 of SimCOM if i sand AT command or other commands all work well, but i have a problem for sand a SMS i write this code

#include "mbed.h"
#include <string>

Serial pc(SERIAL_TX, SERIAL_RX); // pc comunication
Serial SIM900(PA_9, PA_10);   //tx, rx SIM 900
string result;
char x;
void power()
{
  sim_power.write(1); // accension gsm
        wait(1);
        sim_power.write(0);
        wait(13);
        SIM900.printf("ATE0\r\n");  // DISABLE ECHO 
        wait(1);
}

void clearString()
 {
  result.clear();
  }
 
void callback_rx() {
	
    while (SIM900.readable()) {
      x = SIM900.getc();
      result += x;
	pc.putc(x); // print the answer from SIM900
			
       }
}

void sendSMS()
{

clearString();
  SIM900.printf("AT+CMGF=1\r"); //at command for send sms
	wait_ms(100);
clearString();
wait_ms(100);	
SIM900.printf("AT+CMGS=");
SIM900.putc('"');
SIM900.printf("+32292*******");	
SIM900.putc('"');
SIM900.printf("\r");
SIM900.printf("Example Message SMS");
SIM900.putc(0x1A);
wait_ms(20000);
}


int main() {	
power();
pc.printf("\r\n GSM 900 TEST\n"); 
SIM900.attach(&callback_rx);  
SIM900.baud(9600); // 
wait_ms(100);
			
    while(1) {

wait_ms(10);
sendSMS();	// SEND SMS		
 wait_ms(100);		
			
}

}

i see this when i send the sms but i have this strange message: AT+CMGF=1AT+CMGS="+32292*"" Example Message SMS

i see that the system send the message later two loop, i don't know where is the error can you help me?

best regards. A.

You have not declared variable x in callback_rx

posted by Rushabh Shah 01 Nov 2014

sorry, i declare char x;

posted by Antoniolinux B. 18 Nov 2014

4 Answers

7 years, 7 months ago.

Hello I try this project just difference I use sim908c and I do not understand how I do hardware connection if you know please help me

10 years ago.

You should use more time between AT commands. eg.

GSM

#include "mbed.h"
#include <string>

Serial pc(SERIAL_TX, SERIAL_RX); // pc comunication
Serial SIM900(PA_11, PA_12);   //tx, rx SIM 900
string result;
char x;


void clearString()
 {
  result.clear();
  }

void callback_rx() {

    while (SIM900.readable()) {
      x = SIM900.getc();
      result += x;
    pc.putc(x); // print the answer from SIM900

       }
}

void sendSMS()
{

clearString();
  SIM900.printf("AT+CMGF=1\r"); //at command for send sms
    wait_ms(1000);
clearString();
wait_ms(1000);
SIM900.printf("AT+CMGS=");
SIM900.putc('"');
SIM900.printf("+48*********");
SIM900.putc('"');
SIM900.printf("\r");
wait_ms(1000);
SIM900.printf("test1");
wait_ms(1000);
SIM900.putc(0x1A);
wait_ms(5000);
}


int main() {

pc.printf("\r\n GSM 900 TEST\n");
SIM900.attach(&callback_rx);
SIM900.baud(9600); //
wait_ms(100);

    while(1) {

wait_ms(10);
sendSMS();  // SEND SMS
 wait_ms(100);

}

}


8 years, 6 months ago.

what is your librarys ?

I do not use the GSM library, You should turn on GSM and then send sms. It is important to correct the delay between commands

posted by Paweł Mama 19 Jun 2016
8 years, 6 months ago.

i am also getting same issue, not able o send sms please help

Thanks Gautam

At first, check if your sim card is not "3G only". After power up please type "AT+CREG?" to check, if you are registered to the network.

posted by Michal Wisniewski 19 Jun 2016

Its working now, problem with hardware connection.

posted by gautam tripathi 22 Jun 2016

What is your hardware connection?

posted by rutuj t 04 Feb 2017