Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2defcfc

Browse files
committedJan 3, 2022
Create SARA-R5_Example11_Clock.ino
1 parent a91973e commit 2defcfc

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed
 
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
3+
SARA-R5 Example
4+
===============
5+
6+
Clock
7+
8+
Written by: Paul Clark
9+
Date: January 3rd 2022
10+
11+
This example demonstrates how to use the clock function to read the time from the SARA-R5.
12+
13+
Note: the clock will be set to network time only if your network supports NITZ (Network Identity and Time Zone)
14+
15+
Feel like supporting open source hardware?
16+
Buy a board from SparkFun!
17+
18+
Licence: MIT
19+
Please see LICENSE.md for full details
20+
21+
*/
22+
23+
#include <SparkFun_u-blox_SARA-R5_Arduino_Library.h> //Click here to get the library: http://librarymanager/All#SparkFun_u-blox_SARA-R5_Arduino_Library
24+
25+
// Uncomment the next line to connect to the SARA-R5 using hardware Serial1
26+
#define saraSerial Serial1
27+
28+
// Uncomment the next line to create a SoftwareSerial object to pass to the SARA-R5 library instead
29+
//SoftwareSerial saraSerial(8, 9);
30+
31+
// Create a SARA_R5 object to use throughout the sketch
32+
// Usually we would tell the library which GPIO pin to use to control the SARA power (see below),
33+
// but we can start the SARA without a power pin. It just means we need to manually
34+
// turn the power on if required! ;-D
35+
SARA_R5 mySARA;
36+
37+
// Create a SARA_R5 object to use throughout the sketch
38+
// We need to tell the library what GPIO pin is connected to the SARA power pin.
39+
// If you're using the MicroMod Asset Tracker and the MicroMod Artemis Processor Board,
40+
// the pin name is G2 which is connected to pin AD34.
41+
// Change the pin number if required.
42+
//SARA_R5 mySARA(34);
43+
44+
void setup()
45+
{
46+
Serial.begin(115200); // Start the serial console
47+
48+
// Wait for user to press key to begin
49+
Serial.println(F("SARA-R5 Example"));
50+
51+
//mySARA.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial
52+
53+
// For the MicroMod Asset Tracker, we need to invert the power pin so it pulls high instead of low
54+
// Comment the next line if required
55+
mySARA.invertPowerPin(true);
56+
57+
// Initialize the SARA
58+
if (mySARA.begin(saraSerial, 9600) )
59+
{
60+
Serial.println(F("SARA-R5 connected!"));
61+
}
62+
else
63+
{
64+
Serial.println(F("Unable to communicate with the SARA."));
65+
Serial.println(F("Manually power-on (hold the SARA On button for 3 seconds) on and try again."));
66+
while (1) ; // Loop forever on fail
67+
}
68+
Serial.println();
69+
70+
// Make sure automatic time zone updates are enabled
71+
if (mySARA.autoTimeZone(true) != SARA_R5_SUCCESS)
72+
Serial.println(F("Enable autoTimeZone failed!"));
73+
74+
// Read and print the clock as a String
75+
String theTime = mySARA.clock();
76+
Serial.println(theTime);
77+
78+
// Read and print the hour, minute, etc. separately
79+
uint8_t year, month, day, hour, minute, second;
80+
int8_t timeZone;
81+
if (mySARA.clock( &year, &month, &day, &hour, &minute, &second, &timeZone ) == SARA_R5_SUCCESS)
82+
// Note: not all Arduino boards implement printf correctly. The formatting may not be correct on some boards.
83+
// Note: the timeZone is defined in 15 minute increments, not hours. -28 indicates the time zone is 7 hours behind UTC/GMT.
84+
Serial.printf("%02d/%02d/%02d %02d:%02d:%02d %+d\r\n", year, month, day, hour, minute, second, timeZone);
85+
86+
}
87+
88+
void loop()
89+
{
90+
// Nothing to do here
91+
}

0 commit comments

Comments
 (0)
Please sign in to comment.