# DEMO: Pixhawk-4 GPS Module with Zephyr

## Introduction

This tutorial describes how to operate the [Pixhawk-4 GPS Module](https://docs.px4.io/main/en/gps_compass/gps_holybro_m8n_m9n.html) (Ublox M8N) with [Zephyr](https://github.com/NXPHoverGames/Zephyr/tree/pr-mimxrt1062-fmurt6) on [FMURT6 board](https://www.nxp.com/part/RDDRONE-FMURT6#/).

## Items Needed

| NAME                                                                                           | QUANTITY |
| ---------------------------------------------------------------------------------------------- | -------- |
| [Holybro Pixhawk-4 GPS](https://holybro.com/products/pixhawk-4)                                | 1        |
| [RDDRONE-FMURT6 Board](https://www.nxp.com/part/RDDRONE-FMURT6#/)                              | 1        |
| [Pixhawk Debug Adapter](https://holybro.com/products/pixhawk-debug-adapter)                    | 1        |
| [J-Link EDU Mini](https://www.segger.com/products/debug-probes/j-link/models/j-link-edu-mini/) | 1        |
| USB-C to USB-A Cable                                                                           | 2        |
| Micro-USB to USB-A Cable                                                                       | 1        |
| [JST SH 10-Pin Cable](https://www.pcboard.ca/jst-sh-10-pin-cable)                              | 1        |
| [.05" 10-Pin Ribbon Cable](https://www.adafruit.com/product/1675)                              | 1        |

## Hardware Procedure

<figure><img src="https://3991116448-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M8v3AGPa-j5DtYx8zqd%2Fuploads%2FQFGx1DNAlhLjO6Jjto0G%2Fcomplete_setup.jpg?alt=media&#x26;token=eff6cbdd-4c8b-493a-a196-374727ac22dc" alt=""><figcaption><p>Complete Hardware Setup</p></figcaption></figure>

<figure><img src="https://3991116448-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M8v3AGPa-j5DtYx8zqd%2Fuploads%2FIK4Ehf10NVf7gNsgdriS%2Fblock_diagram.png?alt=media&#x26;token=55fffbbe-ccb5-4d5b-9002-9903f5c0ed4f" alt=""><figcaption><p>Block Diagram (Hardware)</p></figcaption></figure>

## Zephyr Software Procedure

#### Initialize west workspace and checkout branch

<pre><code><strong>west init -m git@github.com:NXPHoverGames/Zephyr.git zephyrproject
</strong><strong>cd zephyrproject
</strong><strong>west update
</strong><strong>cd zephyr
</strong><strong>git checkout pr-gps-fmurt6
</strong></code></pre>

#### Building and Flashing

```
west build -b mimxrt1062_fmurt6 samples/drivers/neo_m8 -p
west flash
```

#### Error Handling

1. if you get the following error (or similar): "fatal error: command exited with status 1: /opt/segger/jlink\_v788a/jlinkexe -nogui 1 -if swd -speed auto -device 'mimxrt1062xxx6a?bankaddr=0x60000000\&loader=hyperflash' -commanderscript /tmp/tmpgcx4mnhnjlink/runner.jlink -nogui 1", then simply run west flash again. Or unplug the board, then re-plug it. And then flash again.
2. if you get the following error: "fatal error: required program jlinkexe not found; install it or add its location to path", then download and install jlink from [here](https://www.segger.com/downloads/jlink/), and add its folder to the path using the following command: set PATH=%PATH%;\<path to Jlink.exe>
   * Note: this command only modifies the PATH variable for the current session.

## Running and Demonstration

#### Key Notes

* If any configuration API returns NACK (which can be seen from the debug logs), then it's recommended to run the application again.
* The reception of GPS data from the Pixhawk-4 GPS Module depends on the location of operation. According to our testing, this module doesn't work indoors, but only outdoors, or rooms with at least one open window.
* We may need to wait 3-5 minutes before our GPS module is able to receive data. As shown in 'Logs From Testing on GPS Module 2 (Success)', the module first senses the data on the 280th function call, but after that returns the correct data consistently. **According to our observations, the 'GPS Fix' Indicator LED will start blinking when GPS signals are available.**

#### Logs

{% file src="https://3991116448-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M8v3AGPa-j5DtYx8zqd%2Fuploads%2FXUl0soWRF1JMoWbUGp00%2FGPS_Module_Logs.log?alt=media&token=bbcf8508-a0fd-4c85-9835-bc1773f15ce3" %}
GPS Module Logs
{% endfile %}
