Interfacing Arduino to USB GPRS modem



Cheap GPRS modem from Dealextreme

USB GPRS modem
by Oleg via Circuits@Home

Some time ago I started writing about connecting Arduino to cellular network. Using standard GSM AT commands, a program running on Arduino can place and take calls, send and receive SMS, shoot pictures, access the Internet while monitoring phone’s battery level, signal strength and connection status. For many of these tasks any old phone works quite well, however, there are times when a specialized piece of hardware is desired. Today I’m going to talk about one such piece of hardware which can be connected to Arduino board using USB Host Shield.

USB Tri-band GPRS Modem from DealExtreme is just an ordinary GSM cell phone minus keyboard, display, battery, and built-in microphone/speaker. What is left makes inexpensive (~$25), lightweight (25 grams) and compact (see title picture) GSM/GPRS module to use in DIY projects. It supports a standard subset of GSM commands as well as some proprietary ones. The modem is built around BenQ M23 GSM/GPRS Wireless module and uses Prolific PL-2303 USB-to-serial converter. As explained on this page, the PL-2303 in the modem uses non-default USB PID; make sure to grab the latest version of my library, which transparently supports both PIDs.
To explore the functionality of this device I wrote a simple program which is based on Xbee terminal. The program initializes the PL-2303 and waits for user input passing keystrokes to the modem and displaying replies to the screen. Let’s run it and see what this little modem is capable of.

The hardware arrangement is shown on title picture. During normal operation the system can be powered from USB; depending on your Arduino board you may need to disconnect the modem during programming. All interactions occur via terminal emulator running on a PC – I use putty on Windows and minicom on Linux. Using serial monitor built into Arduino IDE is not recommended. The modem needs activated SIM card to function, I use prepaid SIM from T-Mobile and also successfully used it with AT&T.
If everything is connected correctly sketch will output the following:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
Start
PL Init
Addr:1
NC:1
0000: 09 02 27 00 01 01 00 A0 FA 09 04 00 00 03 FF 00
0010: 00 00 07 05 81 03 0A 00 01 07 05 02 02 40 00 00
0020: 07 05 83 02 40 00 00 Conf.Val: 01
Iface Num: 00
Alt.Set: 00
Endpoint descriptor:
Length:         07
Type:           05
Address:        81
Attributes:     03
MaxPktSize:     000A
Poll Intrv:     01
Conf.Val: 01
Iface Num: 00
Alt.Set: 00
Endpoint descriptor:
Length:         07
Type:           05
Address:        02
Attributes:     02
MaxPktSize:     0040
Poll Intrv:     00
Conf.Val: 01
Iface Num: 00
Alt.Set: 00
Endpoint descriptor:
Length:         07
Type:           05
Address:        83
Attributes:     02
MaxPktSize:     0040
Poll Intrv:     00
Conf:1
PL configured

The last message (line 38) shows that PL-2303 has been recognized and successfully configured. Type at on the keyboard and press Enter. If you see OK on the next line the modem is alive and answering.
...
Conf:1
PL configured
at
OK
Now let’s see if a modem is connected to a network. Type at+creg? and press Enter:
at+creg?
+CREG: 0, 1
 
OK
The second number in reply indicates the state of registration. My output (1) means the modem is happily registered with home network. Other numbers you may see are “0″ – no service, “2″ – searching for operator, “3″ – registration denied.
If modem is registered, it is possible to determine the cell operator:
at+cops?
+COPS: 0,0,"T-Mobile 260"
 
OK
When modem is online, we can do something useful. I’ve already sent several text messages to this number, let’s take a look at them by using +CMGL command:
at+cmgl=1 +CMGL: 1,1,,50 07912160130320F8040B919127163673F500001101814190044A23F3F61C6496BFDBA0F3FB7D6697152D503BACAFCBDF76C0B91D4EB35DE3771B +CMGL: 2,1,,57 07912160130320F5040B919127163673F500001101814124244A2B66F9BB0D3ABFDF677619447F83885850FB4D2EB7152D503BACAFCBDF76C0B91D4EB35DE3771B +CMGL: 3,1,,53 07912160130320F8000B919127163673F500001101817184554A26F4F29C0E9A81CCF2771B747EBFCFECB2A2056A87F575F9DB0E38B7C369B66BFC6E03 +CMGL: 4,1,,53 07912160130320F8040B919127163673F500001101817145154A26F4F29C0EA281CCF2771B747EBFCFECB2A2056A87F575F9DB0E38B7C369B66BFC6E03   OK
What you see is output in so-called PDU format. Many GSM devices have this format turned on at power-up. It is OK for computers but not so easy for humans. Luckily for us, this modem also supports SMS text mode, which can be turned on using +CMGF command:
at+cmgf=1
OK
at+cmgl="ALL"
+CMGL: 1,"REC READ","19725555555",,"11/10/18,14:09:40-36",145,35
sms from google- m...v@gmail.com
+CMGL: 2,"REC READ","19725555555",,"11/10/18,14:42:42-36",145,43
from google to DX modem - m...v@gmail.com
+CMGL: 3,"REC READ","19725555555",,"11/10/18,17:48:55-36",145,38
test 3 from google- m...v@gmail.com
+CMGL: 4,"REC READ","19725555555",,"11/10/18,17:54:51-36",145,38
test 4 from google - m...v@gmail.com
 
Sending messages is also easy. It is done using +CMGS command. The command takes recipient’s phone number as a parameter and outputs a prompt where a message can be entered. End of message is indicated by pressing Ctrl+z, make sure your terminal program passes this code unchanged to the modem (putty works correctly here). Here is an example:

at+cmgs="19725555555"
> test from T-Mobile to google
> +CMGS: 34
OK


There is much more that can be done with this little modem (or to any GSM phone for that matter). Some things, like placing or receiving calls, are pretty easy to do, while others, like accessing internet, would require some extra programming. In coming weeks I’m planning to develop code to support a cell phone in unattended mode; in the mean time, try to talk to your phone via terminal and let me know if you have any issues.