Instructables

SM5100B GPRS and General Notes

Picture of SM5100B GPRS and General Notes
This instructable is for the use of the SM5100B-D shield from sparkfun: https://www.sparkfun.com/products/9607
Its no good to you for the other GSM shields, Sorry.

I spent so, so long hacking at this stupid shield trying to make sense of the +SIND's  and other rubbish - these things do work, they just test your patience. The minimal and poorly written documentation is useful if not as frustrating, hopefully this will save you some time.

Dont take this all for gospel, Im not an electronics or programming whizz, I have just persevered and learnt a few things.
Please feel free to question anything written here and Ill try to update the instruct-able if you can contribute.
 
 
Remove these adsRemove these ads by Signing Up

Step 1: Things to consider


I have found some good resources,
The most useful being some actual working code:
https://github.com/tobek/SM5100B-GPRS/blob/master/...
&
A good intro into setup
http://tronixstuff.com/2011/01/19/tutorial-arduino...


Some things to note:
1) Software serial is not the best option, in my tests it doesn't keep up with the serial output from the GSM module, and if you cant keep up then the data is dropped and your stuck. Software serial is ok for grabbing the return codes from your AT commands but when it comes to receiving your actual data, like http responses - it just doesn't keep up at all. I have seen mention that the 9600 baud rate that the SM5100B-D is set to is not fast enough, I have not found this to be true, as long as I use a hardware UART I get all the data back from the shield.

2) Power - you cant run this shield from the Arduino Power - you just cant. I tried to ignore these warnings, dont waste your time. Feed it 5 volts from a transformer or battery capable of supplying 2-3 amps. You will find that if you dont it will just keep overdrawing on your Arduino when it goes to transmit and everything will just reset.

3) Antenna, you need one.
I have actually been able to get +SIND:4 without one, but I have been getting full reception with one of those tiny little duck Antennas - I got two for a couple of dollars right here:http://www.electrodragon.com/?product=quad-band-ce... For Australians - You can pick up an antenna from Jaycar - pricey but dont have to wait on delivery: http://www.jaycar.com.au/productView.asp?ID=AR3310

4) Documentation, the official AT command set documentation comes in handy, only the author truly knows what on earth he/she was trying to describe, its bad, real bad, but it comes in handy: https://www.sparkfun.com/datasheets/CellularShield...
I guess sparkfun wrote this more specific GPRS / IP stuff, as it kind of makes sense in comparison:
https://www.sparkfun.com/datasheets/CellularShield/SM5100B%20TCPIP%20App%20Note.pdf

Step 2: Power

Power:
As mentioned, you need external power. Im using a 3 amp 5 volt regulated power supply. Negative into GND and positive into VIN. Picture 1




Step 3: Serial Connections

As mentioned, I have had no luck using the software serial library to talk to the SM5100B-D.
Since you need to use a Hardware UART for the GSM stuff, and you need to use a serial connection also for your debugging purposes, you need either more hardware UARTS or A USB serial adaptor.

So the options are:

1) Get a Mega 2560 - official from Arduino: http://arduino.cc/en/Main/arduinoBoardMega2560
Or I prefer the free tronics EtherMega:http://www.freetronics.com/collections/arduino/pro...
These Arduinos have 4 hardware UARTS, plenty!

2) Use your standard UNO or whatever and also make use of a USB serial adaptor such as the one I have from freetronics:http://www.freetronics.com/products/usb-serial-ada... or one of the prolific based usb serial converters that are all over ebay. (If using the ebay jobbies - check that they are 5 volt logic not 12v, 12v will fry arduino!)

I'm using option 2, usb Serial Adaptor.
With RX and TX going to pins 2 and 3 on my uno. Vout & Gnd to the Uno's Gnd and Vin.
Conveniently this Serial adaptor will power the uno as well, if your using a standard serial converter cable like the prolific ones you'll need an external 5 volt source for your arduino, you can take it from the SM5100B-D 5v and GND.

From the SM5100B-D i have pins 2 and 3 connected to the Hardware UART on the UNO pins 0 and 1.
You can see I have not stacked the GSM board ontop of the UNO!
This is because when I need to upload sketches to the UNO it cannot be done through the software serial pins that and the USB serial adaptor. I have to disconnect the SM5100B-D serial connection and plug the USB cable into the uno to upload the sketch. The Arduinos will only accept sketches uploaded to pins 0/1!

And I have to remember to disconnect the SM5100B-D from these pins while uploading code it will not know what to do with that info being dropped on pins 0/1 during this time, it might also be dangerous for one or the other board? Either way when uploading code disconnect the serial connection between the uno and SM5100B-D and then reconnect again.

So the first photo is the connection when I am running my GPRS code and debugging, with the software serial port sending data out pins 2/3 to the USB serial adaptor to the serial monitor, and the hardware UART pins 0/1 doing the high speed communication with the SM5100B-D.
The second photo is what I have to do for uploading sketches.

Yes It would be easier to just use a MEGA 2560!

Step 4: +SIND 4


We need to see a +SIND: 4 response from the SMB5100B-D, ( im just gonna call that the GSM card now, sick of typing SMB5100B-D).

So some easy code for checking this:

#include
#define GSMSerial Serial // the hardware serial will now be known as GSMSerial, to avoid confusion
SoftwareSerial SMSerial(2,3); //Using Software Serial as second UART -
char incoming_char=0; //Will hold the incoming character from the software Serial Port.
void setup()
{
//Initialize serial ports for communication.
SMSerial.begin(9600);
GSMSerial.begin(9600);
SMSerial.println("Starting SM5100B Communication...");
}
void loop()
{
if(GSMSerial.available()>0) //If a character comes in from the cellular module...
{
SMSerial.write(GSMSerial.read()); //write it out to the serial monitor so we can see it
}
if(SMSerial.available() >0) //If you type something into the serial monitor
{
incoming_char=SMSerial.read(); //Get the character coming from the terminal
GSMSerial.print(incoming_char); //Send the character to the cellular module.
}
}


You should see the following output on your serial monitor:

Starting SM5100B Communication...
+SIND: 1
+SIND: 10,"SM",1,"FD",1,"LD",1,"MC",1,"RC",1,"ME",1
+STIN:0
+SIND: 11
+SIND: 3
+SIND: 4

If you get nothing, you probably mixed up the TX RX pins on the serial monitor.

If you get "Starting SM5100B Communication..." then a whole lot of gobbly gook then you may have mixed up the serial TX RX pins between uno 0/1 and GSM 2/3

If its all just rubbish output then check if your serial monitor is set to 9600!

BUT If the last line you got was "+SIND: 4" then your luckier than most:)
If you got anything else as the last line, you need to find out why. You'll get more info on that here.


+SIND: 4 means we are registered on the mobile network and ready to do stuff.
For Example, type into the serial monitor, ATDXXXXXXXXXX
With the X's replaced with your own mobile number, and hit enter. (Make sure NL & CR are selected in the drop-down box at the bottom of the serial monitor). The sketch you uploaded will pass this to your GSM module and it will dial your mobile. You can send the command ATH to hangup.

Step 5: GPRS

If you got this far and you can either send an SMS or make a call, or some other way validate that you indeed have a functioning connection to the mobile network then we can try to get a GPRS session going.

This code is a hacked up from a sample I found by a guy named Toby: https://github.com/tobek/SM5100B-GPRS/blob/master/... it was pretty much the only functioning bit of code on the internet! Thank You Toby Fox!!
It calls out to httpbin.org and makes a http get request. httpbin.org is a handy set of pages for debugging http stuff.

You may want to just go and grab Toby's sample instead cause its the original, probrably better and is well documented, although this one below is already modified to use the Hardware UART for GSM and software for serial monitor as mentioned earlier.


// Using the Hardware UART Initially to program the Sketch,
// Disconnect the GSM serial connection, plug usb into uno and upload sketch.
//Then to test the sketch, then remove the usb from uno and plug into the USB-Serial module.
// plug the GSM modem serial wires back into the hardware UART pins 0&1 again

//The idea is to use the GSM modem with the hardware UART as the Software Serial Library
//is to slow for GSM modem, but its obviously fine for debugging stuff

#include
#define GSMSerial Serial
SoftwareSerial SMSerial(2,3); //Using Software Serial as second UART -
const String apn = "internet"; // access-point name for GPRS
const String ip = "54.235.174.110"; // IP address of server we're connecting to
const String host = "httpbin.org"; // required in HTTP 1.1 - what's the name of the host at this IP address?
const String request = "GET /get?data=testing HTTP/1.1";
const String useragent = "Mozilla/5.0"; // for our purposes the user agent doesn't matter - if I understand correctly it's helpful to use something generic the server will recognize
void setup()
{
SMSerial.begin(9600);
SMSerial.println("Starting SM5100B Communication...");
GSMSerial.begin(9600);
waitTil("+SIND: 4"); // keep printing GSMSerial output til we get "+SIND: 4"
SMSerial.println("Module ready");
}
void loop()
{

SMSerial.println("Attaching GPRS...");
GSMSerial.println("AT+CGATT=1");
waitFor("OK");
SMSerial.println("Setting up PDP Context...");
GSMSerial.println("AT+CGDCONT=1,\"IP\",\""+apn+"\"");
waitFor("OK");
SMSerial.println("Activating PDP Context...");
GSMSerial.println("AT+CGACT=1,1");
waitFor("OK");
SMSerial.println("Configuring TCP connection to TCP Server...");
GSMSerial.println("AT+SDATACONF=1,\"TCP\",\""+ip+"\",80");
waitFor("OK");
SMSerial.println("Starting TCP Connection...");
GSMSerial.println("AT+SDATASTART=1,1");
waitFor("OK");
while (1) { // now we'll loop forever, checking the socket status and only breaking when we connect
SMSerial.println("Checking socket status:");
GSMSerial.println("AT+SDATASTATUS=1"); // we'll get back SOCKSTATUS and then OK
String sockstat = getMessage();
waitFor("OK");
if (sockstat=="+SOCKSTATUS: 1,0,0104,0,0,0") {
//SMSerial.println("Not connected yet. Waiting 1 second and trying again.");
delay(750);
}
else if (sockstat=="+SOCKSTATUS: 1,1,0102,0,0,0") {
SMSerial.print(" !!!Socket connected!!! ");
break;
}
else {
SMSerial.println("We didn't expect that.");
cellOutputForever();
}
}
int packetLength = 26+host.length()+request.length()+useragent.length(); // 26 is size of the non-variable parts of the packet, see SIZE comments below
SMSerial.println("Sending HTTP packet...");
GSMSerial.print("AT+SDATATSEND=1,"+String(packetLength)+"\r");
waitFor('>'); // wait for GSM module to tell us it's ready to recieve the packet
GSMSerial.print(request+"\r\n"); // SIZE: 2
GSMSerial.print("Host: "+host+"\r\n"); // SIZE: 8
GSMSerial.print("User-Agent: "+useragent+"\r\n\r\n"); // SIZE: 16
GSMSerial.write(26); // ctrl+z character: send the packet
waitFor("OK");
waitTil("+STCPD:1"); // this means data is received
//waitTil("+STCPC:1"); // this means socket is closed
SMSerial.println("Reading data from server...");
GSMSerial.println("AT+SDATAREAD=1"); // how we read data server has sent
cellOutputForever(); // just keep printing whatever GSM module is telling us
}
/* NOTES
*
* what is +STIN:1 ?
*
* to disconnect after transmission: AT+CGACT=0,1 breaks socket. AT+CGATT=0 seems to work more authoritatively?
* AT+SDATASTART=1,0 // close TCP connection
* AT+SDATASTATUS=1 // clear sent/ack bytes from SOCKSTATUS
*
*/
// ====== HELPER FUNCTIONS ====== //
// keep reading the serial messages we receive from the module
// loop forever until we get a nonzero string ending in \r\n - print and return that.
// TODO: implement a timeout that returns 0?
String getMessage() {
String s="";
while(1) {
if(GSMSerial.available()>0) {
s = s+(char)GSMSerial.read();
if (s.length()>1 && s[s.length()-2]=='\r' && s[s.length()-1]=='\n') { // if last 2 chars are \r\n
if (s==" \r\n" || s=="\r\n") { // skip these, move on
s="";
}
else { // we have a message!
SMSerial.println(s.substring(0,s.length()-2));
return s.substring(0,s.length()-2);
}
}
}
}
}
// for eating a single message we expect from the module
// prints out the next message from the module. if it's not the expected value, die
void waitFor(String s) {
String message=getMessage();
if (message != s) {
SMSerial.println("Wait, that's not what we were expecting. We wanted \""+s+"\"");
cellOutputForever();
}
delay(100); // wait for a tiny bit before sending the next command
}
// keep spitting out messages from the module til we get the one we expect
void waitTil(String s) {
String message;
while (1) {
message = getMessage();
if (message == s){
delay(100); // cause we're probably about to send another command
return;
}
}
}
// keep reading characters until we get char c
void waitFor(char c) {
while(1) {
if(GSMSerial.available()>0) {
if ((char)GSMSerial.read() == c) {
delay(100);
return;
}
}
}
}
// if something goes wrong, abort and just display cell module output so we can see error messages
// this will loop forever
void cellOutputForever() {
SMSerial.println("Now displaying cell module output forever");
GSMSerial.println("AT+SDATAREAD=1\r\n");
char incoming_char=0;
while(1)
{
if(GSMSerial.available()>0)
{
SMSerial.write(GSMSerial.read());
}
if(SMSerial.available() >0)
{
incoming_char=SMSerial.read(); //Get the character coming from the terminal
GSMSerial.print(incoming_char); //Send the character to the cellular module.
}
}
}
// like above, but in hex, useful for debugging
void cellHexForever() {
while(1) {
if(GSMSerial.available()>0) {
char c = (char)GSMSerial.read();
// Serial.print("a char: ");
SMSerial.print(c, HEX);
SMSerial.print(" ");
SMSerial.println(c);
}
}
}
// receive string such as "SOCKSTATUS: 1,1,0102,10,10,0"
// 0 is connection id. 1 is whether connected or not. 2 is status (0104 is connecting, 0102 is connected, others)
// 3 is sent bytes. 4 is acknowledged bytes. 5 is "received data counter"
// THIS FUNCTION WILL check that sent bytes == ack bytes, and return that value
// return 0 if they don't match or if amount of data is 0
int checkSocketString(String s) {
if (socketStringSlice(3,s) == 0)
return 0;
else if (socketStringSlice(3,s) == socketStringSlice(4,s))
return socketStringSlice(3,s);
else
return 0;
}
// returns the index of the nth instance of char c in String s
int nthIndexOf(int n, char c, String s) {
int index=0;
for (int i=0; i<=n; i++) {
index = s.indexOf(c,index+1);
}
return index;
}
// expects string such as "SOCKSTATUS: 1,1,0102,10,10,0"
// returns nth chunk of data, delimited by commas
int socketStringSlice(int n, String s) {
String slice = s.substring(nthIndexOf(n-1,',',s)+1,nthIndexOf(n,',',s));
char cArray[slice.length()+1];
slice.toCharArray(cArray, sizeof(cArray));
return atoi(cArray);
}




Here is the Serial monitor output you should expect
Starting SM5100B Communication...
ÐèÐÐÐ
+SIND: 1
+SIND: 10,"SM",1,"FD",1,"LD",1,"MC",1,"RC",1,"ME",1
+STIN:0
+SIND: 11
+SIND: 3
+SIND: 4
Module ready
Attaching GPRS...
OK
Setting up PDP Context...
OK
Activating PDP Context...
OK
Configuring TCP connection to TCP Server...
OK
Starting TCP Connection...
OK
Checking socket status:
+SOCKSTATUS: 1,0,0104,0,0,0
OK
Checking socket status:
+SOCKSTATUS: 1,1,0102,0,0,0
OK
!!!Socket connected!!! Sending HTTP packet...
OK
+STCPD:1
Reading data from server...
Now displaying cell module output forever
+SDATA:1,486,485454502F312E3120323030204F4B0D0A4163636573732D436F6E74726F6C2D416C6C6F772D4F726967696E3A202A0D0A436F6E74656E742D547970653A206170706C69636174696F6E2F6A736F6E0D0A446174653A205468752C203134204E6F7620323031332030353A32373A323320474D540D0A5365727665723A2067756E69636F726E2F302E31372E340D0A436F6E74656E742D4C656E6774683A203236330D0A582D43616368653A204D4953532066726F6D207478323272727065703233620D0A436F6E6E656374696F6E3A206B6565702D616C6976650D0A0D0A7B0A20202275726C223A2022687474703A2F2F6874747062696E2E6F72672F6765743F646174613D74657374696E67222C0A20202268656164657273223A207B0A2020202022436F6E6E656374696F6E223A2022636C6F7365222C0A2020202022486F7374223A20226874747062696E2E6F7267222C0A202020202243616368652D436F6E74726F6C223A20226D61782D6167653D323539323030222C0A2020202022557365722D4167656E74223A20224D6F7A696C6C612F352E30220A20207D2C0A2020226F726967696E223A202234392E3138302E3132322E3337222C0A20202261726773223A207B0A202020202264617461223A202274657374696E67220A20207D0A7D
OK
+SDATA:1,0,
OK


Note that the +SDATA output is in HEX, so that big old string of garble you will receive back needs to be converted.
You can paste it into this site to get an easy look at what the output was: http://www.dolcevie.com/js/converter.html
and after decoding the hex, our output is

HTTP/1.1 200 OK??Access-Control-Allow-Origin: *??Content-Type: application/json??Date: Thu, 14 Nov 2013 05:27:23 GMT??Server: gunicorn/0.17.4??Content-Length: 263??X-Cache: MISS from tx22rrpep23b??Connection: keep-alive????{? "url": "http://httpbin.org/get?data=testing",? "headers": {? "Connection": "close",? "Host": "httpbin.org",? "Cache-Control": "max-age=259200",? "User-Agent": "Mozilla/5.0"? },? "origin": "49.180.122.37",? "args": {? "data": "testing"? }?}?

So a successfull http get request, I never thought it would happen.


EDIT!!!

You can tell the 5100B to replay you the recived data in ASCII!! With one simple command "AT+SDATARXMD=1,1,0"

So before this line:"GSMSerial.println("AT+SDATAREAD=1"); // how we read data server has sent"
add the code:

GSMSerial.println("AT+SDATARXMD=1,1,0");
waitFor("OK");

This will set the output to ASCII just before you call the SDATAREAD!
And the data your presented will now look much more beautiful more like this:

+SSTR:1,HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Cont12:16 GMT
Server: gunicorn/0.17.4
Content-Length: 264
X-Cache: MISS from tx22rrpep38a
Connection: keep-alive
{
"args": {
"data": "testing"
},
"headers": {
"Host": "httpbin.org",
"User-Agent": "Mozilla/5.0",
"Cache-Control": "max-age=259200",
"Connection": "close"
},
"url": "http://httpbin.org/get?data=testing",
"origin": "49.180.112.246"
}


With no need for you to write a Hex to ASCII conversion function:)

One big old problem this presents is the "OK" that is part of a HTTP response.
OK is also the way the SM5100B tells us its processed a command, whenever we se "OK\r\n" as a string in the serial buffer we know that the GSM module has answered and this forms the end of the message,,, so then its difficult to know if the "OK\r\n" at the beginning of the HTTP response is part of the response or the message at the end of successfully processing the AT Command.  
"So look for the second "OK\r\n" I thought... but then what if there is also a "OK\r\n" in the body of the response!!! 
Any ideas anyone, bueller, anyone?



Step 6: Make an arduino Library

So now I am working on a library so that I can make simple http requests without having to deal with all of that code.
I hope to make it as simple as response = GSMhttpGet("URL").
Anyone want to help with this?

Im making allot of progress with this library already.
Here are the functions I have already got coded and partially tested:

void reboot();
String GetReceptionLvl();
int hasNetworkReg();
int networkSignal();
void placeCall(String phoneNumber);
void hangUp();
void answerCall();
void sendDTMF(String DTMFTone);
void setDTMFTime(String DtmfTime);
void sendSMS(String sendTo, String sendText);
int getSMSMsgCount(String storeType); //Dont use: made obsolete by getSMSIndexs
void getSMSByIndex(int smsIndex, String smsString[]);
bool deleteSMSByIndex(int smsIndex);
void getSMSIndexs(int smsIndexs[], int &arraysize);
bool GPRSCheckAndAttach();
bool PDPSetupAndActivate(String apn);
bool TCPIPSetupAndStart(String IP);
String HttpGet(String Request, String host, String useragent);

Ive basically gone through the AT command documentation and made functions out of all the useful AT commands.
Then made some more goodies like, getmssagecount, and some GPRS functions, and HttpGet which accepts all the required information, makes the HTTP get and returns you back the result. Im not a C coder, Im a hack, so Im not going to post this library till Ive had the best go I can at it, if anyone wants it in its current state or would like to help me build on it, please send me a message!

Ben

cbrompton1 month ago

Hey Thanks for all your info on this. I have successfully made connection to my web server. I'm no t a C coder either but I would love to look at your library and perhaps have a go at it with you. send me a message if you are interested

BenHarper (author)  cbrompton1 month ago

G'day,

Sorry to say I dropped the ball on this.

I really needed a GSM modem in the end form my project so got a 3g dongle and connected it to a beaglebone, was allot of hassle trying to work with AT commands and strings and such when I really just needed full blown tcp routing.

I can dig up the code I had started for the library if your interested, its fairly basic but maybe its a starting point if you wish to pursue it? Library had some test scripts as well.

I've zipped them up and I PM'd you, reply if your interested in what I have so far and ill send it.

Hi!

I am working on a project and your info has been really helpfull! Could you plz send me a copy of your arduino library?

thanks!

BenHarper (author)  cristobalgh10 days ago

G'day Cristobalgh, were are you from mate?

I don't have your email so I have put it up on dropbox: https://dl.dropboxusercontent.com/u/57971816/5100B...

I don't remember what state the library is but I assume its as i left it.

Im not a great coder so its probably just a good reference for you to make your own code more than a fantastic library ready to use;)

Cheers

Ben

amir11224 months ago

Hey,

Can I please ask why did you need the USB serial adapter. Couldn't you connect to the one UART you have? I have Arduino Due with 4 UART and having trouble connecting it properly to the shield? How should it be connected as I get no response on the serial monitor.

Thank you

BenHarper (author)  amir11224 months ago

I was using a uno with only one UART, I needed that one UART for the module to talk to the arduino but also wanted to wanted to debug via the serial monitor which needs a UART as well so I needed the extra FTDI serial connection, you wont need it as you have 4 on board - I have since taken to the mega 2560 so I dont need that any longer either.

Are you getting no response at all from your aduino or the arduino is showing no response from the GSM module?

First Thank you.
On my cellular shield, the two connections that are soldered together are the two closest to the Rx Tx writing. According to the schematic and my understanding, this only enables the shield to send serial communication via ports 2,3. My connections:
Arduino Due connected to computer via USB.
Shield gets its power from 5v external power (capable of 2.5A) supply and both the shield and the board are connected to its ground.
Port 2 of shield connected to Tx1 of Arduino
Port 3 of shield connected to Rx1 of Arduino.
I have also tried to used ports 0,1 of the shield labelled Rx Tx and connect them to Arduino serial 1. Anyway still nothing appears on Arduino IDE serial monitor but starting serial communication.
Any help will be much appreciated...
BenHarper (author)  amir11224 months ago

And did you try the amended code I added in the comment below?

I think port two on the GSM module is TX and should go to the RX of your arduino - I know that looks strange as the markings show RX TX for 0 & 1 and so you would guess that it was RX TX for 2 & 3 - but no its TX RX for pins 2 & 3 on the GSM shield.

Try that simple swap first, then if no good - troubleshoot with some ideas below:

Connect TX0 to RX1, and RX0 to TX1 - then start the serial montitor

You should get the "Starting SM5100B Communication..." bouncing backwards and forwards between your serial connections and printing over and over on your serial monitor - If so your Code is working fine.

If so, then connect pin 2 of GSM Sheild (confusingly it seems pin two is TX not pin 3 as i would have guessed) to your Serial 1 RX and restart the shield and the arduino.

Also remember when your searching for the serial connection, restart the GSM sheild after making changes as it goes through its setup and then goes quiet, so you may not see anything and think its not working, but in reality its just waiting for you to talk to it - So reset gsm shield and see if you get any serial data.

If your not getting any serial data resembling

+SIND: 11

+SIND: 3

+SIND: 4

ÐèÐèÐ

+SIND: 1

+SIND: 10,"SM",1,"FD",1,"LD",1,"MC",1,"RC",1,"ME",1

+STIN:0

+SIND: 4

then at this point then you need to work out why your GSM shield is not communicating. Even if your baud rates are mismatched you should at least get a whole lot of rubbish characters showing up. If you get nothing get your oscilloscope then probe the TX pin of the shield , if you don't have an oscilloscope consider buying one - you need one - even a super cheapie of eBay is worth every dollar * 1000, without a scope everything is just a big old guess).

Otherwise if you have a logic analyser you can use that to check the TX line from GSM Module, or maybe even get by with a multimeter. Or if you have a FTDI cable or other TTL serial to USB cable you can connect the RX of that to the TX of the GSM Module and see if you can capture any serial data. You really need to have at least one if not all of these test equipment options to work out whats going on - otherwise your just jumping pins everywhere in random combinations hoping something will work.

Hey Ben,

I did what you said and it does work. The problem was with the pins. Thank you for that. However, now I have another issue. I am trying to connect both the shield (serial 3 on Due) and a puprletooth jamboree bluetooth module (Serial2 on Due). When both are connected to Due only the BT module works and the cellular shield stops responding. Both are connected to an external power source. Any idea as to why? Is the board unable to drive both together?

Thank you.

BenHarper (author)  amir11223 months ago
No, board can talk on all 4 serial connections almost at same time, it buffers incoming data so it can process it as it has time, I believe, either way I have communicated on all 4 connections before to test this theory and it's no prob. Please attach photo and code sample and I'm sure it's something I can see going wrong
BenHarper (author)  amir11224 months ago

Maybe I know why theres nothing coming back to you, if you are using the code from step 4, you will need to remove the software serial part and just apply one of your other hardware serial UART ports instead so something like

#include
#define GSMSerial Serial1 // the hardware serial will now be known as GSMSerial

#define SMSerial Serial //

char incoming_char=0; //Will hold the incoming character from the software Serial Port.
void setup()
{
//Initialize serial ports for communication.
SMSerial.begin(9600);
GSMSerial.begin(9600);
SMSerial.println("Starting SM5100B Communication...");
}
void loop()
{
if(GSMSerial.available()>0) //If a character comes in from the cellular module...
{
SMSerial.write(GSMSerial.read()); //write it out to the serial monitor so we can see it
}
if(SMSerial.available() >0) //If you type something into the serial monitor
{
incoming_char=SMSerial.read(); //Get the character coming from the terminal
GSMSerial.print(incoming_char); //Send the character to the cellular module.
}
}


And then your serial (Serial 0) which comes out of the USB port (and pins 0&1) will be your serial monitor connection and what ever ports your second UART (serial1) is connected to will be the ones you connect over to the GSM module.

Also - dont sit the GSM module on top of your arduino, sit it beside for testing and run link wires over to it like in my photo. The GSM module is using pins 0&1 for its serial link, if you stick the boards together it will be talking to your aduino over the same pins (0&1) that your arduino is talking to the computer on.

Sorry if this is obvious, but just in case your not aware - the USB serial interface, shares the pins 0 & 1 - so you will find anything getting sent up and down the USB cable is also using those pins 0&1, and if you try to use them for other purposes (by accidentally putting a shield on top which tries to use the same pins, like this GSM shield does)then there will be a big old miscommunication.

I guess this is where your problem is - let me know if its not the case.

So in short.

Use your USB for degugging via serial montor

Dont stack the shield on the top of your Arduino!

Use pins 19 (RX) and 18 (TX) on your due to connect to the GSM module

ANd lastly, when you put it all together in the end and want to be able to stack the shield on top without the pins 0&1 double up, there is a trace on the GSM module that you can solder or desolder (forget the details) and it changes the pins that the GSM module is using - Youll have to read into that cause I have forgotten how it works

arei2_114 months ago

Great job! I'm also writing my TCP library (I need only a GET connection). Now I'm thinking which is the best method to capture an error from the module when connection is lost using the virtual serial port.

This is a part of my code.

void SerialTCP::sendData(String DOM, String URL)

{

String toReplace = GETCONST;

toReplace.replace("!", URL);

toReplace.replace("<", DOM);

int l = toReplace.length() * 2;

int i = 0;

this->print("AT+SDATASEND=1,");

this->print(l);

this->print(",\"");

while(i < toReplace.length())

{

if(toReplace.charAt(i) == '(')

{

this->print("0A");

}

else

{

this->print(toReplace.charAt(i), HEX);

}

i++;

}

this->println("\"");

}

Where GETCONST = "GET /! HTTP/1.1(Host:<(("