MG2639 Cellular Shield autobauding issue (Mega 2560)

Hi all,

I’m trying to configure an MG2639 quad-band shield (online link here, datasheet here) for use in my project. I’ve been trying basic sketches that came with the library, but there seems to be a problem with it interacting with the serial monitor - I just get gibberish fed back (i.e. strings of characters that look like a baud issue).

Things I’ve already tried/am trying

  • external power (9V,1.75A)
  • shield configured so it should work with the Mega (according to this solution on Stackexchange)
  • changing baudrate of serial port set up in code (and scaling serial monitor accordingly)
  • changing network of the SIM card

all with no luck.

I’ve been following Sparkfun’s setup guide, and the comments section of the setup guide mentions that this is a known bug, but I don’t know how to manually configure the baudrate in a library (and I’m assuming it’s always better to stick with the most recent IDE version here).

Could anyone help me?

To confirm,

Hardware

  • Genuino Mega 2560
  • MG2639 cellular shield
  • 9V 1.75A wall wart
  • SIM card (various networks)

Software

  • Arduino IDE 1.6.13
  • Official MG2639 library (here if anyone’s interested)

This is the code I’m using to try and see if the shield’s working. It should just return information about the SIM it contains:

#include <SoftwareSerial.h>
// Include the MG2639 Cellular Shield library
#include <SFE_MG2639_CellShield.h>

char imi[16]; // Storage array for IMI 
char iccid[20]; // Storage array for ICCID
char imei[17]; // Storage array for IMEI
char myPhone[15]; // Storage array for your phone number
char manufacturer[64]; // Storage array for manufacturer info
int ret;

void setup()
{
  Serial.begin(9600);
  
  // serialTrigger() halts execution of the program until
  // any value is received over the serial link.
  serialTrigger();
  
  // This status variable will store the response error codes
  // of any functions we call.
  uint8_t status;
  
  // Every MG2639 sketch should begin with cell.begin().
  // This function will initialize the module, turn it on if
  // it's off, and verify communication.
  // If it's successful, it'll return a 1. If it can't
  // communicate with the module, it returns a 0.
  ret = cell.begin();
  if (ret <= 0)
  {
    Serial.println("Unable to communicate with shield. Looping");
    while(1)
      ;
  }
  
  // cell.getInformation() returns a big, long string with
  // information like the manufactuer and hardware version.
  ret = cell.getInformation(manufacturer);
  if (ret > 0)
  {
    Serial.print("Manufacturer Info: ");
    Serial.println(manufacturer);
  }
  
  // cell.getIMI() returns the International Mobile
  // Identification (IMI or IMSI) of a SIM card.
  ret = cell.getIMI(imi);
  if (ret > 0)
  {
    Serial.print("IMI: ");
    Serial.println(imi);
  }
  
  // cell.getICCID() returns the ICCID of your SIM card. A 
  // unique value that should also be engraved on your card.
  ret = cell.getICCID(iccid);
  if (ret > 0)
  {
    Serial.print("ICCID: ");
    Serial.println(iccid);
  }
  
  // cell.getIMEI() returns the International Mobile Station
  // Equipment Identity (IMEI) of your MG2639 module.
  // The IMEI is a unique number, specific to the module on
  // the cell shield.
  ret = cell.getIMEI(imei);
  if (ret > 0)
  {
    Serial.print("IMEI: ");
    Serial.println(imei);
  }
  
  // getPhoneNumber requires one parameter - a char array
  // with enough space to store a phone number (~15 bytes).
  // Upon return, cell.getPhoneNumber(myPhone) will return
  // a 1 if successful, and myPhone will contain a char array
  // of your module's phone number.
  ret = cell.getPhoneNumber(myPhone);
  if (ret > 0)
  { // If the function successfully returned, print the #:
    Serial.print("My phone number is: ");
    Serial.println(myPhone);
  }
  Serial.println("Done. Did it work?");
}

void loop() 
{
}

void serialTrigger()
{
  Serial.println("Send some serial to start");
  while (!Serial.available())
    ;
  Serial.read();
}

I’ve also attached the cpp and h files, in case they’re any help.

To confirm, shield RSSI LED blinks at the expected 3Hz (searching for signal), then at 1Hz (idle) - so the SIM appears to be compatible, and the Mega seems to be making contact with the shield.

UPDATE: informed myself about the begin() function in the .h file, and realised you could use begin(BAUD_RATE) to set the shield connection to a desired baud rate. However that still doesn’t work, I’ve been using the same MG2639_getinfo example sketch as above, with both Serial.begin() and cell.begin() functions set to 4800 baud and am getting the following feedback:

Send some serial to start
Shield connected! Retrieving info...
Manufacturer Info: ¨»ü;ﯘöP»×yø¿¾¢H×é÷þMÂþÛ8›²„|Žm7åï•Ðeûœk÷%éûå>û¸j¾ó/
Manufacturer info found. Retrieving IMI
IMI: 
ICCID: 
IMEI: 
My phone number is: 
Done. Did it work?
Send some serial to start
Shield connected! Retrieving info...
Manufacturer Info: J¾þ—·'“£ÉÂ/‡/—ïéמïÕ}[½>·ãSí{ûZìEïJÚ/ré©ÿ¿û‰ÿ^ôÿà‹
Manufacturer info found. Retrieving IMI
IMI: 
ICCID: 
IMEI: 
My phone number is: 
Done. Did it work?

SFE_MG2639_CellShield.cpp (16.4 KB)

SFE_MG2639_CellShield.h (12.2 KB)

FURTHER UPDATES:

I've also been trying to use AT commands and other commands defined in the .h here, but can't quite find the right syntax for inserting them into sketches/more problems arrive. Any thoughts?

Using MG2639 .h Functions

I modified the getinfo example sketch with

currentBaud = cell.autoBaud();
  Serial.println(currentBaud);

to (obviously) display what the autobaud is up to after shield connection, and this is giving me slightly weird answers - mostly 0, and 2400 a few times, when I'm setting baud rate to 4800. 2400 baud returns gibberish at a random information return with silence elsewhere; 0 returns nothing (again, fairly obvious why).

Autobaud returns a 0 when unsuccessful, so this is clearly very hit-and-miss (and hugely unhelpful). It also seems to suggest either the module is initialising and completely ignoring my baud rate setting, or the autobaud function is hugely off.

Trying to use AT Commands

There's a function detailed in the .h file - sendATCommand() - it's what the majority of the other functions use, so it would make sense to be able to call it in the sketch itself. This command is described as below

/// sendATCommand([command]) - Send an AT command to the module. This
/// function takes a command WITHOUT the preceding "AT". It will add
/// the "AT" in the beginning and '\r' at the end.
/// Ex: sendATCommand("E0"); // Send ATE0\r to turn echo off
void sendATCommand(const char * command);

so I check the autobaud and, if it's wrong, call it

.
.
.
currentBaud = cell.autoBaud();
  Serial.print("Autobaud set at: ");Serial.println(currentBaud);
  if (BAUD == currentBaud)
  {
    Serial.println("This matches the baud rate specified in the sketch!!");
  }
  else
  {
    Serial.print("Autobaud does not match. Sending command 'AT+IPR=4800");
    cell.sendATCommand("+IPR=4800");
    currentBaud = cell.autoBaud();
    Serial.print("Autobaud now set at: ");Serial.println(currentBaud);
  }
.
.
.

but this refuses to compile and I get

exit status 1
within this context

highlighting the "cell.sendATCommand" line. What am I doing wrong here, could anybody point me in the right direction?