MATLAB Answers

Reading serial data (NMEA) into simulink

2 views (last 30 days)
Jan De Vries
Jan De Vries on 2 Oct 2011
I have a NMEA compass connected to my PC through COM1 (4800 baud, 8 data bits, 1 stop bit, no parity).
It sends heading data into the following format:
$HCHDG,hhh.h,,,,<CR><LF>
where hhh.h is the direction the compass is heading in degrees with 1 decimal.
I am able to read the output of the compass using the "Query instrument". I tried saving the output of this block into a matlab file to check what happens, and it yields me a series of ascii codes corresponding to the format above (eg. 36 72 67 72 etc. which corresponds to $HCH). It's reading out the output as long as mu simulation runs, so I get a long string with multiple sentences in the format described above.
However, I am only interested in the heading hhh.h, and do not want all the other characters. I want to have a signal in my simulink model which is equal to the (realtime) heading to control my direction.
How can I filter out the heading from the Query Instrument output?

Answers (2)

Shankar Subramanian
Shankar Subramanian on 13 Oct 2011
Hi Jan,
Do you receive a response from the compass after you send a query command to it? Or do you continuously get data from the compass? If it is streaming, have you tried to use Serial Configuration and Serial Receive blocks? The Serial receive block has the option of specifying header and terminator on the mask to separate out the required data alone.
Thanks
Shankar
  2 Comments
Jan De Vries
Jan De Vries on 13 Oct 2011
Just took a quick look at the serial receive block, might be what I'm looking for.
Now I need to find a way to extract the heading info from the NMEA sentence, that is, to get hhh.h from the sentece
$HCHDG,hhh.h,,,,<CR><LF>

Sign in to comment.


Marc
Marc on 7 May 2013
Hello,
I am trying to use "serial receive block" to recieve data from the gyros conected to my arduino. I send this with Serial.write() which sends bytes. My problem is: when I try to select my port (COM3) in the "serial receive block" no port apperas, just the sentence "please select a port..".
Is there any configuration that I might be missing? How can I select the port?
Thank you

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!