PICAXE to SMS

lanternfish

Senior Member
As discussed in a previous thread, here is a description using AT commands to communicate with a Nokia 6100 cellphone.

The Nokia 6100 has two serial protocol buses available for interfacing - M-Bus and F-Bus. M-Bus is a bi-directional bus having a combined Rx/TX line. F-Bus, on the other hand, has seperate Rx and Tx lines. This is the bus I used.

I was able to test and use the following AT commands:

AT+CGMM Request Model Identification ; Will reply with phone model ident. In this case "Nokia 6100"

AT+CSQ Signal Quality ; Will reply with "+CSQ: rssi,ber" where rssi = 0 to 31 or 99 (usually in the range 2 to 30) & ber = 0 - 7 or 99

AT+CMGF=1 Set to text message format ; Will reply with "OK" (=0 sets to PDU mode)

Commands always start with AT (ATtention) and end with <CR>

Responses start and end with <CR><LF>. These have been ignored.

The original program made use of the ON ... GOSUB command for the various transmit, receive and error reporting routines. While this is compact, it does make the program flow a little difficult to follow. I have simplified the flow by rewriting the code in the following, more linear mode.

The following constants and variables are used:

Code:
'Directives
#PICAXE 28X1
#SIMSPEED 100

'Constants
SYMBOL txpin = 0			; select serial output pin to suit
SYMBOL rxpin = 0			; select serial input pin to suit
SYMBOL gsmbaud = T4800_8		; select baudrate to suit phone used. I used T4800_8
SYMBOL timeout = 100			; Serial in timeout period (ms)
SYMBOL errled = 7			; Red error led
SYMBOL goled = 6			; Green system good led

'Variables
SYMBOL genreg0 = b0        		; General purpose register 0
SYMBOL genreg1 = b1 			; General purpose register 1
SYMBOL genreg2 = b2			; General purpose register 2
SYMBOL genreg3 = b3			; General purpose register 3

SYMBOL errflag = b4			; Error flag

SYMBOL testdata = 145		; Test data
To check if the phone is on and connected the following is used:

Code:
'Main Program
Initialise_Main:

	SETFREQ m8
	errflag = 0							; Clear error flag
	HIGH txpin							; Puts serial out pin into idle condition
	LOW errled							; Error LED off

Model_Ident: 'This checks if phone is connected/on

	SEROUT txpin,gsmbaud,("AT+CGMM",10)				; Request Model Identification
	
	SERIN [timeout,Model_Error_1],rxpin,gsmbaud,("Nokia 6100"); Should receive "Nokia 6100"

	errflag = 0								; Clear error flag
	GOTO Signal_Quality
	
Model_Error_1:

	INC errflag
	IF errflag < 2 THEN GOTO Model_Ident

Model_Error_2:

	HIGH errled							; Turns Red (Error) LED on
	PAUSE 10000						; Wait 1 second
	LOW errled							; Turns Red (Error) LED off
	PAUSE 10000						; Wait 1 second
	GOTO Model_Error_2
Then a test of signal quality is done. No or low signal level causes a retest before signaling an error. If all is good then the program initialises Text mode:

Code:
Text_Mode:

	SEROUT txpin,gsmbaud,("AT+CMGF=1",10)					; Set to text (not PDU) message format

	SERIN [timeout,Mode_Error_1],rxpin,gsmbaud,("OK")			; Will receive "OK"

	errflag = 0										; Clear error flag
	GOTO Send_System_OK

Mode_Error_1:

	INC errflag
	IF errflag < 2 THEN GOTO Text_Mode

Mode_Error_2:

	HIGH errled										; Turns Red (Error) LED on
	PAUSE 2500										; Wait 1/4 second
	LOW errled										; Turns Red (Error) LED off
	PAUSE 2500										; Wait 1/4 second
	GOTO Mode_Error_2
If all is good then the system sends a text message.

Code:
Send_System_OK:	' Send message directly
	
	LOW errled										; Turn off error LED
	HIGH goled										; Turn on System good LED

	SEROUT txpin,gsmbaud,("AT+CMGS=",34,"+33146290800",34,10,"System Active",26)

	SERIN [timeout,Transmit_Error_1],rxpin,gsmbaud,("OK")			; Will receive "OK"

	errflag = 0										; Clear error flag
	GOTO Send_Data

Transmit_Error_1:

	INC errflag
	IF errflag < 2 THEN GOTO Send_System_OK

Transmit_Error_2:

	HIGH errled										; Turns Red (Error) LED on
	PAUSE 1250										; Wait 1/8 second
	LOW errled										; Turns Red (Error) LED off
	PAUSE 1250										; Wait 1/8 second
	GOTO Transmit_Error_2
To transmit any data gathered the receiving phone number has to be included in the GMSS string. In this case "+33146290800" ( a dud number). The number is in international format.

As the text string can only hold ASCII characters, the # is put before the variable storing the data. This outputs the variable in ASCII format. Refer to the manual for more info.

Code:
Send_Data:	' Send message directly
	
	LOW errled										; Turn off error LED
	HIGH goled										; Turn on System good LED

	SEROUT txpin,gsmbaud,("AT+CMGS=",34,"+33146290800",34,10,"Data = ",#testdata,26)

	SERIN [timeout,Send_Data_Error_1],rxpin,gsmbaud,("OK")		; Will receive "OK"

	errflag = 0										; Clear error flag
	GOTO Endless									; End of program
	
Send_Data_Error_1:

	INC errflag
	IF errflag < 2 THEN GOTO Send_Data_Error_1

Send_Data_Error_2:

	HIGH errled										; Turns Red (Error) LED on
	PAUSE 625										; Wait 1/8 second
	LOW errled										; Turns Red (Error) LED off
	PAUSE 625										; Wait 1/8 second
	GOTO Send_Data_Error_2

Endless:

	GOTO Endless
I did have some trouble with receiving replies from the phone and had to make small adjustments to the timeout variable in each (sub)routine. This was probably due to the time taken for the phone to process the AT commands, especially sending the text message.

I hope this goes someway to answering vttom's query in the original post. And MPep's enquiry.

Cheers
 
Last edited:

joely87

Member
SMS with AT Commands

Hi Lanternfish,

This is the day i have been waiting for!! :) I have been searching the forum and googling for days and finally a successful picaxe to nokia program...

I have not tried any of the code as i am awaiting the arrival of a Nokia 6210. Could you please clarify, How did you connect your nokia to the picaxe? I was thinking i would have to buy the $40 DLR-3P Data Cable but if you have a better cheaper option i would be interested. I have seen the self made version but it looks like more than $40 work...

from your other post..
"AT is definitely the way to go if the cell phone allows it. Am wondering if it is even worth experimenting with all these when Sparkfun and others sell Telit quad band GSM modems that are combined with a SirfIII GPS module. Expensive!"

They are Expensive ($130 AU) however if don't have old nokia laying around when you think about the cost of a second hand nokia ($30 - $40 AU) and the data cable ($40 AU) your only looking at an extra $50 to have a new, compact unit that may be easier to interface and possibly have GPS / Time Data as well (not sure about that?).
I probably would have gone with this option however i could not find any information about interfacing with picaxe.

If you do look the telit GSM modems i would love to see what you come up with.

Once i have the 6210 working with picaxe i might also have a play with the telit modem and will post any successes or lack of.

Eventually i hope to have an alarm system that will SMS my mobile if the alarm goes off and send various other data when requested. I also hope to be able to send an SMS to the alarm system to activate / deactivate the alarm, open door (lost key or let guest in while away), turn on air con etc...

Thank you for posting

Joel
 

lanternfish

Senior Member
... How did you connect your nokia to the picaxe? I was thinking i would have to buy the $40 DLR-3P Data Cable but if you have a better cheaper option i would be interested. I have seen the self made version but it looks like more than $40 work...
Used SKU-5 to test AT commands to the 6100. You will use the DLR-3P to do the same so that you can see how the 6210 responds to the commands. This can help with the timeout varaible values.

I also bought a cheap $9 RS232 - Pop port adaptor. I'm not sure if one is available for the 6210. A quick Google search should locate one.

To interface to the picaxe I cut off the RS232 D-connector end of the cable to retain the Pop port and lead. I then used a multimeter to check which wire went to which terminal. A useful link for 6210 Pop port pinout here

As the F-Bus is a 3V3 interface I used this circuit to connect the 5V picaxe to the 3V3 phone. Rather than using SMD components initially, I used a 2N7000 jfet from Jaycar Electronics and standard 1% resistors.

from your other post..
"AT is definitely the way to go if the cell phone allows it. Am wondering if it is even worth experimenting with all these when Sparkfun and others sell Telit quad band GSM modems that are combined with a SirfIII GPS module. Expensive!"

They are Expensive ($130 AU) however if don't have old nokia laying around when you think about the cost of a second hand nokia ($30 - $40 AU) and the data cable ($40 AU) your only looking at an extra $50 to have a new, compact unit that may be easier to interface and possibly have GPS / Time Data as well (not sure about that?).
I probably would have gone with this option however i could not find any information about interfacing with picaxe.
They are expensive, though this is offset by ease of use and size. Mind you, nothing like playing around with recyclable technology to expand our knowledge and skills.:eek:

Interfacing is a lot easier in the sense that the Rx/Tx pins are easier to access. Same process re AT commands. There is info on interfacing to other uprocessors that run some form of BASIC like the picaxe series.

Once i have the 6210 working with picaxe i might also have a play with the telit modem and will post any successes or lack of.
Sounds good.

Eventually i hope to have an alarm system that will SMS my mobile if the alarm goes off and send various other data when requested. I also hope to be able to send an SMS to the alarm system to activate / deactivate the alarm, open door (lost key or let guest in while away), turn on air con etc...
Have a hunt around some good websites (Makezine, Instructables) and magazines (Silicon Chip, Elektor, Nuts & Volts) at your local library. Many of these magazines have published similar projects and you will be able to look at what others have done and adapt as necessary.

FYI. I am buying a couple of 20X2's, one of which will replace the 28X2 as the 20X2 will run at 3V3 and so the 5V to 3V3 level converter won't be needed. This will mean some minor changes to the program, particularly around the /input/output 'numbering'.

My final program is larger and a bit 'messy' as I am using a large number of variables in the final message output.

I am also saving the messages in the phone before sending. I will post the info on this on Friday.

Glad this will help you with your project.

Cheers
 

lanternfish

Senior Member
As a cellphone allows you store messages before sending them, I used this feature as a sort of datalogging feature.

The AT comand for storing a message is AT+CMGW.

Code:
SYMBOL messindex = b5

Message_Save:					; Write message to memory

	SEROUT txpin,gsmbaud,("AT+CMGW=",34,"+33146290800",34,10,#testdata,26)

       SERIN [timeout,Save_Error_1],rxpin,gsmbaud,("+CMGW:"),messindex

	errflag = 0								; Clear error flag
	GOTO Send_Saved
	
Save_Error_1:

	INC errflag
	IF errflag < 2 THEN GOTO Message_Save

Save_Error_2:

	HIGH errled						; Turns Red (Error) LED on
	PAUSE 300						; Wait
	LOW errled						; Turns Red (Error) LED off
	PAUSE 300						; Wait
	GOTO Save_Error_2
The variable messindex is returned by the phone. This is where the message is stored. This allows a number of messages to be stored that can be sent depending on a trigger event. To send the stored message:

Code:
Send_Saved:

       SEROUT txpin,gsmbaud,("AT+CMSS=",messindex,26)

       SERIN [timeout,Send_Error_1],rxpin,gsmbaud,("OK")

	errflag = 0								; Clear error flag
	GOTO Endless                                                     ; End of program
	
Send_Error_1:

	INC errflag
	IF errflag < 2 THEN GOTO Send_Saved

Send_Error_2:

	HIGH errled						; Turns Red (Error) LED on
	PAUSE 300						; Wait
	LOW errled						; Turns Red (Error) LED off
	PAUSE 300						; Wait
	GOTO Send_Error_2
Enjoy.
 
Last edited:

MPep

Senior Member
Hi LF,

Whilst I haven't had a chance to fully study your code just yet, I appreciate your post.:)

I am curious to know how you found out the cellphone you used was AT compatible.

Cheers,
MPep.
 

lanternfish

Senior Member
A good question. Ummmmmmmmmmmmm .... After a quick web search I have found some of the sources I used.

Nokia Europe has a pdf on AT commands for Nokia phones.

I then connected the Nokia to my laptop and tested other commands as Listed in this AT Reference pdf.

Cheers
 

lanternfish

Senior Member
As a footnote to my original post, I chose to test if the phone was on by using the AT+CGMM command. A simpler way is to send the command "AT". If the phone is connected and on, it will reply with "OK".
 

MPep

Senior Member
Thanks.
I, too, have a general list of AT commands, as well as those used by Iridium satellite telephones, and data modems.

You are correct in using AT only. However, even if using PDU, you still need to talk, using AT commands. PDU is the encryption method for SMS transmission.

Cheers,
MPep.
 

MPep

Senior Member
Actually, re-reading my question, the real question should have been: How did you know that the cellphone you used could accept SMS data payload using ASCII (textual) input? As opposed to PDU coding.:D
MPep.
 

lanternfish

Senior Member
Actually, re-reading my question, the real question should have been: How did you know that the cellphone you used could accept SMS data payload using ASCII (textual) input? As opposed to PDU coding.:D
MPep.
It was a matter of trying the appropriate AT command (AT+CMGF=1) and getting the "OK" response.

Cheers
 

MPep

Senior Member
Yeah I guessed that part of it. Suck-it-n-see technique still works! :D
Must give it a go with my work cellphone. Have the USB cable, so will see.

Of course, for PICAXE work, serial is required (as previously mentioned).

Actually, does anyone know of a USB-serial bridge that can act as a USB master?

Cheers,
MPep.
 

mindertvanrij

New Member
I was looking for this a long time!

I've been struggeling on the same thing,Using A NOKIA 6021. Found this thread after solving moost of the hurdels. Just for others to find this.
I used a Nokia CA-42 cable (12 euro's). cut it in two.
The picaxe connection was made here using an opamp to increase the phone signal from 2.7 Volt to 5 vollt. I needed opamps annyway to connect the pic to an open therm thermostat (not working Yet).
I keep both ends of the CA-42 connected this activates the phone into the datacable connected mode. To protect the phone against the 5 Volts I used a diode that only allows to pull down the 2.7 Volts signal if neccecary to talk to the phone.

Thanks for the info, it helps me to get on with this project.:):):)
 

hippy

Technical Support
Staff member
does anyone know of a USB-serial bridge that can act as a USB master?
I can only think of "a PC" though a modified NAS, router or similar may be able to do that. With new PICmicro's having USB OTG, host handling, such things may appear or be possible in the future. A lot will depend upon what exactly it is that you want to control and how you want to to control it.

If the data cable is simply USB to serial and presents itself as a COM port to the PC you'll probably be better off removing the USB part and dealing with the serial TX and RX lines directly.

I was given a USB data cable but that presents itself as a HID device on the PC so not sure how that would be controlled from a PC or any other USB host. Phones which have cables which appear as COM ports will be much easier to use.
 

luke.wheat

New Member
Hi
I'm doing a similar project but am using a Siemens MC35 for a school project. I am new to using picaxe with serial and am looking for help on how to both wire up the GSM modem with a picaxe and then program it to send text data that is pre-defined by certain situations.
Thanks,
Luke
 

hippy

Technical Support
Staff member
Welcome to the PICAXE Forum.

The Siemens MC35 is a unit which I believe I have used but some time ago and with a PC rather than a PICAXE. Should be easy enough to connect to a PICAXE. I'd recommend an X2 to allow use of the high-speed serial background receive capability but you might be able to get away with any PICAXE using 'blind send' and just SEROUT.

First step is to find the AT Command set list, then I'd recommend using a PC connection and a terminal emulator to experiment with sending AT commands and seeing what comes back as responses. Build up a list of AT commands to do what you want then port that to a PICAXE.

Treat the project as three parts -

1) Getting the TC35 to work via a PC
2) Get it to work from a PICAXE
3) Get the PICAXE to make the TC45 do different things depending on inputs

AT commands ...

http://tc485.od.ua/docs/at_commands_tc35.pdf
 
Top