Modulo de GSM para Ardduino o Netduino

El  Escudo de GSM para Arduino le permite hacer llamadas de teléfono celular y enviar mensajes de texto.El cerebro  este escudo es el SM5100B que es un módulo celular robusto capaz de realizar muchas de las tareas de los teléfonos móviles más habituales. Este escudo requiere el uso de una tarjeta SIM para conectarse a una red celular. A continuación mostraremos  como  inicializar el escudo, y enviar y recibir mensajes de texto y llamadas telefónicas. Para obtener más información acerca de la funcionalidad del módulo, asegúrese de revisar las hojas de datos en la página del producto de Sparkfun .


Usted necesitará:

(X1) Celular escudo
(X1) apilables encabezados Arduino
(X1) antena de banda cuádruple
(X1) Arduino Uno (o similar)





En primer lugar inserte los pines  del escudo en los orificios de la placa  y sueldelos  como en la imagen 


Inserte los pasadores de cabecera en los zócalos de la placa Arduino.

La conexión del cable de la antena al módulo SM5100B no suele ser muy buena. Resolder cada una de las conexiones del cable al módulo para garantizar la conectividad.

Enrosque la antena al cable de la antena.


Inserte ahora  una  tarjeta SIM  en activo  firmemente en la ranura de la tarjeta SIM


Ejecute este código en su Arduino


*/SparkFun Cellular Shield – Pass-Through Sample Sketch
SparkFun Electronics
Written by Ryan Owens
3/8/10

Description: This sketch is written to interface an Arduino Duemillanove to a  Cellular Shield from SparkFun Electronics.
The cellular shield can be purchased here: http://www.sparkfun.com/commerce/product_info.php?products_id=9607
In this sketch serial commands are passed from a terminal program to the SM5100B cellular module; and responses from the cellular
module are posted in the terminal. More information is found in the sketch comments.

An activated SIM card must be inserted into the SIM card holder on the board in order to use the device!

This sketch utilizes the NewSoftSerial library written by Mikal Hart of Arduiniana. The library can be downloaded at this URL:
http://arduiniana.org/libraries/NewSoftSerial/

This code is provided under the Creative Commons Attribution License. More information can be found here:
http://creativecommons.org/licenses/by/3.0/

(Use our code freely! Please just remember to give us credit where it’s due. Thanks!)
*/

#include  //Include the NewSoftSerial library to send serial commands to the cellular module.
#include         //Used for string manipulations

char incoming_char=0;      //Will hold the incoming character from the Serial Port.

SoftwareSerial cell(2,3);  //Create a ‘fake’ serial port. Pin 2 is the Rx pin, pin 3 is the Tx pin.

void setup()
{
  //Initialize serial ports for communication.
  Serial.begin(9600);
  cell.begin(9600);
  
  //Let’s get started!
  Serial.println(«Starting SM5100B Communication…»);
}

void loop() {
  //If a character comes in from the cellular module…
  if(cell.available() >0)
  {
    incoming_char=cell.read();    //Get the character from the cellular serial port.
    Serial.print(incoming_char);  //Print the incoming character to the terminal.
  }
  //If a character is coming from the terminal to the Arduino…
if( Serial.available( ) > 0)
{
incoming_char = Serial.read( ); // Get the character coming from the terminal
if(incoming_char == ‘~’) // If it’s a tilde…

incoming_char = 0x0D;      // …convert to a carriage return  

else if( incoming_char == ‘^’) // If it’s an up caret…

incoming_char =  0x1A;    // …convert to ctrl-Z  

cell.print( incoming_char ); // Send the character to the cellular module.
Serial.print( incoming_char ); // Echo it back to the terminal
}

}

/* SM5100B Quck Reference for AT Command Set
*Unless otherwise noted AT commands are ended by pressing the ‘enter’ key.

1.) Make sure the proper GSM band has been selected for your country. For the US the band must be set to 7.
To set the band, use this command: AT+SBAND=7

2.) After powering on the Arduino with the shield installed, verify that the module reads and recognizes the SIM card.
With a terimal window open and set to Arduino port and 9600 buad, power on the Arduino. The startup sequence should look something
like this:

Starting SM5100B Communication…
    
+SIND: 1
+SIND: 10,»SM»,1,»FD»,1,»LD»,1,»MC»,1,»RC»,1,»ME»,1

Communication with the module starts after the first line is displayed. The second line of communication, +SIND: 10, tells us if the module
can see a SIM card. If the SIM card is detected every other field is a 1; if the SIM card is not detected every other field is a 0.

3.) Wait for a network connection before you start sending commands. After the +SIND: 10 response the module will automatically start trying
to connect to a network. Wait until you receive the following repsones:

+SIND: 11
+SIND: 3
+SIND: 4

The +SIND response from the cellular module tells the the modules status. Here’s a quick run-down of the response meanings:
0 SIM card removed
1 SIM card inserted
2 Ring melody
3 AT module is partially ready
4 AT module is totally ready
5 ID of released calls
6 Released call whose ID=
7 The network service is available for an emergency call
8 The network is lost
9 Audio ON
10 Show the status of each phonebook after init phrase
11 Registered to network

After registering on the network you can begin interaction. Here are a few simple and useful commands to get started:

To make a call:
AT command – ATDxxxyyyzzzz
Phone number with the format: (xxx)yyy-zzz

try —- cell.print(«ATDxxxyyyzzzz»);

If you make a phone call make sure to reference the devices datasheet to hook up a microphone and speaker to the shield.

To send a txt message:
AT command – AT+CMGF=1
This command sets the text message mode to ‘text.’
AT command = AT+CMGS=»xxxyyyzzzz»(carriage return)’Text to send'(CTRL+Z)
This command is slightly confusing to describe. The phone number, in the format (xxx)yyy-zzzz goes inside double quotations. Press ‘enter’ after closing the quotations.
Next enter the text to be send. End the AT command by sending CTRL+Z. This character can’t be sent from Arduino’s terminal. Use an alternate terminal program like Hyperterminal,
Tera Term, Bray Terminal or X-CTU.

The SM5100B module can do much more than this! Check out the datasheets on the product page to learn more about the module.*/





Abrir el puerto serie en el terminal. En un Mac, esto se logra escribiendo:
pantalla / dev/tty.usbmodemfa131 9600

(Reemplace tty.usbmodemfa131 con dirección serie de la placa Arduino)

Esperar a ver la siguiente secuencia devuelta:

A partir SM5100B Comunicación …

+ SIND: 3

+ SIND: 4

+ SIND: 11

. (Si esta secuencia no se devuelve comprobar los códigos de error que aparecen al final del código de seguridad, y depurar adecuadamente Puede que tenga que configurar el módulo para el uso en América del Norte – ver abajo – antes de que se registre en la red (es decir, + SIND 11))

Envíe los siguientes comandos al puerto serie:

Enviar esto para uso en América del Norte:
AT + SBAND = 7

Ajuste la hora actual – aa / mm / dd:
AT + CCLK = «13/05/15, 11:02:00»

Enviar llamada de prueba:
ATD4155551212


Envio de Mensajes de Texto

Descarga e instala SerialGSM a tu biblioteca Arduino.

Para enviar un mensaje de texto utilice el siguiente código de ejemplo: 

**********************************************************************************
// SEND A TEXT MESSAGE
//
// CODE TAKEN FROM:
// http://tronixstuff.wordpress.com/2011/01/19/tutorial-arduino-and-gsm-cellular-part-one/
//
// Download SerialGSM:
// https://github.com/meirm/SerialGSM
//
//**********************************************************************************

#include
#include

//Set up a virtual serial port
SerialGSM cell(2,3);

void setup()
 delay(30000); // wait for GSM module
 cell.begin(9600);
}

void sendSMS(){
  cell.Verbose(true); // used for debugging
  cell.Boot(); 
  cell.FwdSMS2Serial();
  cell.Rcpt(«+xxxxxxxxxx»); // replace xxxxxxxxxx with the recipient’s cellular number
  cell.Message(«Contents of your text message»);
  cell.SendSMS();
}

void loop(){
  
  //Sends a text message
  sendSMS();
  
  //Stops the code
  // remove this loop at your peril
  do 
  { 
    delay(1); 
  }
  while (1>0);
}

Si desea ejecutar el código de ejemplo para recibir un texto, conectar un LED al pin 8 y lo puso en serie con una resistencia de 220 ohmios a tierra. 

Para recibir un mensaje de texto utilice el siguiente código de ejemplo: 



//**********************************************************************************
// RECEIVE A TEXT
//
// CODE BASED UPON:
// http://tronixstuff.wordpress.com/2011/01/31/tutorial-arduino-and-gsm-cellular-%E2%80%93-part-two/
//
//**********************************************************************************
 
 #include
 
 //Will hold the incoming character from the Serial Port.
 char inchar; 
 
 //Create a ‘fake’ serial port. Pin 2 is the Rx pin, pin 3 is the Tx pin.
 SoftwareSerial cell(2,3); 

 //the pin the LED is attached to
 int led1 = 8;

 void setup(){
   // prepare the digital output pin
   pinMode(led1, OUTPUT);
   digitalWrite(led1, LOW);
   
   //Initialize GSM module serial port for communication.
   cell.begin(9600);
   
   // give time for GSM module to register on network etc.
   delay(30000); 
   
   // set SMS mode to text
   cell.println(«AT+CMGF=1»); 
   delay(200);
   
   // set module to send SMS data to serial out upon receipt 
   cell.println(«AT+CNMI=3,3,0,0»); 
   delay(200);
 }

 void loop(){
   //If a character comes in from the cellular module…
   if(cell.available() >0){
     inchar=cell.read();
     
     //Look for # from the virtual serieal port
     if (inchar==’#’){
       delay(10);
       inchar=cell.read(); 
       
       //Look to see if the characheter is an «a»
       if (inchar==’a’){
         delay(10);
         inchar=cell.read();
         
         //If the next charachter is 0 turn the LED off
         if (inchar==’0′){
           digitalWrite(led1, LOW);
         } 
         else if (inchar==’1′){
         //If the next charachter is 0 turn the LED on
           digitalWrite(led1, HIGH);
         }
         delay(10);
         
         //delete all SMS from the SIM
         cell.println(«AT+CMGD=1,4»); 
       }
     }
   }
 }
 






Texto  de uno de los siguientes comandos hacia el modulo GSMr: 

/ / Enciende el LED 
# A1 

/ / Enciende el LED 
# A0


Llamadas de Voz

Conecte un micrófono y un altavoz a la pantalla con el cable de audio conectado a tierra. El cable de señal del centro debe ir a los terminales positivo de audio y la pantalla debe ir a los respectivos terminales negativos sobre el escudo. Estos cables deben ser conectados de manera similar en el micrófono y el lado del altavoz.

Para iniciar una llamada de voz subir el siguiente código: 

*********************************************************************************
// MAKE A CALL
//
// BUFFERING CODE BASED UPON:
// http://jayeshprojects.blogspot.com/2010/04/real-time-mobile-gps-tracker-with.html
//
//**********************************************************************************

#include
#define BUFFSIZ 90

//Set up buffer array
char at_buffer[BUFFSIZ];
char buffidx;

//Network state variables
int network_registered;
int network_AT_ready;

//Code state variables
int firstTimeInLoop = 1;
int firstTimeInOtherLoop = 1;
int x;
 
//Will hold the incoming character from the Serial Port.
char incoming_char=0;

//Create a ‘fake’ serial port. Pin 2 is the Rx pin, pin 3 is the Tx pin.
SoftwareSerial cell(2,3);  


void setup() {
  
  //Initialize Arduino serial port for debugging.
  Serial.begin(9600);
  
  //Initialize virtual serial port to talk to Phone.
  cell.begin(9600);

  //Hello World.
  Serial.println(«Starting SM5100B Communication…»);
  delay(1000);

  //Set initial network state
  network_registered = 0;
  network_AT_ready = 0;

}


//Read AT strings from the cellular shield
void readATString(void) {

  char c;
  buffidx= 0; // start at begninning
  for (x = 0; x < 10000; x ++) {    
    if(cell.available() > 0) {
      c=cell.read();
      if (c == -1) {
        at_buffer[buffidx] = ‘\0’;
        return;
      }
      if (c == ‘\n’) {
        continue;
      }
      if ((buffidx == BUFFSIZ – 1) || (c == ‘\r’)){
        at_buffer[buffidx] = ‘\0’;
        return;
      }
      at_buffer[buffidx++]= c;
    }
  }
}




//Process the AT strings
void ProcessATString() {

  if( strstr(at_buffer, «+SIND: 8») != 0 ) {
    network_registered = 0;
    Serial.println(«network Network Not Available»);
  }

  if( strstr(at_buffer, «+SIND: 11») != 0 ) {
    network_registered=1;
    Serial.println(«network Registered»);
  }
  
  if( strstr(at_buffer, «+SIND: 4») != 0 ) {
    network_AT_ready=1;
    Serial.println(«network AT Ready»);
  }
}

 
void loop() {

/* If called for the first time, loop until network and AT is ready */

if(firstTimeInLoop == 1) {

  firstTimeInLoop = 0;
  while (network_registered == 0 || network_AT_ready == 0) {
    readATString();
    ProcessATString();
    }
  }

//LET’S MAKE A PHONE CALL!
if(firstTimeInOtherLoop == 1){
  
     //Change the 10 digit phone number to whatever you wish
     cell.println(«ATD4155551212»);
     firstTimeInOtherLoop = 0;
   }
}
Para recibir una llamada de voz subir el siguiente código: 


**********************************************************************************
// ANSWER A CALL
//
// BUFFERING CODE BASED UPON:
// http://jayeshprojects.blogspot.com/2010/04/real-time-mobile-gps-tracker-with.html
//
//**********************************************************************************
#include
#define BUFFSIZ 90
//Set up buffer array
char at_buffer[BUFFSIZ];
char buffidx;
//Network state variables
int network_registered;
int network_AT_ready;
//Code state variables
int firstTimeInLoop = 1;
int firstTimeInOtherLoop = 1;
int x;
 
//Will hold the incoming character from the Serial Port.
char incoming_char=0;
//Create a ‘fake’ serial port. Pin 2 is the Rx pin, pin 3 is the Tx pin.
SoftwareSerial cell(2,3);  
void setup() {
  
  //Initialize Arduino serial port for debugging.
  Serial.begin(9600);
  
  //Initialize virtual serial port to talk to Phone.
  cell.begin(9600);
  //Hello World.
  Serial.println(«Starting SM5100B Communication…»);
  delay(1000);
  //Set initial network state
  network_registered = 0;
  network_AT_ready = 0;
}
//Read AT strings from the cellular shield
void readATString(void) {
  char c;
  buffidx= 0; // start at begninning
  for (x = 0; x < 10000; x ++) {    
    if(cell.available() > 0) {
      c=cell.read();
      if (c == -1) {
        at_buffer[buffidx] = ‘\0’;
        return;
      }
      if (c == ‘\n’) {
        continue;
      }
      if ((buffidx == BUFFSIZ – 1) || (c == ‘\r’)){
        at_buffer[buffidx] = ‘\0’;
        return;
      }
      at_buffer[buffidx++]= c;
    }
  }
}
Y para recibir una  llamada  podemos utilizar este código:
//Process the AT strings
void ProcessATString() {
  if( strstr(at_buffer, «+SIND: 8») != 0 ) {
    network_registered = 0;
    Serial.println(«network Network Not Available»);
  }
  if( strstr(at_buffer, «+SIND: 11») != 0 ) {
    network_registered=1;
    Serial.println(«network Registered»);
  }
  
  if( strstr(at_buffer, «+SIND: 4») != 0 ) {
    network_AT_ready=1;
    Serial.println(«network AT Ready»);
  }
}
 
void loop() {
/* If called for the first time, loop until network and AT is ready */
if(firstTimeInLoop == 1) {
  firstTimeInLoop = 0;
  while (network_registered == 0 || network_AT_ready == 0) {
    readATString();
    ProcessATString();
    }
  }
if(firstTimeInOtherLoop == 1){
  //Look for incoming call
  if( strstr(at_buffer, «+CPAS: 3») != 0 ) {
     //Answer the phone
     cell.println(«ATA»);
     firstTimeInOtherLoop = 0;
   }
 }
}



Fuente aqui





solo-electronicos por Carlos Rodriguez Navarro se encuentra bajo una Licencia Creative Commons Atribución-NoComercial-CompartirIgual 3.0 Unported.

0 comentarios en “Modulo de GSM para Ardduino o Netduino

Deja una respuesta