|
| 1 | +--- |
| 2 | +title: 'Getting Started with the MKR GPS Shield' |
| 3 | +description: 'Learn how to access GPS data from the module on board the MKR GPS Shield.' |
| 4 | +tags: |
| 5 | + - GPS |
| 6 | +author: Arduino |
| 7 | +--- |
| 8 | + |
| 9 | +## Introduction |
| 10 | + |
| 11 | +The MKR GPS Shield is based on the u-blox® [SAM-M8Q](https://www.u-blox.com/sites/default/files/SAM-M8Q_DataSheet_%28UBX-16012619%29.pdf) GNSS (Global Navigation Satellite System) module. This module is designed to operate with different positioning services concurrently. It receives and processes the signals from [GPS](https://en.wikipedia.org/wiki/Global_Positioning_System), [GLONASS](https://en.wikipedia.org/wiki/GLONASS) and [Galileo](https://en.wikipedia.org/wiki/Galileo_satellite_navigation). |
| 12 | + |
| 13 | +The reception of different services at the same time makes this shield suitable for outdoor applications around the world with an accurate calculation of the position down to a few meters. Multiple constellations means also more satellites in sight in environments like cities with tall buildings or areas with deep valleys and limited sky view. |
| 14 | + |
| 15 | +### Hardware |
| 16 | + |
| 17 | +The MKR GPS Shield has a small footprint and it is just slightly bigger than the space occupied by the headers. On it we have placed the [SAM-M8Q](https://www.u-blox.com/sites/default/files/SAM-M8Q_DataSheet_%28UBX-16012619%29.pdf) module, a backup battery holder, a power regulator and a 5 pin connector that is based on our 5pin standard scheme. |
| 18 | + |
| 19 | +| connector pin | Signal | |
| 20 | +| ------------- | ------ | |
| 21 | +| 1 | +5V | |
| 22 | +| 2 | EXTINT | |
| 23 | +| 3 | SCL | |
| 24 | +| 4 | SDA | |
| 25 | +| 5 | GND | |
| 26 | + |
| 27 | +Six solder pads allow the configuration of the connection between the module and the host. Some are already bridged, others are disconnected by default. |
| 28 | + |
| 29 | +| M8Q | HOST | CONNECTED | |
| 30 | +| ---------- | ---- | --------- | |
| 31 | +| RESET_N | 10 | N | |
| 32 | +| RXD | 9 | Y | |
| 33 | +| TXD | 8 | Y | |
| 34 | +| SAFEBOOT_N | 3 | N | |
| 35 | +| EXTINT | 2 | Y | |
| 36 | +| TP | 1 | N | |
| 37 | + |
| 38 | +The shield has been designed to be used with a MKR board as host through the headers or in a detached way, with the I2C connector that supports the power supply through pin 1. |
| 39 | + |
| 40 | +The module runs at a maximum voltage of 3.3 V and it is not 5 V tolerant, so if you plan to use it in a design where the signal levels for communication are managed by a board that has a 5 V microcontroller, you need to add a logic level converter 5V<->3.3V to safeguard the module input ports. |
| 41 | + |
| 42 | +The patch antenna is omnidirectional and should be kept with a clear sky view. Please remember that some car windshields are laminated with filters for IR and UV light that also shield electromagnetic signals. Usually the front windshield has a dedicated uncoated zone, useful for GNSS signal reception, near the rear mirror. |
| 43 | + |
| 44 | +### Software |
| 45 | + |
| 46 | +The MKR GPS Shield is connected through Serial1 to the MKR board or through I2C / DCC protocol on the 5pin connector. You can specify the type of connection you are using in the creator API `begin()` of our [Arduino_MKRGPS](/en/Reference/ArduinoMKRGPS) library that supports both in a transparent way for all the other APIs. |
| 47 | + |
| 48 | +### Examples |
| 49 | + |
| 50 | +The following sketch print continuously on the serial console the position. |
| 51 | + |
| 52 | +```c |
| 53 | +/* |
| 54 | +
|
| 55 | + GPS Location |
| 56 | + This sketch uses the GPS to determine the location of the board |
| 57 | + and prints it to the Serial monitor. |
| 58 | +
|
| 59 | + Circuit: |
| 60 | + - MKR board |
| 61 | + - MKR GPS Shield attached via I2C cable |
| 62 | +
|
| 63 | + This example code is in the public domain. |
| 64 | +
|
| 65 | +*/ |
| 66 | + |
| 67 | +#include <Arduino_MKRGPS.h> |
| 68 | + |
| 69 | +void setup() { |
| 70 | + // initialize serial communications and wait for port to open: |
| 71 | + Serial.begin(9600); |
| 72 | + while (!Serial) { |
| 73 | + ; // wait for serial port to connect. Needed for native USB port only |
| 74 | + } |
| 75 | + |
| 76 | + // If you are using the MKR GPS as shield, change the next line to pass |
| 77 | + // the GPS_MODE_SHIELD parameter to the GPS.begin(...) |
| 78 | + |
| 79 | + if (!GPS.begin()) { |
| 80 | + Serial.println("Failed to initialize GPS!"); |
| 81 | + while (1); |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +void loop() { |
| 86 | + |
| 87 | + // check if there is new GPS data available |
| 88 | + |
| 89 | + if (GPS.available()) { |
| 90 | + // read GPS values |
| 91 | + float latitude = GPS.latitude(); |
| 92 | + float longitude = GPS.longitude(); |
| 93 | + float altitude = GPS.altitude(); |
| 94 | + float speed = GPS.speed(); |
| 95 | + int satellites = GPS.satellites(); |
| 96 | + |
| 97 | + // print GPS values |
| 98 | + |
| 99 | + Serial.print("Location: "); |
| 100 | + Serial.print(latitude, 7); |
| 101 | + Serial.print(", "); |
| 102 | + Serial.println(longitude, 7); |
| 103 | + Serial.print("Altitude: "); |
| 104 | + Serial.print(altitude); |
| 105 | + Serial.println("m"); |
| 106 | + Serial.print("Ground speed: "); |
| 107 | + Serial.print(speed); |
| 108 | + Serial.println(" km/h"); |
| 109 | + Serial.print("Number of satellites: "); |
| 110 | + Serial.println(satellites); |
| 111 | + Serial.println(); |
| 112 | + } |
| 113 | +} |
| 114 | +``` |
| 115 | + |
| 116 | +This second example keeps the power consumption under control waking up the module every 10 seconds to get the position of the shield; when the position is acquired, it gets printed on the serial console together with the time taken to acquire it. |
| 117 | + |
| 118 | +```c |
| 119 | +/* |
| 120 | +
|
| 121 | + GPS Location Standby |
| 122 | + This sketch uses the GPS to determine the location of the board |
| 123 | + and prints it to the Serial Monitor. |
| 124 | +
|
| 125 | + It puts the GPS to in standby mode every 10 seconds, then wakes it up. |
| 126 | +
|
| 127 | + Circuit: |
| 128 | + - MKR board |
| 129 | + - MKR GPS attached via I2C cable |
| 130 | +
|
| 131 | + This example code is in the public domain. |
| 132 | +
|
| 133 | +*/ |
| 134 | + |
| 135 | +#include <Arduino_MKRGPS.h> |
| 136 | + |
| 137 | +void setup() { |
| 138 | + // initialize serial communications and wait for port to open: |
| 139 | + Serial.begin(9600); |
| 140 | + while (!Serial) { |
| 141 | + ; // wait for serial port to connect. Needed for native USB port only |
| 142 | + } |
| 143 | + |
| 144 | + // If you are using the MKR GPS as shield, change the next line to pass |
| 145 | + // the GPS_MODE_SHIELD parameter to the GPS.begin(...) |
| 146 | + |
| 147 | + if (!GPS.begin()) { |
| 148 | + Serial.println("Failed to initialize GPS!"); |
| 149 | + while (1); |
| 150 | + } |
| 151 | +} |
| 152 | + |
| 153 | +void loop() { |
| 154 | + // put the GPS in standby mode |
| 155 | + Serial.println("standby"); |
| 156 | + GPS.standby(); |
| 157 | + // wait for 10 seconds |
| 158 | + Serial.print("delay "); |
| 159 | + for (int i = 0; i < 10; i++) { |
| 160 | + delay(1000); |
| 161 | + Serial.print("."); |
| 162 | + } |
| 163 | + |
| 164 | + Serial.println(); |
| 165 | + // wake up the GPS |
| 166 | + Serial.println("wakeup"); |
| 167 | + GPS.wakeup(); |
| 168 | + Serial.print("wait location ... "); |
| 169 | + // wait for new GPS data to become available |
| 170 | + unsigned long startMillis = millis(); |
| 171 | + while (!GPS.available()); |
| 172 | + unsigned long endMillis = millis(); |
| 173 | + Serial.print(endMillis - startMillis); |
| 174 | + Serial.println(" ms"); |
| 175 | + |
| 176 | + // read GPS values |
| 177 | + |
| 178 | + float latitude = GPS.latitude(); |
| 179 | + float longitude = GPS.longitude(); |
| 180 | + float altitude = GPS.altitude(); |
| 181 | + int satellites = GPS.satellites(); |
| 182 | + |
| 183 | + // print GPS values |
| 184 | + |
| 185 | + Serial.println(); |
| 186 | + Serial.print("Location: "); |
| 187 | + Serial.print(latitude, 7); |
| 188 | + Serial.print(", "); |
| 189 | + Serial.println(longitude, 7); |
| 190 | + Serial.print("Altitude: "); |
| 191 | + Serial.print(altitude); |
| 192 | + Serial.println("m"); |
| 193 | + Serial.print("Number of satellites: "); |
| 194 | + Serial.println(satellites); |
| 195 | + Serial.println(); |
| 196 | +} |
| 197 | +``` |
0 commit comments