neo-8m python programming

Active today
Viewed 84 times

Hi i’m tryng to change the update rate of my gps tracker(neo 6m ublok) i know the byte that i need to send are 0xB5,0x62,0x06,0x08,0x06,0x00,0xC8,0x00,0x01,0x00,0x01,0x00,0xDE,0x6A

i’ve tried echo -e "\xB5\x62\x06\x08\x06\x00\xC8\x00\x01\x00\x01\x00\xDE\x6A" > /dev/ttyAMA0

and with the service stopped i also tryed with a program in c

        #include <stdio.h>
        #include <fcntl.h>   /* File Control Definitions           */
        #include <termios.h> /* POSIX Terminal Control Definitions */
        #include <unistd.h>  /* UNIX Standard Definitions          */ 
        #include <errno.h>   /* ERROR Number Definitions           */

        void main(void)
                int fd;/*File Descriptor*/

                printf("\n +----------------------------------+");
                printf("\n |        Serial Port Write         |");
                printf("\n +----------------------------------+");

                /*------------------------------- Opening the Serial Port -------------------------------*/

                /* Change /dev/ttyUSB0 to the one corresponding to your system */

                fd = open("/dev/ttyAMA0",O_RDWR | O_NOCTTY | O_NDELAY); /* ttyUSB0 is the FT232 based USB2SERIAL Converter   */
                                                                        /* O_RDWR Read/Write access to serial port           */
                                                                        /* O_NOCTTY - No terminal will control the process   */
                                                                        /* O_NDELAY -Non Blocking Mode,Does not care about-  */
                                                                        /* -the status of DCD line,Open() returns immediatly */                                        

                if(fd == -1)                                            /* Error Checking */
                   printf("\n  Error! in Opening ttyUSB0  ");
                   printf("\n  ttyUSB0 Opened Successfully ");

                /*---------- Setting the Attributes of the serial port using termios structure --------- */

                struct termios SerialPortSettings;      /* Create the structure                          */

                tcgetattr(fd, &SerialPortSettings);     /* Get the current attributes of the Serial port */

                cfsetispeed(&SerialPortSettings,B9600); /* Set Read  Speed as 9600                       */
                cfsetospeed(&SerialPortSettings,B9600); /* Set Write Speed as 9600                       */

                SerialPortSettings.c_cflag &= ~PARENB;   /* Disables the Parity Enable bit(PARENB),So No Parity   */
                SerialPortSettings.c_cflag &= ~CSTOPB;   /* CSTOPB = 2 Stop bits,here it is cleared so 1 Stop bit */
                SerialPortSettings.c_cflag &= ~CSIZE;    /* Clears the mask for setting the data size             */
                SerialPortSettings.c_cflag |=  CS8;      /* Set the data bits = 8                                 */

                SerialPortSettings.c_cflag &= ~CRTSCTS;       /* No Hardware flow Control                         */
                SerialPortSettings.c_cflag |= CREAD | CLOCAL; /* Enable receiver,Ignore Modem Control lines       */ 

                SerialPortSettings.c_iflag &= ~(IXON | IXOFF | IXANY);          /* Disable XON/XOFF flow control both i/p and o/p */
                SerialPortSettings.c_iflag &= ~(ICANON | ECHO | ECHOE | ISIG);  /* Non Cannonical mode                            */

                SerialPortSettings.c_oflag &= ~OPOST;/*No Output Processing*/

                if((tcsetattr(fd,TCSANOW,&SerialPortSettings)) != 0) /* Set the attributes to the termios structure*/
                    printf("\n  ERROR ! in Setting attributes");
                    printf("\n  BaudRate = 9600 \n  StopBits = 1 \n  Parity   = none");

                /*------------------------------- Write data to serial port -----------------------------*/

                char write_buffer[] = "A";      /* Buffer containing characters to write into port           */
                unsigned char packet[] = { 0xB5,  0x62, 

        0x06, // 

        0x08, // 

        0x06, // length

        0x00, // 

        0x64, // measRate, hex 64 = dec 100 ms

        0x00, // 

        0x01, // navRate, always =1

        0x00, // 

        0x01, // timeRef, stick to GPS time (=1)

        0x00, // 

        0x7A, // CK_A

        0x12, // CK_B

                int  bytes_written  = 0;        /* Value for storing the number of bytes written to the port */ 
                //for(int i=0;i<14;i=i+1){
                //      printf(packet[i]);
                bytes_written = write(fd,packet,sizeof(packet));/* use write() to send data to port                                            */
                                                                             /* "fd"                   - file descriptor pointing to the opened serial port */
                                                                             /* "write_buffer"         - address of the buffer containing data              */
                                                                             /* "sizeof(write_buffer)" - No of bytes to write                               */
                char buf [100];
int n = read (fd, buf, sizeof buf);
                printf("\n  %s written to ttyUSB0",write_buffer);
                printf("\n  %d Bytes written to ttyUSB0", bytes_written);
                printf("\n +----------------------------------+\n\n");

                close(fd);/* Close the Serial port */


and with python

import serial
#from serial import Serial

import time

import string

import pynmea2

ser=serial.Serial(port, baudrate=9600 ,   parity=serial.PARITY_NONE,



#serdata= bytearray([0xB5,0x62,0x06,0x08,0x06,0x00,0xC8,0x00,0x01,0x00,0x01,0x00,0xDE,0x6A,0xB5,0x62,0x06,0x01,0x08,0x00,0xF0,0x01,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x2B]) #0x06"0x00"0xC8"0x00"0x01"0x00"0x01"0x00"0xDE"0x6A"

#serdata= bytearray([0xB5,0x62,0x06,0x08,0x06,0x00,0xC8,0x00,0x01,0x00,0x01,0x00,0xDE,0x6A])
#ser.write(bytes([181,98,6,8,6,0,100,0,1,0,1,0,122,18])) # 5hz
#ser.write(bytearray([181, 98, 6, 1, 8, 0, 240, 1, 0, 0, 0, 0, 0, 1, 1, 43])) #GxGLL off
while True:


        #ser=serial.Serial(port, baudrate=9600, timeout=0.5)

        dataout = pynmea2.NMEAStreamReader()

        #print(newdata[0:6] == "$GPRMC")
        if (newdata[0:6] == b"$GPRMC"):


                gps = "Latitude=" + str(lat) + "and Longitude=" + str(lng)


but nothig change the navigation update rate of the device

all of the byte code came from the manual of the device

and this


and this

https://forum.arduino.cc/index.php?topic=470763.0 wiring gps wire

EDIT: i’ve tryed both of the response but none of them worked cutecom what i have to do if i want to connect with usb instread of uart

share  edit  follow  close  flag
 New contributor
  • Hi @awaska, Welcome and nice to meet you. Ah, let me see. (1) Can I assume that you have setup your Neo6 and that cgps and xgps run OK? If yes, then your serial setup should be default 9600, 8N1, (2) Can I assume that you know you are using ttySerial0 or ttyUSB by setting the gps config file? (2) Suppose you are using ttyUSB0, and using python to send the bytes to change nav rate for 1Hz to 5Hz. (3) One troubleshooting trcik you might use is to do the serial loopback test, with (a) Neo6 removed from serial port. (b) short TxD to RxD and see if Rx loopback Tx. / to continue, … – tlfong01 Jun 18 at 13:24   
  • Actually you can use any terminal emulator, say Win10 RealTerm, Rpi CuteCom, or miniCom etc to send the update to 5Hz bytes to Neo6. Please let me know if you wish to know more about python serial loopback program, or terminal emulator to do loop back test and send bytes to Neo6. Cheers. – tlfong01 Jun 18 at 13:27    
  • hi thanks for the responi connected my gps trough uart, i can read the message of the gps with no problem using cat or the python program, i’ve tryed the serial loopback and it works i’ve shorted the 2 pin and if i do echo "test" > /dev/serial0 and cat -v < /dev/serial0 i can see test so the serial is working, i’ve tryed trougth the u-center with network serial for controlling the gps but still the gps won’t change i’ve retryed with bash ans the hex directly given from the u-center but still the update rate won’t change, is wrong how i wrote the code in python for writing the hex? – awaska Jun 18 at 15:18
  • What you send to/dev/ttyAMA0 with echo is not a byte. – Ingo Jun 18 at 17:40
  • when i tryed to send byte the serial gose crazy and start to repeat the message and after some time i can’t write anything and when i read the serial is just brakeline, i have the jumper, and after reboot when i send echo -e -n "\xB5\x62\x06\x01\x08\x00\xF0\x01\x01\x00\x00\x01\x01\x00\x03\x35" > /dev/serial0 echo -e -n "\xB5\x62" > /dev/serial0 i read nothing from the serial cat -v < /dev/serial0 but if i send echo "test" > /dev/serial0 strange stuff append, the word test is repited multiple time with incrising space – awaska Jun 18 at 19:48
  • this is the resul of cat -v < /dev/serial0 test test test test test test test – awaska Jun 18 at 19:52
  • Just to confirm. Did you mean that you also used u-center config but still no luck? Please see my u-center log below. And for the UBX message, can you try (1) End the frequency update string with check sum, and (2) End the UBX message with CR, LF? – tlfong01 Jun 20 at 5:15    
  • @awaska, Part A of my answer shows how to use the u-center to set my Neo-8M measurement rate to 0.25Hz, and the measurements now repeat every four seconds. You might like to verify with your Neo-6M. Good luck. Cheers. – tlfong01 Jun 20 at 13:09   
  • Part B shows how to use CuteCom to send 14 byte UBX command to change the update rate to 4 seconds. – tlfong01 yesterday   

2 Answers



How can Rpi update Neo-6M/8M GPS measurement rates?


Short Answer


Part A - Using ublox u-centre*

Part B - Using Rpi CuteCom

Part C - Using Thonny pyton

Part A – Using u-center to do the frequency setting

u-center screen below shows if measurement frequency is set to 0.25Hz, then the test measurements repeats every 4 seconds.

set rates

Part B – Using cuteCom to send UBX message to change update rate to 4 seconds

(1) Try end measurement/navigation frequency command with the two check sum bytes. See Appendix E for an example to calculate the check sum for a update rate to 4000mS command.

(2) Try end UBX message with CR, LF. (update – CR, LF is not necessary for hex input, only necessary for text input)

Note – it is much more newbie friendly to use GUI Rpi terminal emulator cuteCom than CLI bash echo and cat.

I have compiled a command message to set the measurement rate to 4 seconds. Then I used cuteCom to input the 14 byte command string to Neo-8M serial. Neo-8M accepted the command and measurement rate became 4 seconds.

set update rate

Part C – Using Rpi4B Thonny Python to set Neo-8M update rate

Now I am thinking of using thonny python 3.7.3 to set the Neo-8M measurement update rates. To make thing simple, I will only handle the RMC sentence, as shown below:

update 4000mS


(1) NEO-M6 Receiver Description Including Protocol Specification – ublox

(2) NEO-M6 GPS NMEA message parsing in python (with checksum calculation) – tomazas/nmea_ublox.py 2015

(3) NEO-M6 How to update system Date & Time from GPS in python (with checksum calculation) – 2016dec15

(4) NEO-M8 Receiver description Including protocol specification R19 – 2020may14

(5) NEO-M8 concurrent GNSS modules Product sheet R07 – 2020apr30

(6) NEO-M8 GNSS modules Hardware integration manual R07 – 2020may20

(7) Fletcher’s Checksum – Wikipedia

(8) Fletcher’s Checksum – TutorialsPoint

(9) Endianness (Big and Little Endian) -Wikipedia

(10) Enabling/disabling NMEA sentences on u-Blox gps receiver? – GIS SE Q&A Asked 2016jun17 Viewed 13k times

(11) Getting Started with U-Center for u-blox – SparkFun

(12) SparkFun GPS-RTK Board – NEO-M8P-2 – US$200

(13) GPS-RTK Hookup Guide – SparkFun

(14) What is GPS RTK? – SparkFun

(15) Enable or disable NMEA datasets in u-blox GPS module – HandHeldGroup 2018apr18

(16) Enabling/disabling NMEA sentences on u-Blox gps receiver? – Asked 4 years ago, Viewed 13k times

(17) GIS StackExchange

(18) NMEA 0183 – Wikipedia

(19) NMEA (National Marines Electronics Association) Official Web Site

(20) NMEA 0183 V4.10 Standard – NMEA

(21) NMEA v3.01 data – gpsInfo.org

(22) Global Positioning System, Principle and Practices – Satheesh Gopi, McGraw-Hill 2005

(23) BeiDou – Wikipedia


Appendix A – Set rates

set rates

Appendix B – UBX Checksum

ubx checksum

Appendix C – NEO-8M Set Measurement and Navigation Update Rates

neo8m set rate

Appendix D – UBX Checksum Program

checksum 1

Appendix E – Python program to calculate checksum

# fletcher_chksum02.py Fletcher 8-bit checksum - tlfong01  2020jun22hkt2147

# *** NEO-6M/8M IBX Message Examples ***
# --------------------------------------------------------------------------------------------------------------------
# synC1 synC2 class id    length      measRate    navRate     timeRef     checkSum   measurement update rate
# --------------------------------------------------------------------------------------------------------------------
# 0xb5, 0x62, 0x06, 0x08, 0x06, 0x00, 0x64, 0x00, 0x01, 0x00, 0x01, 0x00, 0x7A, 0x12 measRate 0x64  = 100ms  = 0.1 sec
# 0xB5, 0x62, 0x06, 0x08, 0x06, 0x00, 0xC8, 0x00, 0x01, 0x00, 0x01, 0x00, 0xDE, 0x6A measRate 0xc8  = 212ms  = 0.2 sec
# 0xB5, 0x62, 0x06, 0x08, 0x06, 0x00, 0xa0, 0x0f, 0x01, 0x00, 0x01, 0x00, 0xC5, 0xC5 measRate 0xfa0 = 4000ms = 4.0 sec
# --------------------------------------------------------------------------------------------------------------------

dataByteList01 = [0x06, 0x08, 0x06, 0x00, 0x64, 0x00, 0x01, 0x00, 0x01, 0x00]
dataByteList02 = [0x06, 0x08, 0x06, 0x00, 0xC8, 0x00, 0x01, 0x00, 0x01, 0x00]
dataByteList03 = [0x06, 0x08, 0x06, 0x00, 0xa0, 0x0f, 0x01, 0x00, 0x01, 0x00] # measRate = 0xa0 0x0f = 0xfa0 = d4000

def calcCheckSum(dataByteList):
    ckA = 0
    ckB = 0
    for dataByte in dataByteList:
        ckA = ckA + dataByte
        ckB = ckB + ckA
    ckA = ckA & 0xff
    ckB = ckB & 0xff
    print(hex(ckA), hex(ckB))


# *** End of program ***

Appendix F – NMEA v3.01 data – gpsInfo.org

NMEA v3.01 data – gpsInfo.org

nmea sen 1

nmea sen 2

share  edit  delete  flag
  • 1
    look at the edit, by the way thanks so mutch for responding so quickly – awaska 9 hours ago
  • Let me see. My CuteCom is using ttyUSB0 and you ttyAMA0. If you want to use ttyUSB0, then say so to CuteCom. But if you want to talk USB to USB (or SPI or I2C) then you might like to consider SparkFun’s USD200 recommendation (Ref 12). By the way, I tried S0, AMA0, Serial0, and USB0 and found all except AMA0 not always working. So I almost always use USB0 in my experiments. Please also see my comments to @tqhien about my bad experiences on AMA0. Another reason of using ttyUSB0 is that my plan is using ttyUSBn for more than 6 GNSSs at the same time. – tlfong01 7 hours ago    


You can send a string to your Neo with the following sentence (I didn’t check the validity of your bytes):

echo -en '\xB5\x62\x06\x08\x06\x00\xC8\x00\x01\x00\x01\x00\xDE\x6A' > /dev/ttyAMA0

But you need to be under the root user for both side of the “>” character : if you do only

sudo echo [...] > /dev/ttyAMA0

the echo command is executed as root, but opening device ttyAMA0 for writing is not.

So you’ll have to make a “sudo su” before all that.

As for your program, it’ll have to be executed as root to be able to open /dev/ttyAMA0 for writing.

share  edit  follow  flag
  • Many thanks for your advice and clarification. I found “/dev/ttyAMA0” and “/dev/Serial0″ problematic. And ”sudo su” seems to solve the problem. On the other hand, “/dev/ttyS0” and “/dev/ttyUSB0” seems problem free. – tlfong01 22 hours ago   

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: