The Arduino can talk over a wide range of networks. Ethernet, Bluetooth, Wifi, XBEE and GPRS to name the most known. I had a Telit GM862-GPS module laying around, unused for some time already. It has GPRS and GPS capabilities, both accessible with AT commands. So I decided to port some of my code to the Arduino.
Schematic
Connecting the Arduino Mega to the GM862 is rather easy. Only four connections are needed.
- Tx3 – Tx
- Rx3 – Rx
- Pin 22 – On/Off
- GND – GND
The GM862 is accessed with a breadboard fiendly breakout board from Sparkfun.
The logic pins of the GM862 accept only CMOS 2.8 Volt. For that reason, a voltage divider is needed for the Tx line. Both, Rx and Tx are pulled up to the PWR_CTL line of the module because these pins don’t have an internal pull up resistor.
The on/off line is connected to ground with a transistor.
The bad thing for this setup is the power supply. The module is powered by a LiPo cell (3.7 V with 2000 mAh). The Arduino Mega is powered by the USB port. If I want to make this portable, I have to use two batteries. Or find a better solution. Maybe powering the Arduino with a step-up converter.
Software
First I wanted to use an Arduino Pro mini, that runs on 3.3 V. That would save me from having two different power supplies for the Arduino and the GM862. I tried to connect the Rx/Tx lines to two digital pins and use the NewSoftSerial library. This library enables a second serial port on the Arduino besides the hardware serial port. Unfortunately it wasn’t reliable enough. Sending to the module seems to work well, receiving sometimes did not. I tried it with different baud rates and different Arduinos, 8 MHz and 16 MHz, but that didn’t help. Maybe I did something wrong, but I couldn’t figure it out.
So I switched to my brand new Arduino Mega. I just connected Rx/Tx to one of the hardware serial ports and it worked immediatly.
The following features are implemented:
- Starting and stopping the module
- Initialization
- Sending of SMS
- Requesting GPS position and parsing the result
- Opening a socket, writing and reading (used to talk HTTP) over GPRS
The software is an really early stage. I focussed most on functionality and less on performance or compact code. The following todos are still open:
- Make debugging output configurable
- Use of PROGMEM to reduce RAM usage
- More compact structure for AT commands
- Parse more responses of AT commands. Some are simply issued, without looking at the response
Nevertheless, here is a small snippet, that shows features that are already working. To get it working, you have to replace XXXX with your PIN. For GPRS you have to dig into the module code and adapt the GPRS settings.
/* * GM862-GPS testing sketch * used with Arduino Mega * http://tinkerlog.com */ #include "GM862.h" int onPin = 22; // pin to toggle the modem's on/off char PIN[5] = "XXXX"; // replace this with your PIN Position position; // stores the GPS position GM862 modem(&Serial3, onPin, PIN); // modem is connected to Serial3 char cmd; // command read from terminal void setup() { delay(10000); Serial.begin(19200); Serial.println("GM862 monitor"); modem.switchOn(); // switch the modem on delay(4000); // wait for the modem to boot modem.init(); // initialize the GM862 modem.version(); // request modem version info while (!modem.isRegistered()) { delay(1000); modem.checkNetwork(); // check the network availability } Serial.println("---------------------"); Serial.println("ready"); } void requestHTTP() { char buf[100]; byte i = 0; modem.initGPRS(); // setup of GPRS context modem.enableGPRS(); // switch GPRS on modem.openHTTP("search.twitter.com"); // open a socket Serial.println("sending request ..."); modem.send("GET /search.atom?q=gm862 HTTP/1.1rn"); // search twitter for gm862 modem.send("HOST: search.twitter.com portrn"); // write on the socket modem.send("rn"); Serial.println("receiving ..."); while (i++ 0) { // we received something Serial.print("buf:"); Serial.println(buf); i--; // reset the timeout } } Serial.println("done"); modem.disableGPRS(); // switch GPRS off } void loop() { if (Serial.available()) { cmd = Serial.read(); switch (cmd) { case 'o': modem.switchOff(); // switch the modem off break; case 's': // send a SMS. Replace with your number modem.sendSMS("6245", "your@email.com hello from arduino"); break; case 'w': modem.warmStartGPS(); // issue a GPS warmstart break; case 'p': position = modem.requestGPS(); // request a GPS position if (position.fix == 0) { // GPS position is not fixed Serial.println("no fix"); } else { // print lat, lon, alt Serial.print("GPS position: "); Serial.print(position.lat_deg); Serial.print("."); Serial.print(position.lat_min); Serial.print(", "); Serial.print(position.lon_deg); Serial.print("."); Serial.print(position.lon_min); Serial.print(", "); Serial.println(position.alt); } break; case 'h': requestHTTP(); // do a sample HTTP request break; default: Serial.println("command not recognized"); } } }
Log
Here is a log, that I recorded within the Arduino IDE. You can see, how
- the modem gets switched on
- the modem gets initialized
- the version info is requested
- it waits until the network is reachable
- a GPS position is requested
- a SMS gets send
- how a HTTP GET is issued over GPRS, it searches for gm862 on twitter
GM862 monitor switching on done initializing modem ... AT ->ok AT+IPR=19200 ->ok AT+CMEE=2 ->ok AT+CPIN=XXXX ->ok done version info ... AT+GMI ->buf: AT+GMI Telit OK AT+GMM ->buf: AT+GMM GM862-GPS OK AT+GMR ->buf: AT+GMR 07.02.403 OK AT+CSQ ->buf: AT+CSQ +CSQ: 0,0 OK done checking network ... AT+CREG? ->buf: AT+CREG? +CREG: 0,2 OK done checking network ... AT+CREG? ->buf: AT+CREG? +CREG: 0,2 OK done checking network ... AT+CREG? ->buf: AT+CREG? +CREG: 0,1 OK done --------------------- ready requesting GPS position ... AT$GPSACP ->buf: AT$GPSACP $GPSACP: 110621.999,5333.9477N,00954.8735E,1.4,66.3,3,22.21,0.10,0.05,150509,08 OK 3 GPS position: 53.565794, 9.914568, 66 sending SMS ... AT+CMGF=1 ->ok AT+CMGS="6245" ->not ok: AT+CMGS="6245" > your@email.com hello from arduino done initializing GPRS ... AT+CGDCONT=1,"IP","internet","0.0.0.0",0,0 ->buf: +CMGS: 35 OK AT+CGDCONT=1,"IP","internet","0.0.0.0",0,0 OK AT#USERID="" ->buf: AT#USERID="" OK AT#PASSW="" ->buf: AT#PASSW="" OK done switching GPRS on ... AT#GPRS=1 ->buf: AT#GPRS=1 +IP: 10.37.146.251 OK done opening socket ... AT#SKTD=0,80,"search.twitter.com",0,0 ->buf: AT#SKTD=0,80,"search.twitter.com",0,0 buf: buf: CONNECT sending request ... receiving ... buf:HTTP/1.1 200 OK Date: Fri, 15 May 2009 11:07:19 GMT Server: hi Status: 200 OK Cache-Control: ma buf:x-age=20, must-revalidate, max-age=1800 Content-Type: application/atom+xml; charset=utf-8 X-Serve buf:d-By: searchweb005.twitter.com Expires: Fri, 15 May 2009 11:37:18 GMT Content-Length: 4757 Vary: buf: Accept-Encoding X-Varnish: 218274860 Age: 0 Via: 1.1 varnish X-Cache-Svr: searchweb005.twitter buf:.com X-Cache: MISS Connection: close <?xml version="1.0" encoding="UTF-8"?> [...] </author> </entry> </feed> NO CARRIER done switching GPRS off ... AT#GPRS=0 ->buf: AT#GPRS=0 OK done
Outlook
Besides some software todos on the list, two things are still bugging me. One is the need of an Arduino Mega because of the hardware serial port. I will try the new version of NewSoftSerial, as soon as it is released. The other thing is the need of two power sources. But that could be solved with the Arduino Mini pro, when the software serial issue is fixed.
Everything else worked well. Now I only need a problem that could be solved with this ;) .
Links and Downloads
- Source code: arduino-gm862.zip
- Interfacing an AVR controller to a GPS Mobile Phone
- GM862 breakout board from Sparkfun
- GM862 specs at Telit.
- roundsolutions, distributor for GM862 modules.
As noted above, are the sketch, GM826.cpp and GM862.h in the same directory?
LikeLike
Nevermind, it was some random bug, the code compiled. Thanks again!
LikeLike
I desperately need some help with my project. I have a Telit GSM/GPS unit and need to interface it with a PIC board. I have code written in basic and need the Telit module to work with the PIC board I have. I would appreciate any help given.
Kind regards,
James Hood.
LikeLike
Can I do this project with a arduino atmega328?
LikeLike
Great project thanks.
By the way I use the lithium backpack from Liquidware (not connected to me). Their backpacks step up 3.3v to 5v and provide both 3.3v and 5v supply pins. Can be recharged from usb or ano source.
Finally, if you would like to use Visual Studio to program arduino pick up a copy of Visual Micro. It’s free and the intellisense works well with your code.
LikeLike
Hello,
do you know with this “snipped” what is the maximum frequency for sending the gps position through Http? I mean in a second
how many times I can read gps position and
make http request roughly?
Kind regards
Biagio
LikeLike
I would guess about one gps request + http post per second.
LikeLike
Great article! I’m looking for a pre-paid phone to use the sim out of. Do you have any idea what service providers out there support the “mobile web” and SMS at a decent price?
I have a semi-permanent idea and need some service that won’t break the bank.
LikeLike
Hi, everyone, first of all great post about arduino and tellit, but I’ve a problem!
How can I use my telit and arduino in order to have a port allways opened to the internet waiting for connections?
I’ve tried to do this, using the socket listen AT command, but seems like I can’t use it the right way…
The first try out was:
Send the following to the modem:
AT#FRWL=1,[my-ip],255.255.0.0 -> Add my ip to accepted list
AT#SL=2,1,1001 -> Open the socket for listen connections…
It works fine that way, but when I change my ip, the ip is not authorised and the connection is rejected…
So… I read a little bit of the AT commands reference guide, and I tried this:
Send the following to the modem:
AT#SCFG=2,0,0,5000 -> Basic Socket Config (OK)
AT#SCFGEXT=2,0,0,0,1,0 -> Extended config, supposedly auto-accept connections mode… (ERROR)
AT#SL=2,1,1001 -> Open the socket for listen connections…
I don’t know why an error happens, when I try to configure the socket to auto-accept all connections… What should I do? What am I missing?
Thanks!
Help please!
LikeLike
Having the same problem with the auto answer. I’ll post any fixes if I find some.
LikeLike
Hi all.
First, let me thank you Alex for providing the source code. I think you should post this project in arduino.cc. I came across your blog only after searching lots of pages with incomplete info.
My goal is to connect my siemens S55 to arduino and send SMS at pre-set triggers, using AT gsm comand .
Tryed to use the Fbus, on nokia 3310, but it was really anoying to make it to work.
LikeLike
Hi Alex,
Thanks for tall of the good work with the 862, do you have any plans to update your parsing routine, to add minus characters to the gps coordinates when there is a south or west to deal with ?
LikeLike
Hi Alex,
This is really great stuff. How easy is it to receive SMS messages?
LikeLike
Alex, thanks for the code it helped in my project with “Twitter Tracker”.
http://hackaday.com/2010/09/08/location-tracking-with-twitter-and-google-maps/
http://ohararp.com/wp/?p=119
LikeLike
Hi Alex,
Thank you for the great project. I want to make a gps tracker for my dog. I would highly appreciate if you could kindly let me know how to change the SMS feature to GPRS feature. I would like the tracking information send through internet rather then the SMS.
thank you in advance for your time and help
cheers
LikeLike
Hi,
I found a shield for the GM862, it uses a virtual serial port to communicate to the modem. I think the store is from Chile.
here is the link http://www.olimex.cl/product_info.php?products_id=733
[img]http://www.olimex.cl/images/MCI-TDD-00733.JPG[/img]
LikeLike
Hi Alex,
I am contacting you in regards to a couple of GM 862 modules I have. I have to consrtuct a circuit using one of the modules in conjunction with a zigbee mesh network. I also have a PICAXE 40 pin development board, a programming interface and a PIC 16F877A processor. I desperately need some technical advice for my project and I am very willing to pay for this and purchase parts. I eagerly await your reply.
Kind regards.
LikeLike
Hi Jim,
I’m sorry but I have no experience in PIC programming.
Cheers,
Alex
LikeLike
Hi Alex,
I am trying a similar setup. Arduino and Telit gm862. I can send commands from Arduino to Telit (like send sms) and it’s working. But I can’t get anything back. For example, if I send “AT” from Arduino to Telit, I want to read the “OK” on Arduino. Well, this doesn’t work, i don’t get anything back and I tried *everything*! Can you help a little, please?
LikeLike
Hi Andrew,
double check if you have connected the RX pin correctly and if you have the pull-up resistor in place.
Cheers,
Alex
LikeLike
Thank you for answering, Alex. Yes, I noticed the RX is the problem, if I disconnect it, I can still send AT commands from Arduino to Telit.
Do I need to use a pull-up resistor? I just hooked a wire between :-s. Also, I power the Telit with 9V external source and Arduino with the USB cable.
Thank you so much, Alex, I really appreciate any help you can give me.
LikeLike
hi, is there an update to your code because the twitter had transition from Basic Auth to OAuth.
LikeLike
No, sorry. But take a look at supertweet. I used them lately and it worked fine.
LikeLike
Hi Alex and people,
I’m trying to establish connection between the Telit module and a server.
I’m using the same commands as the GPRS part (Initializing GPRS, swtching on the GPRS,..) and averything is fine.
But when I try to open the socket sending the command “AT#SKTD”, I keep waiting the answer and don’t get anything. When I send another command (AT for example), I got the answer “+CME ERROR: timeout in opening socket”.
What should I do? Is there anything missing? Or the time to open the socket is very large?
Thanks in advance,
Cheers,
Marcelo
LikeLike
I find this really interesting since Ive been doing some research to do a DIY GPS Tracking system for my car. Does this works without the need of a Cellphone Career? Is there a posibility of mapping the coordinates you get into Google maps/earth/latitude?
Im really interested in this project (even though im not too hardware-savvy
LikeLike
You always need a carrier. Using coordinates with Google Maps is done here: https://tinkerlog.com/2007/07/28/using-google-maps-with-a-mobile-gps-tracker/
LikeLike
Hey. Thanks for the writeup.
Is there a reason you didn’t use a simpler resistor divider to transition 3.3 to 2.8? Something like R1=100k R2=18k?
This might be explained on the Trackbox2 page but I cannot read German.
Thanks!
LikeLike
Hm, you won’t get 2.8V out of a voltage divider with 100k and 18k.
I just looked at what resistors I had lying around and what would fit.
LikeLike
Alex, what are you using for antennas?
Thanks!
Jason
LikeLike
Hi guys,
I’m looking at this with the intention of using it to track a high altitude balloon. Got an arduino mega board and was wondering if anyone could help me out by recommending the necessary hardware for this type of application. I’m somewhat amature when it comes to electronics!
Cheers
LikeLike
@Jason, I bought the module with all needed antennas from roundsolutions.de. They told me, what to use.
@Ian, I would suggest to look at sparkfun. They have great stuff and very helpful forum.
LikeLike
i’m just researching and trying to sort out some things for a mobile project…
first of all even though i didn’t put my hands on yet i think this is an awesome tutorial alex – thanks a lot for your efforts.
as my project definitely has to be mobile and of course as small as possible the arduino mega is not really an option for me so i am wondering if anybody made this circuit working with the arduino pro mini 3.3V (http://www.sparkfun.com/products/9220)
thanks jona
LikeLike
HELP NEEDED:::::::
we are making a project in which we have to connect a gps module and gsm module to an arduino microcontroller.
the co-ordinates would be extracted from gps and sent to a server through sms. we dont have much knowledge about it. plz help in any way you can.
The telit gm862 is not available here around.
Please suggest a economical alternative.
LikeLike
I dont have much funds for a similar project….can u suggest a way out
LikeLike
Hi, this is a great project. I wander where is the modem function implementation.
Tahnks
LikeLike
Hi,
I developed a library (is a modified version of the library of HWKitchen) for a GSM shield based on a SIM900 module. I think that you can use this library with Telit also.
For download the library visit http://www.open-electronics.org/arduino-gsm-shield/
LikeLike
Hello Alex,
Thanks for your work on the GM862. I have it working with an Arduino Mega, but I, like you, would like to use NewSoftSerial so that I can use a Duemilanove instead. But I need your guidance.
I included NewSoftSerial.h, defined “Telit_Serial” on pins 2 and 3 and changed the GM862 modem(&Telit_Serial, onPin, PIN) line … but then I get a compiler error stating in part
Test_Telit_GM862:15: error: no matching function for call to ‘GM862::GM862(NewSoftSerial*, int&, char [5])’
What do I need to do to resolve this? Obviously I am a newbie
Thanks,
Ross
LikeLike
Never mind Alex. I moved to a Mega and all works with the hardware uarts instead.
Cheers,
Ross
LikeLike
hey!
how workable is the hardware and software on a duemilanove?
LikeLike
Vishal,
I don’t know if you are asking me or Alex.
If me … well the NewSoftSerial was not reliable enough when using Alex’s code with all of my other requirements in my design so I had to change to the Mega to be able to use 2 hardware UARTs. So the answer for you can only be answered by you. If you have enough resources, maybe it will be OK.
Best,
Ross
LikeLike
Hey Alex! Thank you so much for this wonderful post! It’s been almost a year since I first discovered it and finally these days I managed to put all things together.
Unfortunately I cannot get it to work! The status LED doesn’t light up at all and the serial in Arduino says AT not ok and it’s all not ok from there.
I have to admit I am new in EE so I would like to ask you a few questions about your schematics that will hopefully let me complete this. I hope you can answer.
1. May I ask you what is the difference between V+ and VCC (I am guessing V+ stands for 5V/arduino while VCC for 3.8V/battery but I just need to be sure).
2. Is GRD from arduino and GND from the battery connected?
3. How are the pins of the transistor supposed to be connected? Is the collector connected to the GRD or is it the other way around? I am guessing pin22 is connected in the middle.
I searched the net for answers to these questions before posting here, but no luck! :(
Thank you once again!
Cristian
LikeLike
I actually saw you gave an answer to my first question in a comment you posted.
I changed some connections and it still doesn’t work!
I power my gm862 from a 3.7V LiPo battery, 1000mAh.
And this is what it says:
GM862 monitor
switching on
done
initializing modem …
AT
->not ok: AT
AT+IPR=19200
->not ok: AT+IPR=19200
AT+CMEE=2
->not ok: AT+CMEE=2
AT+CPIN=0000
->not ok: AT+CPIN=0000
done
version info …
LikeLike
If the LED doesn’t light up, then the module is not switched on. Try to switch it on by hand. Take a look at the datasheet on how to do that.
Cheers,
Alex
LikeLike
Thank you, Alex!
I’ll see what I can do! In the meantime..
Converting an Arduino to 3.3V
http://www.ladyada.net/library/arduino/3v3_arduino.html
LikeLike
Greetings! you see, I’m working with an GM862 like you (but with an LPC2148 instead of an Arduino) and when I initialized the GSM module and trying to connect to a network I always obtain:
->buf: AT+CREG?
+CREG: 0,2
Always get the “0,2”. Now I was wondering, do you have any idea why would this be happening and… another detail, when I bought the module I forgot to buy the antenna, is it absolutely necessary?
Thanks
LikeLike
Hi Abelardo,
for the 0,2 response, please check the datasheet. And yes, you need an antenna for GSM and GPS.
LikeLike
Thanks Alex,
I’ve alredy check the datasheet, the 0,2 is a “trying to connect to network” just that it gets stuck on there.
I guess the problem is the lack of antenna, right?
LikeLike
Yes, I think so.
LikeLike
Hi Alex,
I’ve been searching for a way to manually switch the modem on, but I can not find any.
I have both “Telit GM862 Product Description” and “GM862 Family Hardware User Guide”. None of them help. I even searched to other things related like the Libellium GPRS shield.
Could you please tell me how I can switch it on by hand?
For now I just want to see that LED light up :)
Thank you so much!
LikeLike
theres a bug on you’re code
on this function:
void GM862::parseDegrees(char *str, int *degree, long *minutes) {
char buf[6];
uint8_t c = 0;
uint8_t i = 0;
char *tmp_str;
char minus = ‘-‘;
tmp_str = str;
while ((c = *tmp_str++) != ‘.’) i++;
strlcpy(buf, str, i-1);
*degree = atoi(buf);
tmp_str -= 3;
i = 0;
while (true) {
c = *tmp_str++;
if ((c == ”) || (i == 5)) {
break;
}
else if (c != ‘.’) {
buf[i++] = c;
}
}
buf[i] = 0;
*minutes = atol(buf);
*minutes *= 16667;
*minutes /= 1000;
}
what happens if a 00833.9472W string appears on the gps string? the value should be negative and u don’t check that anywhere…
LikeLike