Page 1 of 2 1 2 LastLast
Results 1 to 10 of 15

Thread: PICAXE to SMS

  1. #1
    Senior Member
    Join Date
    Jan 2009
    Location
    Dunedin, New Zealand
    Posts
    512

    Default PICAXE to SMS

    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 by lanternfish; 06-10-2009 at 02:38. Reason: Added comment at end
    It would be helpful if people wouldn't make sweeping generalizations all the time.

  2. #2
    Member
    Join Date
    Sep 2009
    Location
    Australia
    Posts
    34

    Smile 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

  3. #3
    Senior Member
    Join Date
    Jan 2009
    Location
    Dunedin, New Zealand
    Posts
    512

    Default

    Quote Originally Posted by joely87 View Post
    ... 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.

    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
    It would be helpful if people wouldn't make sweeping generalizations all the time.

  4. #4
    Senior Member
    Join Date
    Jan 2009
    Location
    Dunedin, New Zealand
    Posts
    512

    Default

    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 by lanternfish; 10-10-2009 at 04:04.
    It would be helpful if people wouldn't make sweeping generalizations all the time.

  5. #5
    Senior Member
    Join Date
    Jan 1970
    Location
    Rangiora, New Zealand
    Posts
    1,495

    Default

    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.
    In theory, there is no difference between theory and practice. In practice, there is...


  6. #6
    Senior Member
    Join Date
    Jan 2009
    Location
    Dunedin, New Zealand
    Posts
    512

    Default

    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
    It would be helpful if people wouldn't make sweeping generalizations all the time.

  7. #7
    Senior Member
    Join Date
    Jan 2009
    Location
    Dunedin, New Zealand
    Posts
    512

    Default

    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".
    It would be helpful if people wouldn't make sweeping generalizations all the time.

  8. #8
    Senior Member
    Join Date
    Jan 1970
    Location
    Rangiora, New Zealand
    Posts
    1,495

    Default

    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.
    In theory, there is no difference between theory and practice. In practice, there is...


  9. #9
    Senior Member
    Join Date
    Jan 1970
    Location
    Rangiora, New Zealand
    Posts
    1,495

    Default

    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.
    MPep.
    In theory, there is no difference between theory and practice. In practice, there is...


  10. #10
    Senior Member
    Join Date
    Jan 2009
    Location
    Dunedin, New Zealand
    Posts
    512

    Default

    Quote Originally Posted by MPep View Post
    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.
    MPep.
    It was a matter of trying the appropriate AT command (AT+CMGF=1) and getting the "OK" response.

    Cheers
    It would be helpful if people wouldn't make sweeping generalizations all the time.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •