It’s been over six years now since I published my last post on how to run RTKLIB on a Raspberry PI, so it’s more than time for an update. In my previous post, I described using a Pi Zero as a data logger for a u-blox M8N for PPK solutions. In this post I will work with a Pi Model 4 and a u-blox M8T to demonstrate both logging for PPK solutions and a real-time RTK solution. The good news is that this time no soldering is required since we are going to use the USB port on the Pi to connect the receiver. These instructions will work with any u-blox receiver that supports raw observations and any model Pi that has USB ports for peripherals. With minor modifications, they can be used with any receiver that has a USB or UART port and supports raw observations.
Here’s an image of the assembled setup. The Pi in the center, and the u-blox M8T receiver is on top. We will use a wireless connection to talk to the Pi from an external computer so there is no need for a keyboard or display.
Raspberry Pi with u-blox M8T receiver
Step 1: Configure the Pi
The first step is to configure the Pi in “headless” mode so that we can talk to it from an external computer. This is quite straightforward and well-explained in this post, so I will not describe how to do it here. Only steps 1 and 2 in the post are required for this exercise. If you plan to use this for RTK solutions, be aware that the Pi will rely on the wireless connection to the internet for base station observations. This means that if you don’t want to be limited to using it within range of your home wireless router, then you will probably want to connect to a hot spot from a cell phone. If you are just interested in collecting data for PPK solutions, then it doesn’t matter.
After you have completed steps 1 and 2 above, you should have a Putty window open and have logged into your Pi. The next step is to build and install the RTKLIB code. The commands below will clone the RTKLIB code from the Github repository, compile the stream server app (str2str) and the RTK solution app (rtkrcv), and copy the executables to a location where they can be accessed from any directory.
> sudo apt update
> sudo apt install git
> mkdir rtklib
> cd rtklib
> git clone https://github.com/rtklibexplorer/RTKLIB.git
> cd RTKLIB/app/consapp/str2str/gcc
> sudo cp str2str /usr/local/bin/str2str
> cd ../../rtkrcv/gcc
> sudo cp rtkrcv /usr/local/bin/rtkrcv
> cd ../../../../..
Step 2: Configure the receiver
Before we connect the u-blox receiver to the Pi, we will need to configure it to output raw observation and navigation messages. The easiest way to do this is from your computer with the u-center app which can be downloaded from the u-blox website. Connect the receiver to your computer with a USB cable, start u-center, and connect to the receiver using the “Connection” option in the “Receiver” tab as shown in the image below.
Next, use the “Messages View” window from the “View” menu to enable the RAWX and SFRBX messages as seen below. While you are in the messages view, you can also disable any unnecessary NMEA messages to save communication bandwidth.
Next, we will switch to the “Configuration View” window to configure any other desired settings and then save them to flash . I would recommend verifying that all constellations are enabled with the “GNSS” command and that the sample rate is set to the desired value with the “RATE” command. I usually set this to 5 Hz. I would also recommend disabling both UART ports with the “PORT” command if you are not using them. If the baud rates are set too low, they will limit bandwidth on all ports including the USB port, even if nothing is connected to those ports. Finally, use the “CFG” command to save the settings to flash as shown below.
Step 3: Verify the data stream(s)
Next, we will confirm that we are receiving data from the rover receiver and if running a real-time solution, also from the base receiver. This step is not absolutely essential, but it does verify that we have the individual pieces working before we put it all together, and also gives some practice using the RTKLIB str2str command.
Disconnect the rover receiver from the computer and connect it to the Pi using a USB cable as shown in the image at the top of this post. Enter the following commands into the Putty console to create a new folder and run the stream server. This will connect to the USB port on the Pi. If you are using a UART port, you will need to use the appropriate port name.
> mkdir data
> cd data
> str2str -in serial://ttyACM0
The output of the receiver should now scroll across the Putty console screen. If you have any NMEA messages enabled, you should be able to see them mixed in with a bunch of random characters from the binary messages. Once you’ve confirmed the data stream, hit Control C to stop it.
If we want to log the receiver output for a PPK solution, we just need to add a file name to the previous command to redirect the data stream from the screen to a file. The command below will do this, using keywords in the file name to create a name that includes the current month, day, hour, and minute.
> str2str -in serial://ttyACM0 -out rover_%m%d_%h%M.ubx
The image below shows the expected output of both commands.
If you are using the Pi just to log receiver data then you are done at this point unless you want to configure the Pi to make it automatically start collecting data whenever it is turned on. There are several ways to do this, all described in this post. Modifying the rc.local file is the simplest method.
For those who would prefer to run an RTK solution rather than just log data for a PPK solution, the next step is to confirm the base data stream. We will use the “str2str” command again, but this time we will specify the input to be an NTRIP stream using the format:
In my case, the command looks like this: (with the username and password removed)
> str2str -in ntrip://username:email@example.com:2101/P041_RTCM3: -out temp.log
If everything is working properly, you should see non-zero transfer numbers and no errors, as in example above, in which case you can use Control C again to stop.
Note that if your NTRIP provider is using a VRS (Virtual Reference Station), then things are a little more complicated. We will need to send our local position inside of a GGA message. For this to work, you must have enabled the NEMA GGA message when configuring the receiver. To route these GGA messages back to the NTRIP server we will need to connect the stream server output to the receiver and enable the relay back feature with the “-b” option. Here’s an example I used to connect to test this with a VRS NTRIP server.
str2str -in ntrip://username:firstname.lastname@example.org:2101/CRS -b 1 -out serial://ttyACM0
Step 4: Run the RTK solution
OK, now that we’ve confirmed that we are getting data from base and rover, it’s time to generate an RTK solution. We will use the “rtkrcv” console app in RTKLIB to do this, which we installed in Step 1.
We will need a configuration file for rtkrcv. You can use the “rtknavi_example.conf” file included with the demo5 release as a starting point but you will need to edit the stream configuration settings. Below are the settings I changed as well as a few important ones worth verifying are correct for your configuration. I have it configured to write the output to a file in LLH format. If you want the output in NMEA messages you can either change output stream 1 to “nmea” format or enable output stream 2 to get both a file and a stream of NMEA messages.
pos1-posmode =kinematic # (0:single,1:dgps,2:kin,3:static) pos1-frequency =l1 # (1:l1,2:l1+l2,3:l1+l2+l5) pos1-navsys =13 # (1:gps+2:sbas+4:glo+8:gal+16:qzs+32:comp) pos2-armode =fix-and-hold # (0:off,1:cont,2:inst,3:fix-and-hold) pos2-gloarmode =fix-and-hold # (0:off,1:on,2:autocal,3:fix-and-hold) out-solformat =llh # (0:llh,1:xyz,2:enu,3:nmea) ant2-postype =rtcm # (0:llh,1:xyz,2:sing,3:file,4:rinex,5:rtcm) inpstr1-type =serial (0:off,1:ser,2:file,3:,...,7:ntrip) inpstr2-type =ntripcli # (0:off,1:ser,2:file,3:,...,7:ntrip) inpstr1-path =ttyACM0 inpstr2-path =usrname:email@example.com:2101/P041_RTCM3 inpstr1-format =ubx # (0:rtcm2,1:rtcm3, ...) inpstr2-format =rtcm3 # (0:rtcm2,1:rtcm3,...) inpstr2-nmeareq =single # (0:off,1:latlon,2:single) outstr1-type =file # (0:off,1:serial,2:file, ...) outstr2-type =off # (0:off,1:serial,2:file, ...) outstr1-path =rtkrcv_%m%d_%h%M.pos outstr2-path = outstr1-format =llh # (0:llh,1:xyz,2:enu,3:nmea) outstr2-format =nmea # (0:llh,1:xyz,2:enu,3:nmea) logstr1-type =file # (0:off,1:serial,2:file, ...) logstr2-type =file # (0:off,1:serial,2:file, ...) logstr1-path =rover_%m%d_%h%M.ubx logstr2-path =base_%m%d_%h%M.rtcm3
I like to use WinSCP for editing and transferring files between the Pi and external computer but there are many other ways to do this. When you are done, the edited configuration file needs to be in the current folder you will run rtkrcv from. For my example, I renamed it “rtkrcv_pi.conf”
To run rtkrcv with a configuration file named “rtkrcv_pi.conf”, use the following commands:
> rtkrcv -s -o rtkrcv_pi.conf
>> status 1
If all is well, you should see a status screen updated every second that looks something like this:
I changed the Putty display defaults to make this a little easier to read. I’ve also highlighted in yellow some of the numbers to check to make sure they look OK. Make sure you are seeing base RTCM location messages (usually 1005). If you want to check the input streams in more detail, you can use control c to exit the status menu, then enter “?” to see some of the other rtkrcv commands. To exit rtkrcv, use the “shutdown” command.
If all of your inputs look good, your solution is not working, and it is not obvious why, you can rerun rtkrcv with a “-t 3” in the command line. This will enable trace mode which will create a trace debug file which may offer clues as to what is wrong.
This should be enough to get you started. To explore more configuration options, see the str2str and rtkrcv sections in Appendix A of the RTKLIB users manual.