writeBytes
Write raw commands to the GPS receiver
Syntax
Description
Examples
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)
s = Serialport with properties: Port: "COM4" BaudRate: 9600 NumBytesAvailable: 0 Show all properties, functions
gps = gpsdev(s)
gps = gpsdev with properties: SerialPort: COM4 BaudRate: 9600 (bits/s) SamplesPerRead: 1 ReadMode: "latest" SamplesRead: 0 Show all properties all functions
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
$GPRMC,,V,,,,,,,,,,N*53 $GPVTG,,,,,,,,,N*30 $GPGGA,,,,,,0,00,99.99,,,,,,*48 $GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30 $GPGSV,2,1,08,01,,,18,08,,,12,09,,,12,15,,,19*77 $GPGSV,2,2,08,23,,,13,24,,,09,25,,,10,27,,,25*79 $GPGLL,,,,,,V,N*64 $GPRMC,,V,,,,,,,,,,N*53 $GPVTG,,,,,,,,,N*30 $GPGGA,,,,,,0,00,99.99,,,,,,*48
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
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30 $GPGSV,2,1,05,01,,,13,09,,,11,15,,,16,23,,,12*74 $GPGSV,2,2,05,25,,,10*7A $GPGLL,,,,,,V,N*64 µb ( 7.03 (45969) 00040007 °$GPRMC,,V,,,,,,,,,,N*53 $GPVTG,,,,,,,,,N*30 $GPGGA,,,,,,0,00,99.99,,,,,,*48 $GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30 $GPGSV,2,1,06,01,,,11,09,,,11,23,,,14,24,,,21*75
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;
Input Arguments
The GPS sensor, specified as a gpsdev
object.
Raw command to configure the GPS module, specified as an hexadecimal array.
Example: [0xB5 0x62 0x06 0x01 0x08 0x00 0xF0 0x08 0x00 0x01 0x00
0x00 0x00 0x00 0x08 0x60]
Data Types: uint8
Version History
Introduced in R2020b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)