[RESOLVED]GSM Module SIM900 + W5100 Ethernet shield SoftwareSerial problem

Hello guys,

I try send a SMS through GSM module... http://www.elecfreaks.com/wiki/index.php?title=EFCom_GPRS/GSM_Shield

Everything it's look like fine and my logs shows that SMS was send but I don't receive the SMS in my cellphone.

if I remove ethernet connection I receive the SMS...so GSM and ethernet shield don't work together...

anyone can help me?

thanks and sorry by my poor english.

Probably power. The GSM shield has this note.

The transmitting burst will cause voltage drop and the power supply must be able to provide sufficient current up to 2A. The USB port can not supply such a large current.

The w5100 uses quite a bit of power also (> 130ma). Used by themselves, there may be just enough power, but the combination may be too much for the power supply.

I already supply my ARDUINO with a 9v DC 1000 mA(it's come with GSM module)

do you think that I have supply my GSM module too?

thx!

do you think that I have supply my GSM module too?

Yes.

Posting your code might be a good idea, too. That would let us see if there is a pin conflict. For instance, if you are using pins 10 and 11 for a SoftwareSerial interface, which is not uncommon, that WILL interfere with the ethernet shield, and vice versa. Though it looks like that shield offers a choice of the hardware serial port (pins 0 and 1) or pins 2 and 3.

my code

//  Erick Eden Fróes
//  www.wenomine.com
#include <SoftwareSerial.h>
#include <SPI.h>
#include <Ethernet.h>

//50 rx e 51 tx 
SoftwareSerial mySerial = SoftwareSerial(51,50);
char flag=0;  
//Configurações do Ethernet Shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,0,177);
int led = 23;
const int sensor_pir = 22;
boolean alarme = false;
int meuNumero = 998016219;

 
// String que representa o estado dos dispositivos
char Luz[7] = "0000L#";

EthernetServer server(80); // Cria o servidor na porta 8081
 
// String onde é guardada as msgs recebidas
char msg[7] = "0000L#";
 
void setup() {
  pinMode(23,OUTPUT);
  //pinMode(9,OUTPUT);
  pinMode(sensor_pir, INPUT);
  
  mySerial.begin(19200);
  Serial.begin(19200);
  
  
  
  Ethernet.begin(mac, ip);
  server.begin();
  //Serial.print("server is at ");
  //Serial.println(Ethernet.localIP());
  mandaSMS();
   
}
 
void loop() {
  EthernetClient client = server.available();
  // SE receber um caracter...
  int estado_sensor = digitalRead(sensor_pir);
  
  if(alarme == true){
    
    if (estado_sensor == HIGH) {
       Serial.println("Intruso");
       client.write("Intruso");
       //digitalWrite(9,HIGH);
       mandaSMS();
       //ligar();
       //alarme = false;
       }
    
  }
 
  if (client) {
    // guarda o caracter na string 'msg'
    
    msg[1]=msg[2]; msg[2]=msg[3]; msg[3]=msg[4]; msg[4]=msg[5]; msg[5]=msg[6];
    msg[6] = client.read();
    
    //if HTTP request has ended
    
   if (msg[6]=='#') {
     
      switch(msg[5]) {
        case 'R':
          // Se receber o comando 'R#' envia de volta o status dos
          //   dispositivos. (Que é a string 'Luz')
          client.write(Luz);
        break;
        case 'P':
          // Caso P#, aciona o pino do portão pequeno por 1s.
          digitalWrite(A4,HIGH);
          delay(1000);
          digitalWrite(A4,LOW);
        break;
        case 'G':
          // Caso G#, aciona o pino do portão pequeno por 1s.
          digitalWrite(A5,HIGH);
          delay(1000);
          digitalWrite(A5,LOW);        
        break;
        case 'L':
          // Caso L#, ele copia os 4 bytes anteriores p/ a
          //   string 'Luz' e cada byte representa um
          // dispositivo, onde '1'=ON e '0'=OFF
          Luz[0]=msg[1];
          Luz[1]=msg[2];
          Luz[2]=msg[3];
          Luz[3]=msg[4];
          Serial.print(Luz[0]);
          if (Luz[0]=='1') {
          digitalWrite(23,HIGH); 
          alarme= true;
          }else{
           digitalWrite(23,LOW);
           //digitalWrite(9,LOW);
           alarme= false;
          }
          if (Luz[1]=='1') digitalWrite(1,HIGH); else digitalWrite(1,LOW);
          if (Luz[2]=='1') digitalWrite(2,HIGH); else digitalWrite(2,LOW);
          if (Luz[3]=='1') digitalWrite(3,HIGH); else digitalWrite(3,LOW);
        break;
       
      }
    }
  }
    
}

void mandaSMS(){
     if(flag==0)
    {
      mySerial.print("AT+CMGF=1\r"); //mandando SMS em modo texto
      delay(1000);
      mySerial.print("AT+CMGS=\"+99801****\"\r"); // numero que vamos mandar o SMS
      delay(1000);
      Serial.println("SMS Armado");
      flag=1;
    }
   
    if(flag==1)
      {
        mySerial.print("Perimetro invadido!Alarme disparado!\r"); // corpo da msg
        delay(1000);
        mySerial.write(0x1A); //equivalente a mandar Ctrl+Z(finaliza corpo do SMS)
        delay(1000);
        Serial.println("Pronto pra enviar");
        flag=2;
      }
      if(flag==2)
        {
          Serial.println("SMS Enviado com sucesso!");
          delay(5000);
          flag=3;
        }
  
}
/*
void ligar(){
mySerial.println("\r");
delay(1000);
mySerial.println("AT+CMGF=1\r");
delay(1000);
if (mySerial.available())
    {
    mySerial.println("ATD 99801****;");      // numero a ser discado
    delay(10000);                           //completar licação
    delay(6000);                           //receber licação, esperar.
    mySerial.println("ATH0");              //finaliza ligação
    }

}*/

That is a Mega, so you can't use pins 50 and 51 for SoftwareSerial. Why don't you use one of the other hardware serial ports?

edit: Pins 50 to 53 are the SPI bus pins. The ethernet shield uses those through the ICSP connector.

I'm try using hardware serial ports, but it's fail... :cold_sweat:

I do it

//  Erick Eden Fróes
//  www.wenomine.com
//#include <SoftwareSerial.h>
#include <SPI.h>
#include <Ethernet.h>

//50 rx e 51 tx 
//SoftwareSerial mySerial = SoftwareSerial(51,50);
char flag=0;  
//Configurações do Ethernet Shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,0,177);
int led = 23;
const int sensor_pir = 22;
boolean alarme = false;
int meuNumero = 998016219;

 
// String que representa o estado dos dispositivos
char Luz[7] = "0000L#";

EthernetServer server(80); // Cria o servidor na porta 8081
 
// String onde é guardada as msgs recebidas
char msg[7] = "0000L#";
 
void setup() {
  pinMode(23,OUTPUT);
  //pinMode(9,OUTPUT);
  pinMode(sensor_pir, INPUT);
  
  Serial2.begin(19200);
  Serial.begin(19200);
  
  
  
  Ethernet.begin(mac, ip);
  server.begin();
  //Serial.print("server is at ");
  //Serial.println(Ethernet.localIP());
  mandaSMS();
   
}
 
void loop() {
  EthernetClient client = server.available();
  // SE receber um caracter...
  int estado_sensor = digitalRead(sensor_pir);
  
  if(alarme == true){
    
    if (estado_sensor == HIGH) {
       Serial.println("Intruso");
       client.write("Intruso");
       //digitalWrite(9,HIGH);
       mandaSMS();
       //ligar();
       //alarme = false;
       }
    
  }
 
  if (client) {
    // guarda o caracter na string 'msg'
    
    msg[1]=msg[2]; msg[2]=msg[3]; msg[3]=msg[4]; msg[4]=msg[5]; msg[5]=msg[6];
    msg[6] = client.read();
    
    //if HTTP request has ended
    
   if (msg[6]=='#') {
     
      switch(msg[5]) {
        case 'R':
          // Se receber o comando 'R#' envia de volta o status dos
          //   dispositivos. (Que é a string 'Luz')
          client.write(Luz);
        break;
        case 'P':
          // Caso P#, aciona o pino do portão pequeno por 1s.
          digitalWrite(A4,HIGH);
          delay(1000);
          digitalWrite(A4,LOW);
        break;
        case 'G':
          // Caso G#, aciona o pino do portão pequeno por 1s.
          digitalWrite(A5,HIGH);
          delay(1000);
          digitalWrite(A5,LOW);        
        break;
        case 'L':
          // Caso L#, ele copia os 4 bytes anteriores p/ a
          //   string 'Luz' e cada byte representa um
          // dispositivo, onde '1'=ON e '0'=OFF
          Luz[0]=msg[1];
          Luz[1]=msg[2];
          Luz[2]=msg[3];
          Luz[3]=msg[4];
          Serial.print(Luz[0]);
          if (Luz[0]=='1') {
          digitalWrite(23,HIGH); 
          alarme= true;
          }else{
           digitalWrite(23,LOW);
           //digitalWrite(9,LOW);
           alarme= false;
          }
          if (Luz[1]=='1') digitalWrite(1,HIGH); else digitalWrite(1,LOW);
          if (Luz[2]=='1') digitalWrite(2,HIGH); else digitalWrite(2,LOW);
          if (Luz[3]=='1') digitalWrite(3,HIGH); else digitalWrite(3,LOW);
        break;
       
      }
    }
  }
    
}

void mandaSMS(){
     if(flag==0)
    {
      Serial2.print("AT+CMGF=1\r"); //mandando SMS em modo texto
      delay(1000);
      Serial2.print("AT+CMGS=\"+99801****\"\r"); // numero que vamos mandar o SMS
      delay(1000);
      Serial.println("SMS Armado");
      flag=1;
    }
   
    if(flag==1)
      {
        Serial2.print("Perimetro invadido!Alarme disparado!\r"); // corpo da msg
        delay(1000);
        Serial2.write(0x1A); //equivalente a mandar Ctrl+Z(finaliza corpo do SMS)
        delay(1000);
        Serial.println("Pronto pra enviar");
        flag=2;
      }
      if(flag==2)
        {
          Serial.println("SMS Enviado com sucesso!");
          delay(5000);
          flag=3;
        }
  
}
/*
void ligar(){
mySerial.println("\r");
delay(1000);
mySerial.println("AT+CMGF=1\r");
delay(1000);
if (mySerial.available())
    {
    mySerial.println("ATD 99801****;");      // numero a ser discado
    delay(10000);                           //completar licação
    delay(6000);                           //receber licação, esperar.
    mySerial.println("ATH0");              //finaliza ligação
    }

}*/

and GSM pin on RX2 and TX2 on port 16 and 17

but i'ts not response!

SuferTim Thanks a lot man, you kill the MONSTERR :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley:

I change the ports 50 and 51 to 40 and 41 and it's works

Thanks man!

I am surprised it works on pins 40 and 41. The SoftwareSerial rx pin needs to be a change interrupt capable pin, and neither of those are. Check here under "Limitations".

edit: If you are never receiving anything from the GSM module, it will work ok. It appears you never receive anything from it with your code.

Not In the absolute, but 9 time out of 10 a picture tell more then the code when that kind of problem happen.