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:


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


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


    if(xD[0] == 1) 
      #ifndef MATLAB_MEX_FILE
      while (ss.available() > 0)
      if (gps.location.isValid())   

Discrete Update:

      # ifndef MATLAB_MEX_FILE    
      # endif    

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
  • Did you manage to figure this out? – user61142 Nov 26 '19 at 7:49

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.