Menu

How to display response from GSM module on LCD

2019-04-25
2019-05-30
1 2 > >> (Page 1 of 2)
  • oni omoniyi

    oni omoniyi - 2019-04-25

    Please every one am new to code writing. I need your help on a project that am working on. i have a SIM800L gsm module connected to 18f4550 . i will like to read the respone of the gsm module on the LCD when it return "OK" and also turn on an LED connected to PORTA.0. i can make call or send text with the module but i can.t get the LCD to display the respone from the module. Please let someone put me through.
    Here is the code.
    ~~~

    chip 18f4550, 4

    'Set the pin directions
    #define USART_BAUD_RATE 9600
    #define USART_BLOCKING
    #define USART2_BAUD_RATE 9600
    #define USART2_BLOCKING
    

    'InitUSART
    #define SerInPort PORTc.7    'USART 1 Rx Pin
    #define SerOutPort PORTc.6    'USART 1 Tx Pin
    

    'LCD settings
    #define LCD_IO 4
    #define LCD_RS PORTB.7
    #define LCD_RW PORTB.6
    #define LCD_Enable PORTB.5
    #define LCD_DB4 PORTB.4
    #define LCD_DB5 PORTB.3
    #define LCD_DB6 PORTB.2
    #define LCD_DB7 PORTB.1

    'Set pin directions
    Dir SerOutPort Out
    Dir SerInPort In
    
    Dir PORTB.6 Out        'second USART Tx Pin
    Dir PORTB.7 In        'second USART Rx Pin
    
    Dir PORTA.0 Out
    
    Wait 100 Ms
    
    Dim myNum as Word
    Dim MyString as String
    

    HSerPrint "AT"
    HSerPrintCRLF

    'Main routine
    
    Do Forever
    
        HSerGetString MyString
        HSerPrint MyString
        HSerSend(13)
         If MyString = "OK" Then
             Set PORTA.0 On
             Locate 1,0
             Print Mystring
                 End If
        set
    

    Set PORTA.0 Off
    Loop
    ~~~

     

    Last edit: Chris Roper 2019-04-27
  • David Stephenson

    I've noticed an obvious error. You are using portb.6 and portb.7 on both the USART and the LCD.
    I normally specify the LCD as write only which saves on a pin (why would you want to read anyway).

     
    • oni omoniyi

      oni omoniyi - 2019-04-25

      thanks @ David for your observation. it is a mistake on my part when typing. PORTC. 7 and PORTC. 6 were actually used to TX and Rx. why I needed to read the response of the module is because I want to control a load that will be connected to PORTA.0 by send SMS from mobile phone.

       
  • stan cartwright

    stan cartwright - 2019-04-25
     If MyString = "OK" Then
         Set PORTA.0 On
         Locate 1,0
         Print Mystring
             End If
    set------------this line looks incomplete
    

    Set PORTA.0 Off
    Loop

     
    • oni omoniyi

      oni omoniyi - 2019-04-25

      Thanks for for response. its an error and been taken care of but can't still get the response displayed.

       
  • Anobium

    Anobium - 2019-04-27

    @Oni. How are you getting on? All sorted? If not - let us know.

     
  • oni omoniyi

    oni omoniyi - 2019-04-27

    @Anobium. thank you for your concern. I haven't been able to sort out it out. I am new to coding. I have been going through some examples to see if I can solve it on my own no success yet but I have made up my mind am not going to give up on the project.

     
    • Anobium

      Anobium - 2019-04-27

      Describe what you are trying to achieve. Post yourchallenges again. And, attach your code that you have produced.

      There are many that can help.

       
      • oni omoniyi

        oni omoniyi - 2019-04-27

        okay I will that the moment am back home. what I plan to achieve through the project is to be able to control some load by sending SMS from a phone. when the GSM module receive the SMS, it will communicate with the microcontroller which willin turn be able to determine whether load A or B should be on or off as the case may be.

         
        • Anobium

          Anobium - 2019-04-27

          OK. You will need to share what the phone model is, what the phone interface is.

           
  • stan cartwright

    stan cartwright - 2019-04-27

    Doesn't the SIM800L gsm need a 2G sim card? It runs at 3.6V and logic is 3V from a quick look.

     
    • oni omoniyi

      oni omoniyi - 2019-04-27

      the SIM800L is working properly and the power is well taking care of. I have written a small code using the same chip to call another phone number and also text SMS from the chip and it work fine. I strongly believe the problem is with my code.

       
  • oni omoniyi

    oni omoniyi - 2019-04-27

    thank you everyone. I have try to reframe the code this is what I now have.

    ;Chip Settings
    #chip 18F4550,4
    #config OSC=XT, BOREN=OFF, WDT=OFF, MCLRE=ON, LVP=OFF, DEBUG=OFF, CPD=OFF
    
    ;Include files (Libraries)
    #include "C:\GCB@Syn\GreatCowBasic\Include\lowlevel\lcd.h"
    
    ;Defines (Constants)
    #define USART_BAUD_RATE 9600
    #define USART_BLOCKING
    #define LCD_IO 4
    #define LCD_RS PORTB.1
    #define LCD_RW PORTB.2
    #define LCD_Enable PORTB.3
    #define LCD_DB4 PORTB.4
    #define LCD_DB5 PORTB.5
    #define LCD_DB6 PORTB.6
    #define LCD_DB7 PORTB.7
    #define BACKLIGHT PORTB.0
    #define TX PORTC.6
    #define RX PORTC.7
    
    ' USART settings
    Dir TX Out
    Dir RX In
    Dir PORTA.0 Out
    Dir BACKLIGHT Out
    Wait 100 ms
    Set BACKLIGHT On
    CLS
    Locate 0, 3
    Print "Meafactorem"
    Locate 1, 3
    Print "Smart Home"
    Locate 0, 17
    Print "Security Device"
    Wait 5 s
      HSerPrint "AT+IPR=9600"
      HSerPrintCRLF
      Wait 500 ms
    cls
    HSerPrint "ATE0"
      HSerPrintCRLF
      Wait 500 ms
    Dim gsm as string
    main:
    gsm = "AT"
    Do
      For send_data = 0 to 10 
    HSerPrint gsm 
      HSerPrintCRLF
        Locate 0,0: Print "Sent: "
        Locate 0,6: Print "   "
        Locate 0,6: Print gsm
    
    Hsersend gsm, 1  '//send data from USART1
    Rec_data = HserReceive1  '//wait for return byte
       Locate 2,0: Print "Received: "
        Locate 2,10: Print "   "
        Locate 2,10:  Print Rec_data
    wait  1 s   '//time to see data
    IF Rec_data =79 THEN '79 is the ASCII value of O from the "OK" response 
    IF PORTA.0=0 THEN 'If the LED is off..
    SET PORTA.0 ON 'I turn on the LED
    ELSE 'If the LED is on..
    SET PORTA.0 OFF 'I turn off the LED
    END IF
    END IF
    next
    loop
    

    it still not working as expected.

     

    Last edit: Chris Roper 2019-04-27
  • Chris Roper

    Chris Roper - 2019-04-27

    Just an observation, and it will probably not impact on your issue, but you don't need to explicitly #include anything from the "lowlevel" folder.
    They will be auto included at compile time if needed.

     
  • Anobium

    Anobium - 2019-04-28

    @Oni.

    I see nothing wrong with your code. Why do I think this. I have you code running on a test bed. I have a terminal representing the GSM module. This code sents the init codes, sends repeated AT to which the terminal can respond 'OK', at this point the LED toggles. I would think the 1s delay would mess things up.

    But, I would not use this method of get serial data. I have attached the code I adapted (ignore the LCD stuff as this is for the GCB test bed) but I lifted the Serial Ring Buffer from the Help. And, that works a lot better.

    So, if the attached does not work for you to the GSM module... try replacing the GSM module with Terminal to test and diag from the Terminal session.

     

    Last edit: Anobium 2019-04-28
  • Anobium

    Anobium - 2019-04-28

    I have replaced the original file I posted with the attached.

    You may want to increase the #define BUFFER_SIZE from 8 to 64.

     

    Last edit: Anobium 2019-04-28
    • oni omoniyi

      oni omoniyi - 2019-04-28

      thank you for your effort. I really appreciate that. I will try the code and surely give you a feedback the moment power is restored to my community. I've been out of supply for 24hrs now.

       
      • Chris Roper

        Chris Roper - 2019-04-28

        I guess you are also in Africa then Oni.
        I am South African.

         
  • oni omoniyi

    oni omoniyi - 2019-05-30

    @ Evan and everyone thank for your support . After a lot of trying i can now display a full text received by the GSM module on the LCD.
    But i still need some help. is tried to used GET(Line,Col) command to extract some part of the text displayed on the LCD , to store it as a string but i got nothing in return. can someone put me through how to do that please.

     
  • oni omoniyi

    oni omoniyi - 2019-05-30

    @ Evan and everyone thank for your support . After a lot of trying i can now display a full text received by the GSM module on the LCD.
    But i still need some help. is tried to used GET(Line,Col) command to extract some part of the text displayed on the LCD , to store it as a string but i got nothing in return. can someone put me through how to do that please.
    please find attached code.

     

    Last edit: oni omoniyi 2019-05-30
  • Anobium

    Anobium - 2019-05-30

    What are you tryung to do?
    Why not inspect the incoming data? rather than extract from the LCD.

     
    • oni omoniyi

      oni omoniyi - 2019-05-30

      @Anobium. Ive tried to do that without sucess. what i wanted was to be able to extract some part of the message as it coming in and store it in a string var. for future use.

       
  • jackjames

    jackjames - 2019-05-30

    The sim800 module has a pin (RI) that goes low if you receive a call or an SMS.
    If an SMS arrives, the pin goes low for 120 mSec, then returns high.
    We must read through an interrupt the passage to 0 of this pin, wait for a time greater than 120 ms and verify that the pin is again at 1.
    If so then it means that a text message has arrived.

     
    • oni omoniyi

      oni omoniyi - 2019-05-30

      thanks, yes i know, i can receive and read the text message successfully on the LCD but what i need to do now is to extract part of the message received and store it as a string. Any idea please.

       
  • jackjames

    jackjames - 2019-05-30

    This routine is used to extract the various parameters received via SMS.
    The string must have already been received by another routine and must contain all the characters that were received by the modem.
    This is a part from a program written in another language in which the following parameters are extracted from the received string:
    1) Telephone number
    2) Date and time
    3) text of the message
    In this example the variables used are not defined, so we need to define them.

    The"DatiRicevuti" variable is a string with the characters received from the modem.
    MRx_Count = strlen(DatiRicevuti)
    `
    I look for pointers to the various sections of text to be extracted.
    For ii = 0 to MRx_Count ' StrLen (DatiRicevuti) - 1
    If DatiRicevuti [ii] = Chr(34) Then ' Character found
    Inc (Cnt)
    Select Case Cnt
    Case 3 ' Inizio del Numero di Telefono
    PNum = ii + 1
    Case 5
    PDat = ii + 1
    Case 6
    PTxt = ii + 1
    Case Else
    nop
    End Select
    End If
    Next ii
    ' -
    ' Numero di telefono
    ' Telephone number
    If PNum Then
    Jj = 0
    For ii = PNum to MRx_Count
    If DatiRicevuti [ii] <> 34 Then
    DatiSMS.Numero [Jj] = DatiRicevuti [ii]
    Inc (Jj)
    Else
    DatiSMS.Numero [Jj] = 0
    Break
    End If
    Next ii
    End If
    ' -
    ' Data e ora
    ' Date e Time
    If PDat Then
    Jj = 0
    For ii = PDat to MRx_Count
    If DatiRicevuti [ii] <> 34 Then
    DatiSMS.OraData [Jj] = DatiRicevuti [ii]
    Inc (Jj)
    Else
    DatiSMS.OraData [Jj] = 0
    Break
    End If
    Next ii
    End If
    ' -
    ' Testo
    ' TEXT
    If PTxt Then
    Jj = 0
    For ii = PTxt to MRx_Count
    If (DatiRicevuti [ii] <> 10) And (DatiRicevuti [ii] <> 13) Then
    DatiSMS.Messaggio [Jj] = DatiRicevuti [ii]
    Inc (Jj)
    Else
    DatiSMS.Messaggio [Jj] = 0
    Break
    End If
    Next ii
    End If

    `
    ' -

    I hope it can be useful

     

    Last edit: jackjames 2019-05-30
1 2 > >> (Page 1 of 2)

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.