Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

Commit 0af66e5

Browse files
committed
Adding PR #116
1 parent cd6b4dc commit 0af66e5

File tree

4 files changed

+217
-0
lines changed

4 files changed

+217
-0
lines changed

Diff for: examples/Example22_PowerOff/Example22_PowerOff.ino

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
Powering off a ublox GPS module
3+
By: bjorn
4+
unsurv.org
5+
Date: July 20th, 2020
6+
License: MIT. See license file for more information but you can
7+
basically do whatever you want with this code.
8+
9+
This example shows you how to turn off the ublox module to lower the power consumption.
10+
There are two functions: one just specifies a duration in milliseconds the other also specifies a pin on the GPS device to wake it up with.
11+
By driving a voltage from LOW to HIGH or HIGH to LOW on the chosen module pin you wake the device back up.
12+
Note: Doing so on the INT0 pin when using the regular powerOff(durationInMs) function will wake the device anyway. (tested on SAM-M8Q)
13+
Note: While powered off, you should not query the device for data or it might wake up. This can be used to wake the device but is not recommended.
14+
Works best when also putting your microcontroller to sleep.
15+
16+
Feel like supporting open source hardware?
17+
Buy a board from SparkFun!
18+
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
19+
NEO-M8P RTK: https://www.sparkfun.com/products/15005
20+
SAM-M8Q: https://www.sparkfun.com/products/15106
21+
22+
Hardware Connections:
23+
Plug a Qwiic cable into the GPS and a BlackBoard.
24+
To force the device to wake up you need to connect to a pin (for example INT0) seperately on the module.
25+
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
26+
Open the serial monitor at 115200 baud to see the output
27+
*/
28+
29+
#include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_Ublox_GPS
30+
SFE_UBLOX_GPS myGPS;
31+
32+
// define a digital pin capable of driving HIGH and LOW
33+
#define WAKEUP_PIN 5
34+
35+
// interrupt pin mapping
36+
#define GPS_RX 0
37+
#define GPS_INT0 1
38+
#define GPS_INT1 2
39+
#define GPS_SPI_CS 3
40+
41+
42+
void wakeUp() {
43+
44+
Serial.print("-- waking up module via pin " + String(WAKEUP_PIN));
45+
Serial.println(" on your microcontroller --");
46+
47+
digitalWrite(WAKEUP_PIN, LOW);
48+
delay(1000);
49+
digitalWrite(WAKEUP_PIN, HIGH);
50+
delay(1000);
51+
digitalWrite(WAKEUP_PIN, LOW);
52+
}
53+
54+
55+
void setup() {
56+
57+
pinMode(WAKEUP_PIN, OUTPUT);
58+
59+
Serial.begin(115200);
60+
while (!Serial); //Wait for user to open terminal
61+
Serial.println("SparkFun Ublox Example");
62+
63+
Wire.begin();
64+
65+
if (myGPS.begin() == false) //Connect to the Ublox module using Wire port
66+
{
67+
Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
68+
while (1);
69+
}
70+
71+
// Powering off for 20s, you should see the power consumption drop.
72+
Serial.println("-- Powering off module for 20s --");
73+
74+
myGPS.powerOff(20000);
75+
// myGPS.powerOffWithInterrupt(20000, GPS_INT0);
76+
77+
delay(10000);
78+
79+
// After 10 seconds wake the device via the specified pin on your microcontroller and module.
80+
wakeUp();
81+
}
82+
83+
void loop() {
84+
//Do nothing
85+
}

Diff for: keywords.txt

+2
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ setDynamicModel KEYWORD2
139139
getDynamicModel KEYWORD2
140140
powerSaveMode KEYWORD2
141141
getPowerSaveMode KEYWORD2
142+
powerOff KEYWORD2
143+
powerOffWithInterrupt KEYWORD2
142144

143145
configureMessage KEYWORD2
144146
enableMessage KEYWORD2

Diff for: src/SparkFun_Ublox_Arduino_Library.cpp

+128
Original file line numberDiff line numberDiff line change
@@ -2569,6 +2569,134 @@ uint8_t SFE_UBLOX_GPS::getPowerSaveMode(uint16_t maxWait)
25692569
return (payloadCfg[1]); // Return the low power mode
25702570
}
25712571

2572+
// Powers off the GPS device for a given duration to reduce power consumption.
2573+
// NOTE: Querying the device before the duration is complete, for example by "getLatitude()" will wake it up!
2574+
// Returns true if command has not been not acknowledged.
2575+
// Returns false if command has not been acknowledged or maxWait = 0.
2576+
boolean SFE_UBLOX_GPS::powerOff(uint32_t durationInMs, uint16_t maxWait)
2577+
{
2578+
// use durationInMs = 0 for infinite duration
2579+
if (_printDebug == true)
2580+
{
2581+
_debugSerial->print(F("Powering off for "));
2582+
_debugSerial->print(durationInMs);
2583+
_debugSerial->println(" ms");
2584+
}
2585+
2586+
// Power off device using UBX-RXM-PMREQ
2587+
packetCfg.cls = UBX_CLASS_RXM; // 0x02
2588+
packetCfg.id = UBX_RXM_PMREQ; // 0x41
2589+
packetCfg.len = 8;
2590+
packetCfg.startingSpot = 0;
2591+
2592+
// duration
2593+
// big endian to little endian, switch byte order
2594+
payloadCfg[0] = (durationInMs >> (8*0)) & 0xff;
2595+
payloadCfg[1] = (durationInMs >> (8*1)) & 0xff;
2596+
payloadCfg[2] = (durationInMs >> (8*2)) & 0xff;
2597+
payloadCfg[3] = (durationInMs >> (8*3)) & 0xff;
2598+
2599+
if (maxWait != 0)
2600+
{
2601+
// check for "not acknowledged" command
2602+
return (sendCommand(&packetCfg, maxWait) != SFE_UBLOX_STATUS_COMMAND_NACK);
2603+
}
2604+
else
2605+
{
2606+
sendCommand(&packetCfg, maxWait);
2607+
return false; // can't tell if command not acknowledged if maxWait = 0
2608+
}
2609+
}
2610+
2611+
// Powers off the GPS device for a given duration to reduce power consumption.
2612+
// While powered off it can be woken up by creating a falling or rising voltage edge on the specified pin.
2613+
// NOTE: The GPS seems to be sensitve to signals on the pins while powered off. Works best when Microcontroller is in deepsleep.
2614+
// NOTE: Querying the device before the duration is complete, for example by "getLatitude()" will wake it up!
2615+
// Returns true if command has not been not acknowledged.
2616+
// Returns false if command has not been acknowledged or maxWait = 0.
2617+
boolean SFE_UBLOX_GPS::powerOffWithInterrupt(uint32_t durationInMs, uint8_t wakeupPin, boolean forceWhileUsb, uint16_t maxWait)
2618+
{
2619+
// use durationInMs = 0 for infinite duration
2620+
if (_printDebug == true)
2621+
{
2622+
_debugSerial->print(F("Powering off for "));
2623+
_debugSerial->print(durationInMs);
2624+
_debugSerial->println(" ms");
2625+
}
2626+
2627+
// Power off device using UBX-RXM-PMREQ
2628+
packetCfg.cls = UBX_CLASS_RXM; // 0x02
2629+
packetCfg.id = UBX_RXM_PMREQ; // 0x41
2630+
packetCfg.len = 16;
2631+
packetCfg.startingSpot = 0;
2632+
2633+
payloadCfg[0] = 0x00; // message version
2634+
// bytes 1-3 are reserved
2635+
2636+
// duration
2637+
// big endian to little endian, switch byte order
2638+
payloadCfg[4] = (durationInMs >> (8*0)) & 0xff;
2639+
payloadCfg[5] = (durationInMs >> (8*1)) & 0xff;
2640+
payloadCfg[6] = (durationInMs >> (8*2)) & 0xff;
2641+
payloadCfg[7] = (durationInMs >> (8*3)) & 0xff;
2642+
2643+
// flags
2644+
payloadCfg[8] = 0x00;
2645+
payloadCfg[9] = 0x00;
2646+
payloadCfg[10] = 0x00;
2647+
2648+
// disables USB interface when powering off, defaults to true
2649+
if (forceWhileUsb)
2650+
{
2651+
payloadCfg[11] = 0x04;
2652+
}
2653+
else
2654+
{
2655+
payloadCfg[11] = 0x02;
2656+
}
2657+
2658+
// wakeUpSources
2659+
payloadCfg[12] = 0x00;
2660+
payloadCfg[13] = 0x00;
2661+
payloadCfg[14] = 0x00;
2662+
2663+
// wakeupPin mapping, defaults to EXINT0, limited to one pin for now
2664+
// last byte of wakeUpSources
2665+
uint8_t terminatingByte;
2666+
2667+
switch (wakeupPin)
2668+
{
2669+
case 0: // UART RX
2670+
terminatingByte = 0x08; // 0000 1000
2671+
break;
2672+
2673+
case 1: // EXINT 0
2674+
terminatingByte = 0x20; // 0010 0000
2675+
break;
2676+
2677+
case 2: // EXINT 1
2678+
terminatingByte = 0x40; // 0100 0000
2679+
break;
2680+
2681+
case 3: // SPI CS
2682+
terminatingByte = 0x80; // 1000 0000
2683+
break;
2684+
}
2685+
2686+
payloadCfg[15] = terminatingByte;
2687+
2688+
if (maxWait != 0)
2689+
{
2690+
// check for "not acknowledged" command
2691+
return (sendCommand(&packetCfg, maxWait) != SFE_UBLOX_STATUS_COMMAND_NACK);
2692+
}
2693+
else
2694+
{
2695+
sendCommand(&packetCfg, maxWait);
2696+
return false; // can't tell if command not acknowledged if maxWait = 0
2697+
}
2698+
}
2699+
25722700
//Change the dynamic platform model using UBX-CFG-NAV5
25732701
//Possible values are:
25742702
//PORTABLE,STATIONARY,PEDESTRIAN,AUTOMOTIVE,SEA,

Diff for: src/SparkFun_Ublox_Arduino_Library.h

+2
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,8 @@ class SFE_UBLOX_GPS
641641

642642
boolean powerSaveMode(bool power_save = true, uint16_t maxWait = 1100);
643643
uint8_t getPowerSaveMode(uint16_t maxWait = 1100); // Returns 255 if the sendCommand fails
644+
boolean powerOff(uint32_t durationInMs, uint16_t maxWait = 1100);
645+
boolean powerOffWithInterrupt(uint32_t durationInMs, uint8_t wakeupPin = 1, boolean forceWhileUsb = true, uint16_t maxWait = 1100);
644646

645647
//Change the dynamic platform model using UBX-CFG-NAV5
646648
boolean setDynamicModel(dynModel newDynamicModel = DYN_MODEL_PORTABLE, uint16_t maxWait = 1100);

0 commit comments

Comments
 (0)