%% Write Configuration Commands to GPS Receiver
% Write configuration commands to the GPS receiver connected to the host computer using serialport object.
%% Required Hardware
% To run this example, you need:
% UBlox Neo-6M GPS module
% GPS antenna
% USB to UART module
% USB cable
% Connecting wires
%% Hardware Connection
%
% Connect the pins on the UBlox Neo-6M GPS module to the pins on your USB to UART module. The connections are:
% VCC - +5V
% RX - TXO
% TX - RXI
% GND - GND
% Connect the GPS antenna to the GPS module. Connect the USB to UART module to the host computer with a USB cable. GPS Fix can be easily acquired in locations that have a clear view of the sky. Wait for the GPS module to acquire satelite signals (Fix).This can be verified by checking the Fix LED (D1) of your GPS module.
%
%% Create GPS Object
% Connect to the GPS receiver using serialport object. Specify the port name and the baud rate.

s = serialport('COM4',9600)
gps = gpsdev(s)

%% Write Configuration Commands
% In the default configuration the GPS receiver returns the following NMEA messages: GPRMC, GPVTG, GPGGA, GPGSA, GPGSV, and GPGLL. The receiver can be configured to have a user defined set of output messages.
% Read few lines of default messages from the serial port the GPS receiver is connected.

for i = 1:10    
data = readline(s);
disp(data);
end

% Write the version monitor command to the GPS receiver to return the software and hardware version of the GPS receiver.

configCMD = [0xB5 0x62 0x0A 0x04 0x00 0x00 0x0E 0x34];
% writeBytes(gps,cfg)
write(s,configCMD,'uint8')

% Read few lines of messages again to verify the version message.

for i = 1:10    
data = readline(s);
disp(data);
end

% It can be observed from the output, 7.03 (45969) is the software version and 00040007 is the hardware version.
%% Clean Up
% When the connection is no longer needed, clear the associated object.

delete(gps);
clear gps;
clear s;

% Copyright 2020 The MathWorks, Inc.