Connecting issues with SIM900 + Mega 2560

Hi - I’m new to everything here, but I spent a long time trying to work everything out myself and reading as much as I could find before asking here.

I have a SIM900 shield connected to an Arduino Mega 2560 (properly), and a functional SIM card with credit and no SIM lock. Latest libraries installed.

I used the example TinyGSM_SIM800_SIM900 script from the Blynk > Boards_GSM folder - code included below.

I get a continuous message like this:

Connecting to blynk-cloud.com:80

I’ve seen others with the issue and tried their fixes but nothing worked.

I found multiple APN options from this SIM provider (Telcel, Mexico) on these two sites: 1, 2. I tried every password and variation, none seemed to work.

Auth code is correct too (though I haven’t even managed to connect to it yet).

I’m hoping someone will spot something obviously wrong with my code - it’s very frustrating and I’ve exhausted myself trying to work it out :triumph:

#define BLYNK_PRINT Serial

#define TINY_GSM_MODEM_SIM900

#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>

char auth[] = "caa13264af8b49ba947d8f9bf3d52460";

char apn[]  = "internet.itelcel.com";
char user[] = "webgprs";
char pass[] = "webgprs2003";

#define SerialAT Serial1


TinyGsm modem(SerialAT);

void setup()
{
  // Debug console
  Serial.begin(115200);

  delay(10);

  // Set GSM module baud rate
  SerialAT.begin(115200);
  delay(3000);

  Serial.println("Initializing modem...");
  modem.restart();

  Blynk.begin(auth, modem, apn, user, pass);
}

void loop()
{
  Blynk.run();
}

Hi. Try to set time and baud rate on your SIM900. You may do that by following simple code with some of AT-commands:

#include <SoftwareSerial.h>
SoftwareSerial mySerial(50,51); //TX, RX (or if it does not work, change them rx tx)
void setup()
{
  mySerial.begin(9600);                 
  Serial.begin(9600);                 
}
void loop()
{
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read()); 

}

Now enter this command to your serial monitor:
AT+CCLK=“13/09/25,13:25:33+05” <- your current time
AT+IPR=9600 <- Needed baud rate

Try to clear your

char apn[]  = "internet";
char user[] = "";
char pass[] = "";

Try to change (it is not necessary) your serial pins in your blynk-included code:

SoftwareSerial SerialAT(50, 51); // RX, TX (or different)
TinyGsm modem(SerialAT);
void setup()
{
  Serial.begin(9600);
 delay(10);

  // Set GSM module baud rate
  SerialAT.begin(9600);
  delay(3000);
}

That first code doesn’t seem to do anything - I think it’s because I’m using a Mega, my pins are TX = 18 / RX = 19 hardware connection…not sure how to make the code reflect that though, I’m not very good yet

First of all, try to achieve to your serial monitor (for relationship with sim900 module). It does not matter, hardare configuration pins you use, or software. In my case, software pins worked. And, as I understand, software pins may be “Not all pins on the Mega and Mega 2560 support change interrupts,
so only the following can be used for RX:
10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69”
Try to use software-serial library instead of default hardware serial pins, maybe it will help.

I thought I was communicating with it this whole time with the setup I have here - it was clearly communicating with the SIM900 board because it returned my network carrier’s name.

This Mega has been nothing but trouble trying to connect things to it, when I go to look for tutorials and things, there’s ten different methods and none of them seem to work out. This is the closest I’ve gotten: Mega serial1 (TX1 18, RX1 19) to pins 0 and 1 on the SIM900 (TX and RX), plus a ground connection.

The SIM900 board is blinking in 3 second intervals, so the SIM card is definitely working properly. I dunno what else to do with this thing.

You are going from TX on the Mega to RX on the module, and visa versa right? If not, you must.

You know what, I thought of that yesterday just before I gave up, but by that point I’d just been getting a “modem couldn’t init” message - even with my exact previous settings and everything. I’m gonna try to start over again tomorrow I think - I read a lot about lowering the baud rate of the SIM900, and I tried that as well but nothing came of it. It was at 115200 when I had the most success…is that very high?

If you’re getting a response from the SIM900, via your Arduino, then you have the Rx/Tx pins connected correctly and they are talking at the same baud rate.
(Note that this is not the same as connecting your SIM900 than FTDI and getting responses back to your serial monitor, I’m talking about serial monitor —> Arduino —> SIM900 and back again).

If you do want to reduce the baud rate of the communication between your Arduino and your SIM900 then both ends need to be changed. The SIM900 needs to be told to use baud rate xxx by issuing the correct AT cummand, then the Arduino sketch needs to use baud rate xxx when it is talking to the SIM900.
The baud rate used between the Arduino and the serial monitor are totally independent of the Arduino to SIM900 baud rate and can be totally different if you wish.

Everything I’ve written above may already be known by you, but when I first started messing about with serial communications I managed to get myself totally confused, hence why I’ve reiterated the basic principals here.

I’ve not done enough with SIM800/900 boards to know if 115200 is too high, but lowering it might be worth trying.
You should also make sure that you have the latest version of the Tiny GSM library installed and turn on verbose compilation messages in the IDE and check that the correct library is actually being used at compilation time. If your verbose compiler messages say “multiple versions of file zzz found, this one used…” then that should ring some alarm bells, and you’ll need to dig a bit deeper to ensure that it’s the latest version that is in use.

Hope this helps.

Pete.

Thank you for the info - I believe I’ve had a connection before at 115200 because the serial monitor returned the name of the mobile carrier of the card in the SIM900. Maybe that’s not enough to say it’s a good connection though, I’m not sure if it’s an all-or-none type situation with baud rates.

I’m totally up to date over here with libraries and whatnot, TinyGSM and Blynk. I’m going to have to read about these verbose compiler messages you’re describing though.

I tried software connection with the Mega first and it was just not happening - I was pulling info from multiple tutorials though, all with slight differences…is there an official one for software connection anywhere? I have an Uno and a Nano here too if the Mega is just being picky.

The Mega is the better board to use, as it has multiple UARTs so allows hardware serial connections for both the SIM900 and serial debug.
The Uno and Nano would need to use SoftwareSerial to achieve the same result and these software simulated UARTs just aren’t as good. If you do use SoftwareSerial it’s not recommended to use a baud rate higher than 9600.

Pete.

2 Likes

OK so I spent some time messing with baud rates and the SIM900 only wants to connect at 74880. I’m still getting the same message though:

16:01:54.495 -> [97991] Connecting to blynk-cloud.com:80

I decided to try doing a direct USB connection, so I made a new Blynk app/auth for that and plugged it into the basic example script for Mega 2560s and I just get this over and over:

Login timeout

Maybe Blynk just doesn’t like Mexican IP addresses connecting? I have no idea at this point…I’m going to try a USB connection on my Uno now to see if it’s an issue with the 2560 board…

edit: Checked the Uno on USB direct, this time it just prints the auth number over and over on the serial monitor. It’s gotta be an account level error or something just preventing connections from my location :expressionless:

edit2: I’m connected and I can send texts to my other phone, but nothing is showing up on the serial monitor…maybe my code is wrong for that, I dunno. I’m not using Blynk for that though, just direct SIM900. Either way, it works…I just don’t know why Blynk doesn’t work for me.

edit3: ok i give up :frowning: