Skip to content

Commit 6308ba2

Browse files
jhansson-ardlukdog
authored andcommitted
adding missing tutorial for mkr gps shield
1 parent 0d12f94 commit 6308ba2

File tree

1 file changed

+274
-0
lines changed
  • content/hardware/01.mkr/02.shields/mkr-gps-shield/tutorials/getting-started

1 file changed

+274
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,274 @@
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 the pin 1.
39+
40+
The module runs at a maximum voltage of 3.3V and it is not 5V 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 5V 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 and the
51+
52+
```c
53+
/*
54+
55+
GPS Location
56+
57+
This sketch uses the GPS to determine the location of the board
58+
59+
and prints it to the Serial monitor.
60+
61+
Circuit:
62+
63+
- MKR board
64+
65+
- MKR GPS attached via I2C cable
66+
67+
This example code is in the public domain.
68+
69+
*/
70+
71+
#include <Arduino_MKRGPS.h>
72+
73+
void setup() {
74+
75+
// initialize serial communications and wait for port to open:
76+
77+
Serial.begin(9600);
78+
79+
while (!Serial) {
80+
81+
; // wait for serial port to connect. Needed for native USB port only
82+
83+
}
84+
85+
// If you are using the MKR GPS as shield, change the next line to pass
86+
87+
// the GPS_MODE_SHIELD parameter to the GPS.begin(...)
88+
89+
if (!GPS.begin()) {
90+
91+
Serial.println("Failed to initialize GPS!");
92+
93+
while (1);
94+
95+
}
96+
}
97+
98+
void loop() {
99+
100+
// check if there is new GPS data available
101+
102+
if (GPS.available()) {
103+
104+
// read GPS values
105+
106+
float latitude = GPS.latitude();
107+
108+
float longitude = GPS.longitude();
109+
110+
float altitude = GPS.altitude();
111+
112+
float speed = GPS.speed();
113+
114+
int satellites = GPS.satellites();
115+
116+
// print GPS values
117+
118+
Serial.print("Location: ");
119+
120+
Serial.print(latitude, 7);
121+
122+
Serial.print(", ");
123+
124+
Serial.println(longitude, 7);
125+
126+
Serial.print("Altitude: ");
127+
128+
Serial.print(altitude);
129+
130+
Serial.println("m");
131+
132+
Serial.print("Ground speed: ");
133+
134+
Serial.print(speed);
135+
136+
Serial.println(" km/h");
137+
138+
Serial.print("Number of satellites: ");
139+
140+
Serial.println(satellites);
141+
142+
Serial.println();
143+
144+
}
145+
}
146+
```
147+
148+
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.
149+
150+
```c
151+
/*
152+
153+
GPS Location Standy
154+
155+
This sketch uses the GPS to determine the location of the board
156+
157+
and prints it to the Serial monitor.
158+
159+
It puts the GPS to in standby mode every 10 seconds, then wakes it up.
160+
161+
Circuit:
162+
163+
- MKR board
164+
165+
- MKR GPS attached via I2C cable
166+
167+
This example code is in the public domain.
168+
169+
*/
170+
171+
#include <Arduino_MKRGPS.h>
172+
173+
void setup() {
174+
175+
// initialize serial communications and wait for port to open:
176+
177+
Serial.begin(9600);
178+
179+
while (!Serial) {
180+
181+
; // wait for serial port to connect. Needed for native USB port only
182+
183+
}
184+
185+
// If you are using the MKR GPS as shield, change the next line to pass
186+
187+
// the GPS_MODE_SHIELD parameter to the GPS.begin(...)
188+
189+
if (!GPS.begin()) {
190+
191+
Serial.println("Failed to initialize GPS!");
192+
193+
while (1);
194+
195+
}
196+
}
197+
198+
void loop() {
199+
200+
// put the GPS in standby mode
201+
202+
Serial.println("standby");
203+
204+
GPS.standby();
205+
206+
// wait for 10 seconds
207+
208+
Serial.print("delay ");
209+
210+
for (int i = 0; i < 10; i++) {
211+
212+
delay(1000);
213+
214+
Serial.print(".");
215+
216+
}
217+
218+
Serial.println();
219+
220+
// wake up the GPS
221+
222+
Serial.println("wakeup");
223+
224+
GPS.wakeup();
225+
226+
Serial.print("wait location ... ");
227+
228+
// wait for new GPS data to become available
229+
230+
unsigned long startMillis = millis();
231+
232+
while (!GPS.available());
233+
234+
unsigned long endMillis = millis();
235+
236+
Serial.print(endMillis - startMillis);
237+
238+
Serial.println(" ms");
239+
240+
// read GPS values
241+
242+
float latitude = GPS.latitude();
243+
244+
float longitude = GPS.longitude();
245+
246+
float altitude = GPS.altitude();
247+
248+
int satellites = GPS.satellites();
249+
250+
// print GPS values
251+
252+
Serial.println();
253+
254+
Serial.print("Location: ");
255+
256+
Serial.print(latitude, 7);
257+
258+
Serial.print(", ");
259+
260+
Serial.println(longitude, 7);
261+
262+
Serial.print("Altitude: ");
263+
264+
Serial.print(altitude);
265+
266+
Serial.println("m");
267+
268+
Serial.print("Number of satellites: ");
269+
270+
Serial.println(satellites);
271+
272+
Serial.println();
273+
}
274+
```

0 commit comments

Comments
 (0)