Index
1. Introducción
2. Descripción básica del módulo GPRS
3. Especificaciones generales
4. Ejemplo de una Librería Arduino SIM800L
Introducción del uso de la biblioteca Arduino SIM800L en nuestro PLC GPRS
Esta publicación muestra cómo usar elBiblioteca del módulo GPRS de Sim800L >>>
Esta biblioteca está desarrollada por Adafruit y se comunica con los módulos GSM a través de Serial TTL.
Necesitas usar la LibreríaSoftwareSerial.h >>
Descripción básica del módulo GPRS
Controlador industrial basado en tecnología Arduino diseñado para uso profesional. Este controlador lógico programable tiene 17 E / S. También contiene varios puertos de comunicación que brindan más flexibilidad y control.
El Controlador GPRS / GSM Arduino ofrece la posibilidad de expandir hasta 127 módulos a través de I2C. Este modelo también incluye hardware GPRS para comunicación GPRS. ¡La tarjeta SIM no está incluida!
Especificaciones generales de Sim800L (módulo integrado GPRS)
§ Quad-Band GSM 850/900/1800 / 1900MHz
§ Clase de ranuras múltiples GPRS 12/10
§ Estación móvil GPRS clase B
§ Frecuencia GSM 2/2 + FM entre 76 MHz y 109 kHz ajustable por paso 50AT Soporte de conjunto de comandos (3GPP TS 27.007, 27.005 y aumentado por SIMCOM AT)
§ Clase 4 (2W a 850 / 900MHz)
§ Clase 1 (1 W a 1800 / 1900MHz)
§ Interfaz Serial
§ Interfaz de tarjeta SIM 3 V / 1.8 V
Ejemplo de biblioteca Arduino SIM800L
Este código recibirá un SMS, identificará el número de teléfono del remitente y enviará una respuesta automáticamente.
Las conexiones internas entre el Arduino Mega interno del módulo GPRS y el Sim800L se muestran a continuación:
Arduino Mega Pinout | Sim800L Pinout |
5Vdc | Vcc |
GND | GND |
Tx1 (Pin 18) | TxD |
Rx1 (Pin19) | RxD |
Pin 2 | RST |
RECUERDA: ¡Abre la consola serie en el Arduino a 115200 baudios!
/***************************************************
Este es un ejemplo para nuestro Módulo Celular Adafruit FONA
Diseñado específicamente para trabajar con el Adafruit FONA
----> http://www.adafruit.com/products/1946
----> http://www.adafruit.com/products/1963
----> http://www.adafruit.com/products/2468
----> http://www.adafruit.com/products/2542
These cellular modules use TTL Serial to communicate, 2 pins are
required to interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/
/*
THIS CODE IS STILL IN PROGRESS!
Open up the serial console on the Arduino at 115200 baud to interact with FONA
*/
#include "Adafruit_FONA.h"
#define FONA_RX 19 //RX1 on Arduino Mega
#define FONA_TX 18 //TX1 on Arduino Mega
#define FONA_RST 2
// this is a large buffer for replies
char replybuffer[255];
// We default to using software serial. If you want to use hardware serial
// (because softserial isnt supported) comment out the following three lines
// and uncomment the HardwareSerial line
#include <SoftwareSerial.h>
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;
// Hardware serial is also possible!
// HardwareSerial *fonaSerial = &Serial1;
// Use this for FONA 800 and 808s
Adafruit_FONA fona = Adafruit_FONA(FONA_RST);
// Use this one for FONA 3G
//Adafruit_FONA_3G fona = Adafruit_FONA_3G(FONA_RST);
uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0);
void setup() {
while (!Serial);
Serial.begin(115200);
Serial.println(F("FONA SMS caller ID test"));
Serial.println(F("Initializing....(May take 3 seconds)"));
// make it slow so its easy to read!
fonaSerial->begin(4800);
if (! fona.begin(*fonaSerial)) {
Serial.println(F("Couldn't find FONA"));
while(1);
}
Serial.println(F("FONA is OK"));
// Print SIM card IMEI number.
char imei[16] = {0}; // MUST use a 16 character buffer for IMEI!
uint8_t imeiLen = fona.getIMEI(imei);
if (imeiLen > 0) {
Serial.print("SIM card IMEI: "); Serial.println(imei);
}
fonaSerial->print("AT+CNMI=2,1\r\n"); //set up the FONA to send a +CMTI notification when an SMS is received
Serial.println("FONA Ready");
}
char fonaNotificationBuffer[64]; //for notifications from the FONA
char smsBuffer[250];
void loop() {
char* bufPtr = fonaNotificationBuffer; //handy buffer pointer
if (fona.available()) //any data available from the FONA?
{
int slot = 0; //this will be the slot number of the SMS
int charCount = 0;
//Read the notification into fonaInBuffer
do {
*bufPtr = fona.read();
Serial.write(*bufPtr);
delay(1);
} while ((*bufPtr++ != '\n') && (fona.available()) && (++charCount < (sizeof(fonaNotificationBuffer)-1)));
//Add a terminal NULL to the notification string
*bufPtr = 0;
//Scan the notification string for an SMS received notification.
// If it's an SMS message, we'll get the slot number in 'slot'
if (1 == sscanf(fonaNotificationBuffer, "+CMTI: " FONA_PREF_SMS_STORAGE ",%d", &slot)) {
Serial.print("slot: "); Serial.println(slot);
char callerIDbuffer[32]; //we'll store the SMS sender number in here
// Retrieve SMS sender address/phone number.
if (! fona.getSMSSender(slot, callerIDbuffer, 31)) {
Serial.println("Didn't find SMS message in slot!");
}
Serial.print(F("FROM: ")); Serial.println(callerIDbuffer);
// Retrieve SMS value.
uint16_t smslen;
if (fona.readSMS(slot, smsBuffer, 250, &smslen)) { // pass in buffer and max len!
Serial.println(smsBuffer);
}
//Send back an automatic response
Serial.println("Sending reponse...");
if (!fona.sendSMS(callerIDbuffer, "Hey, I got your text!")) {
Serial.println(F("Failed"));
} else {
Serial.println(F("Sent!"));
}
// delete the original msg after it is processed
// otherwise, we will fill up all the slots
// and then we won't be able to receive SMS anymore
if (fona.deleteSMS(slot)) {
Serial.println(F("OK!"));
} else {
Serial.print(F("Couldn't delete SMS in slot ")); Serial.println(slot);
fona.print(F("AT+CMGD=?\r\n"));
}
}
}
}
Diseñado específicamente para trabajar con el Adafruit FONA ----> http://www.adafruit.com/products/1946 ----> http://www.adafruit.com/products/1963 ----> http://www.adafruit.com/products/2468 ----> http://www.adafruit.com/products/2542 These cellular modules use TTL Serial to communicate, 2 pins are required to interface Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! Written by Limor Fried/Ladyada for Adafruit Industries. BSD license, all text above must be included in any redistribution ****************************************************/ /* THIS CODE IS STILL IN PROGRESS! Open up the serial console on the Arduino at 115200 baud to interact with FONA */ #include "Adafruit_FONA.h" #define FONA_RX 19 //RX1 on Arduino Mega #define FONA_TX 18 //TX1 on Arduino Mega #define FONA_RST 2 // this is a large buffer for replies char replybuffer[255]; // We default to using software serial. If you want to use hardware serial // (because softserial isnt supported) comment out the following three lines // and uncomment the HardwareSerial line #include <SoftwareSerial.h> SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX); SoftwareSerial *fonaSerial = &fonaSS; // Hardware serial is also possible! // HardwareSerial *fonaSerial = &Serial1; // Use this for FONA 800 and 808s Adafruit_FONA fona = Adafruit_FONA(FONA_RST); // Use this one for FONA 3G //Adafruit_FONA_3G fona = Adafruit_FONA_3G(FONA_RST); uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0); void setup() { while (!Serial); Serial.begin(115200); Serial.println(F("FONA SMS caller ID test")); Serial.println(F("Initializing....(May take 3 seconds)")); // make it slow so its easy to read! fonaSerial->begin(4800); if (! fona.begin(*fonaSerial)) { Serial.println(F("Couldn't find FONA")); while(1); } Serial.println(F("FONA is OK")); // Print SIM card IMEI number. char imei[16] = {0}; // MUST use a 16 character buffer for IMEI! uint8_t imeiLen = fona.getIMEI(imei); if (imeiLen > 0) { Serial.print("SIM card IMEI: "); Serial.println(imei); } fonaSerial->print("AT+CNMI=2,1\r\n"); //set up the FONA to send a +CMTI notification when an SMS is received Serial.println("FONA Ready"); } char fonaNotificationBuffer[64]; //for notifications from the FONA char smsBuffer[250]; void loop() { char* bufPtr = fonaNotificationBuffer; //handy buffer pointer if (fona.available()) //any data available from the FONA? { int slot = 0; //this will be the slot number of the SMS int charCount = 0; //Read the notification into fonaInBuffer do { *bufPtr = fona.read(); Serial.write(*bufPtr); delay(1); } while ((*bufPtr++ != '\n') && (fona.available()) && (++charCount < (sizeof(fonaNotificationBuffer)-1))); //Add a terminal NULL to the notification string *bufPtr = 0; //Scan the notification string for an SMS received notification. // If it's an SMS message, we'll get the slot number in 'slot' if (1 == sscanf(fonaNotificationBuffer, "+CMTI: " FONA_PREF_SMS_STORAGE ",%d", &slot)) { Serial.print("slot: "); Serial.println(slot); char callerIDbuffer[32]; //we'll store the SMS sender number in here // Retrieve SMS sender address/phone number. if (! fona.getSMSSender(slot, callerIDbuffer, 31)) { Serial.println("Didn't find SMS message in slot!"); } Serial.print(F("FROM: ")); Serial.println(callerIDbuffer); // Retrieve SMS value. uint16_t smslen; if (fona.readSMS(slot, smsBuffer, 250, &smslen)) { // pass in buffer and max len! Serial.println(smsBuffer); } //Send back an automatic response Serial.println("Sending reponse..."); if (!fona.sendSMS(callerIDbuffer, "Hey, I got your text!")) { Serial.println(F("Failed")); } else { Serial.println(F("Sent!")); } // delete the original msg after it is processed // otherwise, we will fill up all the slots // and then we won't be able to receive SMS anymore if (fona.deleteSMS(slot)) { Serial.println(F("OK!")); } else { Serial.print(F("Couldn't delete SMS in slot ")); Serial.println(slot); fona.print(F("AT+CMGD=?\r\n")); } } } }
Echa un vistazo a estas soluciones de automatización de Arduino
Gama GPRS >>>
... y descubre los productos de esta familia diseñados para soluciones de automatización industrial que utilizan esta tecnología.
Lee nuestros estudios de caso
Casos de Estudio >>>
Encontrarás más artículos técnicos y varias implementaciones de proyectos basados en PLC Arduino, Raspberry Pi y ESP32 que te ayudarán con la automatización de tu industria.