1

I have connected a NEO6M GPS module to an Arduino Mega 2560 and programmed using TinyGPS++ library's "Device Example". I am getting proper data at serial port.

NEO6MGPS to ArduinoMega2560
Vcc           3.3volts
GND           GND
TX            Pin10
RX            Pin9

I have created S-function for NEO6M-GPS for ArduinoMega2560 at Matlab to output latitude longitude alone from TinyGPS++ "Device Example" code with following:

Initilization:

No of discrete states:1
Sample mode: Discrete
Sample time value: 0.1

Data Properties:

Two "Output ports" are defined latitude & longitude of data type int32

Libraries:

#ifndef MATLAB_MEX_FILE
#define ARDUINO 100
#include <Arduino.h>
#include "TinyGPS++.h"
#include "TinyGPS++.cpp"
#include "SoftwareSerial.h"
#include "SoftwareSerial.cpp"
TinyGPSPlus gps;
SoftwareSerial ss(10, 9);
#endif

Outputs:

    if(xD[0] == 1) 
    {
      #ifndef MATLAB_MEX_FILE
      while (ss.available() > 0)
      gps.encode(ss.read());  
      if (gps.location.isValid())   
      {
        latitude[0]=gps.location.lat();
        longitude[1]=gps.location.lng();   
      }   
      else   
      {
        Serial.print("0");   
      }
      #endif 
    }

Discrete Update:

    if(xD[0]!=1)   
    {   
      # ifndef MATLAB_MEX_FILE    
      Serial.begin(115200);     
      ss.begin(9600);    
      # endif    
      xD[0]=1;   
    }

Note: I am successful in building the s function and changing the wrapper name to .cpp and editing with addition of extern "C" at appropriate lines. And able to deploy on target hardware.

"### Done invoking postbuild tool."  "### Successfully generated all
binary outputs." AVR Memory Usage
---------------- Device: atmega2560 Program:   11082 bytes (4.2% Full) (.text + .data + .bootloader) Data:       1066 bytes (13.0% Full)
(.data + .bss + .noinit)

Matlab Simulink diagram which is successfully deployed

During live simulation run I don't observe any output in the scope/display.

My question is do I have any logical errors in writing code at "output" part of s-function or misplacing the code at other fields of s-function ?

I am okay to change my library, all I need is latitude and longitude displayed at simulink. Please do suggest necessary changes to be made.

  • Can someone help on this issue ? – Praneeth varma Dec 1 '17 at 4:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.