How to connect GPS to ESP32

Thanks to a very versatile Input/Output matrix, it is quite simple to connect NMEA GPS modules to ESP32 MCUs. Not only ESP32 boards have 3 serial ports you can choose from, they can be assigned to almost any pin you want.

In this example we will connect a popular Ublox NEO-M8N like Beitian BN-880 or BN-220 to a ESP32 development board and output current position on a USB serial port using Arduino IDE and TinyGPS++ library. Let's begin

Sketch header and setup routine

Let's include all of our libraries: TinyGPS++ and HardwareSerial

#include "types.h"
#include <TinyGPS++.h>
#include <HardwareSerial.h>

Then, let's assign variables and create TinyGPSPlus and HardwareSerial object called SerialGPS on serial port 1.

TinyGPSPlus gps;
HardwareSerial SerialGPS(1);

No, set's set up everything in a setup function. GPS will be connected with 9600bps and to pins:

  • Serial 1 RX – pin 16 – connect GPS TX pin to it
  • Serial 1 TX – pin 17 – connect GPS RX pin to it
void setup() {

    Serial.begin(115200); //Serial port of USB
    SerialGPS.begin(9600, SERIAL_8N1, 16, 17);

When everything is configured, we can listen to data on SerialGPS and send it to TinyGPS++ and decoded data to USB serial port

void loop() {
    while (SerialGPS.available() > 0) {

    Serial.print("LAT=");  Serial.println(, 6);
    Serial.print("LONG="); Serial.println(gps.location.lng(), 6);
    Serial.print("ALT=");  Serial.println(gps.altitude.meters());

Full example is available here. It does other functions too!

ESP32 and GPS with a help of TinyGPS++ library

One of the first projects I did with ESP32 development boards is a simple GPS tracker. OK, it's not really a tracker since it does not store the position anywhere, more like distance meter with a UBLOX Neo-8M Beitian BN-880 GPS unit and small SSD1306 OLED display.

This ESP32 GPS Thingy as I call it uses one button to store current position and then report straight line distance, speed and altitude compared to "Home Point". GPS communication is handled by TinyGPS++ library.

Oh, one the best things about ESP32 is that you can map ports to almost any pin you want. It's not like on ATmega328 where UART and I2C are always the same pins. Here you can choose them. How nice is that?

Code is available on GitHub.

Matek SAM-M8Q and SAM-M8Q Compass GPS modules hands on

You might say that UBLOX NEO-M8N (Beitian BN-880 for example) is the workhorse on INAV and other drones with GPS functions. It is reliable, well know and proven. But it is also big and heavy. So why not try something new?

Matek did tried something new and just provided me with two brand new GPS modules of their: Matek SAM-M8Q and SAM-M8Q Compass with a QMC5883 magnetometer. One is only a small GPS module suitable for airplanes (flat surface) while the other one has also a QMC5883 compass that makes it a perfect choice for multirotor drones. Let's take a look at those two and figure out if they might be worth it.

The best GPS module for INAV

This is my personal best GPS module for INAV: Beitian BN-880 based on Ublox Neo-M8N. Currently I have 3 pieces of BN-880, all works just great, and if I will have a need to have another one, I would also choose it.

Why? It really works well. On the outside it gets a solid 3D fix in less than a minute. It even can get a fix with 9-10 sats in a center of a city when only a small piece of sky is visible simply by lying on a windowsill. It take time, but works.

Beitian BN-880 - best GPS module for INAV?

Read More

iNav: Waypoint Mission

This video was taken few weeks ago during my tests of Waypoint Mission implemented in iNav.

Hardware setup:

  • Transporter Q7.6 600mm quadcopter frame
  • SPRacingF3 Acro with BMP085 external barometer
  • Beitian BN-880 (ublox Neo-M8M)
  • 10×4.5" APC props
  • EMAX GT2218/08 1100KV motors
  • 5000mAh 3S battery

Software setup:

  • iNav pre 1.1
  • Default navigation PIDs
  • Slightly tuned FP-PID, quite close to default values
  • GPS nav model: HIGH_G set gps_nav_model=HIGH_G
  • Velocity calculation done by GPS module set inav_use_gps_velned=ON

Mission plan:

  1. Take off in Angle model
  2. Follow 3 waypoints on total distance of about 300m, constant altitude of 10m
  3. At last waypoint goto Position Hold mode
  4. Manually engage Return To Home mode
  5. Automatic RTH and land

iNav: RTH with land mission

This video was taken last weekend during tests of latest changes implemented in iNav, as well as new GPS module Beitian BN-880 I shortly described here.
Mission plan:

  • Take off in Angle mode,
  • Engage 3D Position Hold
  • Fly away 100m
  • Return to Position Hold
  • Engage Return To Home mode


  • Beitian BN-880 performed well. Quadcopter returned home with 1m accuracy. Constant fix on 15 sats all the time and HDOP at 1.2
  • No problems with magnetometer inside GPS module
  • No bigger problems during whole mission. I still have to work on yaw behavior. At the moment FP-PID and linear mixer from Betaflight can cause some strange yaw behavior on bigger quads. Fix should be available soon

Hands-on: Beitian BN-880 GPS module

Looking for a decent replacement for my u-blox NEO-6M GPS modules I came by super cheap, Chinese, Beitian BN-880 modules from Banggood. According to information found in the internet, it’s build based on u-blox Neo-M8N and is capable of receiving signals from GPS, GLONASS, Galileo, BeiDou, QZSS and SBAS. Plus integrated magnetometer module. Yesterday package finally arrived and here are my first impressions:

  • It’s not single board, but 2 boards glued together
  • There is not casing, and cases for popular Neo-6M wont fit. BN-800 is much taller
  • It accepts both 5V and 3.3V voltage and 5V UART level is safe, nothing burned
  • It connected to Cleanflight and iNav without any problems at 38400bps
  • Quick windowsill test showed that indeed it works not only with GPS, but also other positioning systems. When GPS Neo-6M was barely able to acquire 4 satellites, Beitian BN-880 found 9 and a solid 3D fix
  • I did not tested magnetometer yet

Beitian BN-880

Beitian BN-880 Antenna

Beitian BN-880 Side view

Hopefully I will be able to perform more tests next few weekends and provide more info on this module. For now it looks very promising.

iNav: Cleanflight learned how to do missions

In my recent post I mentioned that iNav flight controller software (fork of Cleanflight) introduced missions. Missions are preprogrammed waypoints that drone will fly to in specified order and/or do specified action at each of them. For example, if pilot wants to make a video on specified route, he does not have to pilot his drone all the time. He enters waypoints and lets machine do everything else. In this entry I will show how to configure iNav to do missions.


  • iNav compatible drone flight controller flashed with iNav software. Currently supported boards are: Naze32, Flip32, CC3D, SPracingF3, Sparky, RDMO
  • GPS module connected to flight controller board. This example shows how to do it for Flip32, but it will work for all other boards, only UART pins might be different
  • Magnetometer connected and properly calibrated
  • Barometer connected
  • EZ-GUI Ground Station Android application that will act as Mission Planner. Official Cleanflight Configurator does not support this function yet
  • Bluetooth telemetry. Some time ago I have written how to do it for Flip32, but it will work almost the same for all other flight controllers, only UART pins might be different

Read More

Better GPS for Cleanflight: iNav

Cleanflight is an awesome piece of software for STM32 based flight controllers. But Cleanflight has one very serious flaw that makes its usage on bigger drones at least problematic. Cleanflight sucks in GPS and barometer support. Sucks a lot. It can handle Position Hold (somehow), Return To Home (barely) and Altitude Hold (oh man, up and down, up and down) but if you at least one tried that, you should know that is not only not reliable, but also not precise and hard to tune. Personally I gave up after few tires. It was not worth it. Comparing to Pixhawk (not talking even about Naza) it might as well not exists at all. But it has changed recently…. Read More