How to control servo motor with handphone through GSM modem?


Closed Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    May 2008
    Posts
    7

    Default How to control servo motor with handphone through GSM modem?

    Hi all,

    I am currently doing a mini project of controlling the servo motor using easypic4.

    I managed to control the direction the servo turns by using the pushbuttons on the board to make it turn clockwise or counter-clockwise.

    However, I would like to control the servo by sending a message using handphone to the GSM modem which is connected to the RS232 com port of the easypic4 and make the servo turns accordingly.

    What are the additional codes which I need to control using handphone?

    Any help would be appreciated. Thanks. =)

  2. #2
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by supertyx View Post
    I am currently doing a mini project of controlling the servo motor using easypic4.
    I managed to control the direction the servo turns by using the pushbuttons on the board to make it turn clockwise or counter-clockwise.
    However, I would like to control the servo by sending a message using handphone to the GSM modem which is connected to the RS232 com port of the easypic4 and make the servo turns accordingly.
    What are the additional codes which I need to control using handphone?
    Wow.........

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795

    Default

    I could say a lot of additional code...

    In this special category on GSM there are many examples... Just search through. I warn you it is not an easy project...

    Ioannis

  4. #4
    Join Date
    May 2008
    Posts
    7

    Default

    First I wrote a couple of codes to test the AT commands with SEROUT2 and Tx Command between my PC and the PIC16F77A (CPU) on the easypic4 using hyperterminal.

    These are the codes:

    INCLUDE "modedefs.bas"

    'PIC16F877A specific

    @ __CONFIG _HS_OSC & _WDT_ON & _LVP_OFF & _CP_OFF

    'This is a simple program to drive a servo using easypic4 and pushbuttons.
    'PORTB.0 - Set to drive the servo clockwise to the center.
    'PORTB.1 - Set to drive the servo clockwise to the end.
    'PORTB.3 - Set to drive the servo counter-clockwise to the end.

    'Connections:

    'PIC-PIN : Servo
    'PortC.1 : Control wire
    'Vcc(5V) : Power Wire(Red wire)
    'Gnd(0V) : Black wire

    '************************************************* *********************

    'Defines

    Define LOADER_USED 1 'Use tiny boot loader

    DEFINE USE_LFSR 1
    DEFINE OSC 20

    ' LCD Defines
    DEFINE LCD_DREG PORTD ' LCD data port
    DEFINE LCD_DBIT 4 ' LCD data starting bit 0 or 4
    DEFINE LCD_RSREG PORTD ' LCD register select port
    DEFINE LCD_RSBIT 2 ' LCD register select bit
    DEFINE LCD_EREG PORTD ' LCD enable port
    DEFINE LCD_EBIT 3 ' LCD enable bit
    DEFINE LCD_RWREG PORTD ' LCD read/write port
    DEFINE LCD_RWBIT 2 ' LCD read/write bit
    DEFINE LCD_BITS 4 ' LCD bus size 4 or 8
    DEFINE LCD_LINES 2 ' Number lines on LCD
    DEFINE LCD_COMMANDUS 2000 ' Command delay time in us
    DEFINE LCD_DATAUS 50 ' Data delay time in us

    'Set tris & system registers


    TRISA=%00000000 ' Set Port A pins as Output
    TRISB=%11111111 ' Set Port B pins as Input
    TRISC=%00000000 ' Set Port C pins as Output
    TRISD=%00000000 ' Set Port D pins as Output
    TRISE=%00000000 ' Set Port E pins as output

    'Program variables

    position var byte

    'Input/output port assignments

    PB_UP VAR PORTB.3 'Push button to move servo up
    PB_center VAR PORTB.0 'Push button to move servo to center
    PB_down VAR PORTB.1 'Push button to move servo down

    Tx var PORTC.6 ' Tx Rs232 to Terminal
    Rx var PORTC.7 ' Rx Rs232 from Terminal

    'Main program

    PORTC.1 = 0

    InitModem:
    pause 1000
    lcdout $Fe,01,"Init Modem"
    gosub init

    pause 1000
    lcdout $Fe,01,"Modem Init Done"
    pause 1000

    lcdout $FE, 01, "Ready to start"

    'Read input

    Read_input:

    if PORTB.0 = 1 then
    position = 0

    endif

    if PORTB.1 = 1 then
    position = 1

    endif

    if PORTB.3 = 1 then
    position = 2

    endif

    if position = 0 then
    pulsout PORTC.1, 750

    endif

    if position =1 then
    pulsout PORTC.1, 300

    endif

    if position =2 then
    pulsout PORTC.1, 1150

    endif

    pause 50

    goto Read_input

    'SMS subroutines


    Init:

    ' Subroutine to initialise the GSM modem

    Serout2 Tx,84,["AT+CLIP=1",13] ' CLIP command
    Pause 500
    Serout2 Tx,84,["AT+CNMI=3,0",13] ' SMS now not polled
    Pause 500
    Serout2 Tx,84,["AT+CMGF=1",13] ' Set Text Mode
    Pause 500

    SERout2 Tx,84,["AT+CMGS=",34,"+6598755989", 34,13]

    'Preferred Message Storage: ME on Phone

    Serout2 Tx,84,["AT+CPMS=",34,"ME",34,13] ' Changed for GR47
    Pause 4000

    'Set the storage to SIM

    Serout2 Tx,84,["AT+CPBS=",34,"SM",34,13]' Otherwise cannot read memory location
    Pause 1000

    'SERIN2 Tx,84,5000,Problem,[Wait ("OK")] ' Loopback to NotReady
    'Select Character Set “UTF-8” : Universal text format, 8 bits

    PAUSE 1000
    Serout2 Tx,84,["AT+CSCS=",34,"UTF-8",34,13] ' for @ sign problem
    pause 1000
    Serout2 Tx,84,["AT&W",13] 'Store User Profile to non volatile memory
    pause 1000
    Serout2 Tx,84,["AT+CMGD=1,4",13]
    pause 3000

    Return


    Next I need to change the above codes to SERIN and Rx and "additional codes" so that my GSM modem can receive an sms from a handphone in order to trigger the servo motor.

    This is where my problem comes in. Any help would be appreciated. Thanks.

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795

    Default

    I would strongly suggest to use hardware USART and if possible interrupts like Darrels Instant Interrupts. It will assure you no lost characters.

    Secondly, I see that you are not checking if the modem has replied with OK or an error, except once. Not all commands have the same processing time. So it is a good practise to confirm that the device has accepted succesfully the command by monitoring its response.

    Ioannis

  6. #6
    Join Date
    May 2008
    Posts
    7

    Default

    Quote Originally Posted by Ioannis View Post
    I would strongly suggest to use hardware USART and if possible interrupts like Darrels Instant Interrupts. It will assure you no lost characters.

    Secondly, I see that you are not checking if the modem has replied with OK or an error, except once. Not all commands have the same processing time. So it is a good practise to confirm that the device has accepted succesfully the command by monitoring its response.

    Ioannis
    I've used an open source software called " real term" to test out the serial cable

    The following are the codes i used to test:

    Code:
        Serout2 Tx,84,["Ready:",13]
    	pause 500
    	Serin2 rx,84,[wait("A="),B0]				
    	Pause 500
        Serout2 PORTC.6,84,["Got: ",B0,13]
    	pause 500
    	goto init
    It's working. Now I need to test the GSM modem using SEROUT2 and SERIN2 commands. Anyone knows how?

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795

    Default

    Any special need to use Serin2/Serout2 instead of Hseri/Hserout?

    Ioannis

  8. #8
    Join Date
    May 2008
    Posts
    7

    Default

    Quote Originally Posted by Ioannis View Post
    Any special need to use Serin2/Serout2 instead of Hseri/Hserout?

    Ioannis
    What are the differences between serin2/serout2 and hserin/hserout?

    How can I use either set of commands to capture sms message?

  9. #9
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by supertyx View Post
    What are the differences between serin2/serout2 and hserin/hserout?
    How can I use either set of commands to capture sms message?
    Guess where the answer is?
    (could be in post #8, but it's not!)

    EDIT: Looks like the post I was referring to (i.e. spam) got deleted (Thx admins).
    Let me change that to:
    See post #10...
    Last edited by skimask; - 22nd May 2008 at 01:06.

  10. #10
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795

    Default

    1. Software vs Hardware. Is that clear enough?

    2. If you do not know how to use these commands, then sorry, I cannot teach you PicBasic Pro lanquage. You have to do it yourself, and if you face a problem, then come here to show your code and be sure many will help you debug it.

    3. The GSM thread has many resources for the matter. Just read...

    Ioannis

  11. #11
    Join Date
    May 2008
    Posts
    7

    Default

    I can send sms using at commands:

    Code:
    pause 1000
    LCDOUT $Fe,01, "Sending Now.."
    PAUSE 2000
    serout2 Tx,84,["AT+CMGS=",34,"Put hp number here",34,13]
    pause 1000
    serout2 TX,84,["How are you?",26]
    'pause 1000
    lcdout $Fe,01, "Message sent"
    PAUSE 2000
    LCDOUT $Fe,01, "STOP"
    stop
    Now i want to write a program to receive sms. What are the codes needed to be edited/added?

Similar Threads

  1. More Servo Woes
    By chrisshortys in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 13th May 2009, 09:40
  2. Help with Servo Control Please!
    By wireman22 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 7th June 2007, 19:15
  3. SEROUT2 to GSM Modem
    By tommyers in forum General
    Replies: 5
    Last Post: - 21st August 2006, 22:35
  4. Servo control woes
    By Eriswerks in forum mel PIC BASIC Pro
    Replies: 24
    Last Post: - 28th February 2006, 01:12
  5. Control RC servo via Parallax Servo Control
    By cibotsan in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 17th September 2005, 09:18

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

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