Skip to content

Commit bd91c64

Browse files
committed
Add clock example
1 parent dc56f10 commit bd91c64

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#include "SparkFun_u-blox_Cellular_Arduino_Library.h"
2+
3+
// Uncomment the line below that you need for Serial on your platform
4+
#define mySerial Serial1
5+
// SoftwareSerial mySerial(16, 17);
6+
7+
// Uncomment the module you're using. If your module is not listed below, then
8+
// it's not supported for this example
9+
UBX_CELL myModule; // This example works with all modules, so the base class can be used
10+
// UBX_CELL myModule; // Base SARA-R5 class
11+
// UBX_CELL00S myModule;
12+
// UBX_CELL00S_01B myModule;
13+
// UBX_CELL00S_61B myModule;
14+
// UBX_CELL10M8S_61B myModule;
15+
// UBX_CELL10S myModule;
16+
// LARA_R6 myModule; // Base LARA-R6 class
17+
// LARA_R6001 myModule;
18+
// LARA_R6001D myModule;
19+
// LARA_R6401 myModule;
20+
// LARA_R6401D myModule;
21+
// LARA_R6801_00B myModule;
22+
// LARA_R6801D myModule;
23+
24+
void setup()
25+
{
26+
String currentOperator = "";
27+
28+
Serial.begin(115200); // Start the serial console
29+
30+
// Wait for user to press key to begin
31+
Serial.println(F("u-blox Cellular Example 7 - Clock"));
32+
Serial.println(F("Press any key to begin"));
33+
34+
while (!Serial.available()) // Wait for the user to press a key (send any serial character)
35+
;
36+
while (Serial.available()) // Empty the serial RX buffer
37+
Serial.read();
38+
39+
Serial.println(F("Beginning..."));
40+
41+
// myModule.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial
42+
43+
// For the MicroMod Asset Tracker, we need to invert the power pin so it pulls high instead of low
44+
// Uncomment the next line if required
45+
// myModule.invertPowerPin(true);
46+
47+
// Initialize the module
48+
if (myModule.begin(mySerial, UBX_CELL_DEFAULT_BAUD_RATE) )
49+
{
50+
Serial.println(F("Module connected!"));
51+
}
52+
else
53+
{
54+
Serial.println(F("Unable to communicate with the module."));
55+
Serial.println(F("Manually power-on (hold the module's On button for 3 seconds) and try again."));
56+
while (1) ; // Loop forever on fail
57+
}
58+
Serial.println();
59+
60+
// Make sure automatic time zone updates are enabled
61+
if (myModule.autoTimeZone(true) != UBX_CELL_SUCCESS)
62+
Serial.println(F("Enable autoTimeZone failed!"));
63+
64+
// Read and print the clock as a String
65+
String theTime = myModule.clock();
66+
Serial.println(theTime);
67+
68+
// Read and print the hour, minute, etc. separately
69+
uint8_t year, month, day, hour, minute, second;
70+
int8_t timeZone;
71+
if (myModule.clock( &year, &month, &day, &hour, &minute, &second, &timeZone ) == UBX_CELL_SUCCESS)
72+
// Note: not all Arduino boards implement printf correctly. The formatting may not be correct on some boards.
73+
// Note: the timeZone is defined in 15 minute increments, not hours. -28 indicates the time zone is 7 hours behind UTC/GMT.
74+
Serial.printf("%02d/%02d/%02d %02d:%02d:%02d %+d\r\n", year, month, day, hour, minute, second, timeZone);
75+
}
76+
77+
void loop()
78+
{
79+
// Nothing to do here
80+
}

0 commit comments

Comments
 (0)