GM862 with BASIC Stamp 2: Here's my code

Hey all-

I wrote some code to get the GM862 working with a BS2 back in December 2006 and just came across it today while poking through some old files. Hopefully someone, somewhere, will benefit from this, so here it is :slight_smile:

Joe

' =========================================================================
'
'   File....... GM862.BS2
'   Purpose.... Communicate with the GM862 Cellular Quad Band Module
'   Author..... Joe Grand, Grand Idea Studio, Inc. [www.grandideastudio.com]
'
' {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================

' -----[ Program Description ]---------------------------------------------
'
' Written in December 2006, finally got around to posting January 2009
'
' The GM862 was mounted on the Spark Fun Electronics GM862 Evaluation Board
' (#CEL-00477, www.sparkfun.com/commerce/product_info.php?products_id=477). 
' Pin connections from BS2 to the GM862 are straight-forward, but the TX line 
' from the BS2 needs to be level-shifted down to 2.8V for proper interfacing 
' to the GM862. Sorry for the lame ASCII art.
'
'                               5V
'                                |
'                                > 
'                                > 4.7k
'                                >
'                                |---------------< From BS2 GPRS_TX (pin 12)
'                      10k   b |/ e 
'  To GM862 PWRCTL <---^^^-----|   2N2222
'       (2.8V)                 |\ c
'                                |
'                                |
'                                |---------------< To GM862 TXD line
' 
' 

' -----[ I/O Definitions ]-------------------------------------------------

GPRS_RX		PIN  13
GPRS_TX	     PIN  12
GPRS_On		PIN	11
'GPRS_Reset		PIN	10

' -----[ Constants ]-------------------------------------------------------

#SELECT $STAMP
  #CASE BS2, BS2E, BS2PE
    T1200       CON     813
    T2400       CON     396
    T4800       CON     188
    T9600       CON     84
    T19K2       CON     32
    T38K4       CON     6
  #CASE BS2SX, BS2P
    T1200       CON     2063
    T2400       CON     1021
    T4800       CON     500
    T9600       CON     240
    T19K2       CON     110
    T38K4       CON     45
#ENDSELECT

SevenBit    CON     	$2000
Inverted    CON     	$4000
Open        CON     	$8000

GPRS_Baud	  CON		T9600

' -----[ Initialization ]--------------------------------------------------

Init:
  DEBUG CLS, "Initializing system...", CR
  GOSUB GM862_Powerup	' initialize the GM862-QUAD-PY GSM/GPRS module		

' -----[ Program Code ]----------------------------------------------------

Main:
	GOSUB GM862_Initialize
	
	'   send SMS message to owner
SMS_Prep:
 	 PAUSE 500
 	 DEBUG "Preparing to send SMS message...", CR
 	 SEROUT GPRS_TX, GPRS_Baud, ["AT+CMGF=1", CR]
 	 SERIN GPRS_RX, GPRS_Baud, 3000, SMS_Prep, [WAIT("OK")]

SMS:
	 PAUSE 500
 	 DEBUG "Sending SMS message...", CR
 	 SEROUT GPRS_TX, GPRS_Baud, ["AT+CMGS=", $22, "12223334444", $22, CR] ' phone number 1+NPA+pre+suff
 	 SERIN GPRS_RX, GPRS_Baud, 3000, SMS, [WAIT(">")]

SMS2:
 	 PAUSE 500
 	 SEROUT GPRS_TX, GPRS_Baud, ["This is a text message!", $1A]
 	 SERIN GPRS_RX, GPRS_Baud, 5000, SMS2, [WAIT("OK")]

Voice_Prep:
     PAUSE 1000
     DEBUG "Preparing for voice call...", CR
  	SEROUT GPRS_TX, GPRS_Baud, ["AT+FCLASS=8", CR]
  	SERIN GPRS_RX, GPRS_Baud, 3000, Voice_Prep, [WAIT("OK")]

Mic: ' set up microphone input settings
     PAUSE 500
     	SEROUT GPRS_TX, GPRS_Baud, ["AT#CAP=2", CR]
  	SERIN GPRS_RX, GPRS_Baud, 3000, Mic, [WAIT("OK")]

Voice:
  	PAUSE 500
  	DEBUG "Dialing...", CR
  	SEROUT GPRS_TX, GPRS_Baud, ["ATD12223334444", CR] ' phone number 1+NPA+pre+suff
  	PAUSE 15000  ' wait 15 seconds for the call to go through and someone to answer

' Send audio and do stuff here

  ' hang up phone
Hang_up:
     PAUSE 500
     DEBUG "Hanging up phone...", CR
  	SEROUT GPRS_TX, GPRS_Baud, ["ATH", CR]
  	SERIN GPRS_RX, GPRS_Baud, 3000, Hang_up, [WAIT("OK")]

Phone_Done:
	GOSUB GM862_Powerdown	' turn off module now that the phone call is done
  
  DEBUG "System done!", CR
  END


' -----[ Subroutines ]-----------------------------------------------------

GM862_Initialize:
  DEBUG "Autobauding...", CR
  SEROUT GPRS_TX, GPRS_Baud, ["AT", CR]
  SERIN GPRS_RX, GPRS_Baud, 3000, No_GPRS_Response, [WAIT("OK")]

Baud:
  PAUSE 500
  DEBUG "Setting baud rate to 9600, 8N1...", CR
  SEROUT GPRS_TX, GPRS_Baud, ["AT+IPR=9600", CR]
  SERIN GPRS_RX, GPRS_Baud, 3000, Baud, [WAIT("OK")]

Err:
  PAUSE 500
  DEBUG "Enabling extended error result codes...", CR
  SEROUT GPRS_TX, GPRS_Baud, ["AT+CMEE=1", CR]
  SERIN GPRS_RX, GPRS_Baud, 3000, Err, [WAIT("OK")]

Band:
  PAUSE 500
  DEBUG "Setting network to N. America (GSM 900MHz/PCS 1900Mhz)...", CR
  SEROUT GPRS_TX, GPRS_Baud, ["AT#BND=1", CR]
  SERIN GPRS_RX, GPRS_Baud, 3000, Band, [WAIT("OK")]

Sim:
  PAUSE 500
  DEBUG "Querying SIM presence/status...", CR
  SEROUT GPRS_TX, GPRS_Baud, ["AT+CPIN", CR]
  SERIN GPRS_RX, GPRS_Baud, 3000, Sim, [WAIT("READY")]

Net:
  PAUSE 500
  DEBUG "Checking network registration...", CR
  SEROUT GPRS_TX, GPRS_Baud, ["AT+CREG", CR]
  SERIN GPRS_RX, GPRS_Baud, 3000, Net, [WAIT("0,5")]

  RETURN

' ----------------------------------------------------

GM862_Powerup:
  INPUT GPRS_On
  PAUSE 500
  LOW GPRS_On
  PAUSE 2000
  INPUT GPRS_On
  PAUSE 500
  RETURN

' ----------------------------------------------------

GM862_Powerdown:
  LOW GPRS_On
  PAUSE 2000
  INPUT GPRS_On
  PAUSE 500
  RETURN

' ----------------------------------------------------

No_GPRS_Response:
  DEBUG "No response: GM862", CR       ' ruh-roh, Shaggy
  GOTO Phone_Done

' ----------------------------------------------------

End of transmission.

You are my hero… Thank you for this code!!!

I owe u my girlfriend for one night…ur GOD send for me!!!

What do you mean by GPRS_On and the subroutine

GM862_Powerup:

INPUT GPRS_On

PAUSE 500

LOW GPRS_On

PAUSE 2000

INPUT GPRS_On

PAUSE 500

RETURN

what pin on the Eval Board do you connect to the basic stamp? Thank you

ringmaster:
I owe u my girlfriend for one night…

She would want such?

stevech:

ringmaster:
I owe u my girlfriend for one night…

She would want such?

how we make a gm862 a RX??? i mean could we send a sms to the gm862 to make basic stamp be active??? if yes??? how???

best regrads