-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
sdivarci
authored and
sdivarci
committed
Sep 7, 2022
0 parents
commit 74b0d1e
Showing
38 changed files
with
10,440 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Analog RTC Lib | ||
|
||
AnalogRTCLib package includes arduino driver and usecase examples for MAXIM/ADI RTCs. | ||
Supported part numbers: | ||
|
||
- [MAX31331](https://www.maximintegrated.com/en/products/analog/MAX31331.html) | ||
- [MAX31334](https://www.maximintegrated.com/en/products/analog/MAX31334.html) | ||
- [MAX31328](https://www.maximintegrated.com/en/products/analog/real-time-clocks/MAX31328.html) | ||
- [MAX31341](https://www.maximintegrated.com/en/products/analog/real-time-clocks/MAX31341B.html) | ||
- [MAX31343](https://www.maximintegrated.com/en/products/analog/real-time-clocks/MAX31343.html) | ||
|
||
## How to install | ||
There are two main options to install library: | ||
### Option 1: | ||
1. Open Arduino IDE | ||
2. Go into Tools -> Manage Libraries... | ||
3. Search for AnalogRTCLib | ||
4. Click install button | ||
|
||
### Option 2: | ||
1. Dowload repository as .zip file | ||
2. Rename .zip file as "AnalogRTCLib.zip" | ||
3. Open Arduino IDE | ||
4. Go into Sketch -> Include Library -> Add .ZIP Library... | ||
5. Browse the AnalogRTCLib.zip location | ||
6. Click Open | ||
|
||
## How to build and load an example | ||
1. After installation open Arduino IDE | ||
2. Go into Files -> Examples -> AnalogRTCLib | ||
3. Select the part number you would like to use | ||
4. Select an example | ||
5. (If needs) Update example pin connection in example to it match with your target board. | ||
|
||
![Select an example](./Images/how_to_build/1_select_an_example.png) | ||
|
||
6. Plug your Arduino board to PC via USB cable. | ||
7. Select board type and serial port by navigating to | ||
Tools->Board | ||
Tools->Ports | ||
|
||
![Select board and port](./Images/how_to_build/2_select_port.png) | ||
|
||
8. Click right arrow button to build and load it | ||
|
||
![Build and load image](./Images/how_to_build/3_build_and_load_image.png) | ||
|
||
9. Please check output to see whether load succeeded or not | ||
|
||
![Output screen](./Images/how_to_build/4_after_load_output_screen.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#include <AnalogRTCLibrary.h> | ||
|
||
MAX31328 rtc(&Wire, MAX3128_I2C_ADDRESS); | ||
|
||
// Pin Number that connects to MAX31328 interrupt pin | ||
// Please update pin_inta depend on your target board connection | ||
int pin_inta = 2; | ||
|
||
char time_char_buffer[40]; | ||
struct tm rtc_ctime; | ||
|
||
void print_time(void) { | ||
|
||
rtc.get_time(&rtc_ctime); | ||
|
||
strftime(time_char_buffer, sizeof(time_char_buffer), "%Y-%m-%d %H:%M:%S", &rtc_ctime); | ||
Serial.println(time_char_buffer); | ||
} | ||
|
||
void setup() { | ||
int ret; | ||
|
||
Serial.begin(115200); | ||
Serial.println("---------------------"); | ||
Serial.println("MAX31328 ALARM1 use case example:"); | ||
Serial.println("MAX31328 will be configured to generate periodic alarm."); | ||
Serial.println("Note: You may need to unplug and plug target board while switching between examples, "); | ||
Serial.println("to previous sensor configuration to be deleted."); | ||
Serial.println(" "); | ||
|
||
// Set alarm pin as input | ||
pinMode(pin_inta, INPUT); | ||
|
||
rtc.begin(); | ||
|
||
rtc_ctime.tm_year = 121; // years since 1900 | ||
rtc_ctime.tm_mon = 10; // 0-11 | ||
rtc_ctime.tm_mday = 24; // 1-31 | ||
rtc_ctime.tm_hour = 15; // 0-23 | ||
rtc_ctime.tm_min = 10; // 0-59 | ||
rtc_ctime.tm_sec = 0; // 0-61 | ||
// | ||
rtc_ctime.tm_yday = 0; // 0-365 | ||
rtc_ctime.tm_wday = 0; // 0-6 | ||
rtc_ctime.tm_isdst = 0; // Daylight saving flag | ||
|
||
ret = rtc.set_time(&rtc_ctime); | ||
if (ret) { | ||
Serial.println("Set time failed!"); | ||
} | ||
|
||
ret = rtc.set_alarm(MAX31328::ALARM1, &rtc_ctime, MAX31328::ALARM_PERIOD_EVERYSECOND); | ||
if (ret) { | ||
Serial.println("Set alarm failed!"); | ||
} | ||
|
||
ret = rtc.irq_enable(MAX31328::INTR_ID_ALARM1); | ||
if (ret) { | ||
Serial.println("IRQ enable failed!"); | ||
} | ||
|
||
// clear all irq flags on startup | ||
rtc.irq_clear_flag(); | ||
|
||
print_time(); // print current time | ||
} | ||
|
||
void loop() { | ||
|
||
//Serial.println("Tick"); | ||
|
||
int pin_state = digitalRead(pin_inta); | ||
|
||
if (pin_state == LOW) { | ||
print_time(); | ||
rtc.irq_clear_flag(MAX31328::INTR_ID_ALARM1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#include <MaxEssentialToolkit.h> | ||
|
||
MAX31328 rtc(&Wire, MAX3128_I2C_ADDRESS); | ||
|
||
// Pin Number that connects to MAX31328 interrupt pin | ||
// Please update pin_inta depend on your target board connection | ||
int pin_inta = 2; | ||
|
||
char time_char_buffer[40]; | ||
struct tm rtc_ctime; | ||
|
||
void print_time(void) { | ||
|
||
rtc.get_time(&rtc_ctime); | ||
|
||
strftime(time_char_buffer, sizeof(time_char_buffer), "%Y-%m-%d %H:%M:%S", &rtc_ctime); | ||
Serial.println(time_char_buffer); | ||
} | ||
|
||
void setup() { | ||
int ret; | ||
|
||
Serial.begin(115200); | ||
Serial.println("---------------------"); | ||
Serial.println("MAX31328 ALARM2 use case example:"); | ||
Serial.println("MAX31328 will be configured to generate periodic alarm."); | ||
Serial.println("Note: You may need to unplug and plug target board while switching between examples, "); | ||
Serial.println("to previous sensor configuration to be deleted."); | ||
Serial.println(" "); | ||
|
||
// Set alarm pin as input | ||
pinMode(pin_inta, INPUT); | ||
|
||
rtc.begin(); | ||
|
||
rtc_ctime.tm_year = 121; // years since 1900 | ||
rtc_ctime.tm_mon = 10; // 0-11 | ||
rtc_ctime.tm_mday = 24; // 1-31 | ||
rtc_ctime.tm_hour = 15; // 0-23 | ||
rtc_ctime.tm_min = 10; // 0-59 | ||
rtc_ctime.tm_sec = 0; // 0-61 | ||
// | ||
rtc_ctime.tm_yday = 0; // 0-365 | ||
rtc_ctime.tm_wday = 0; // 0-6 | ||
rtc_ctime.tm_isdst = 0; // Daylight saving flag | ||
|
||
ret = rtc.set_time(&rtc_ctime); | ||
if (ret) { | ||
Serial.println("Set time failed!"); | ||
} | ||
|
||
ret = rtc.set_alarm(MAX31328::ALARM2, &rtc_ctime, MAX31328::ALARM_PERIOD_EVERYMINUTE); | ||
if (ret) { | ||
Serial.println("Set alarm failed!"); | ||
} | ||
|
||
ret = rtc.irq_enable(MAX31328::INTR_ID_ALARM2); | ||
if (ret) { | ||
Serial.println("IRQ enable failed!"); | ||
} | ||
|
||
// clear all irq flags on startup | ||
rtc.irq_clear_flag(); | ||
|
||
print_time(); // print current time | ||
} | ||
|
||
void loop() { | ||
|
||
//Serial.println("Tick"); | ||
|
||
int pin_state = digitalRead(pin_inta); | ||
|
||
if (pin_state == LOW) { | ||
print_time(); | ||
rtc.irq_clear_flag(MAX31328::INTR_ID_ALARM2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include <AnalogRTCLibrary.h> | ||
|
||
MAX31328 rtc(&Wire, MAX3128_I2C_ADDRESS); | ||
|
||
#define MAX_LOOP_COUNTER 250 | ||
|
||
void setup() { | ||
int ret; | ||
|
||
Serial.begin(115200); | ||
Serial.println("---------------------"); | ||
Serial.println("RTC temperature use case example:"); | ||
Serial.println("Temperature will be read periodically"); | ||
Serial.println(" "); | ||
|
||
rtc.begin(); | ||
} | ||
|
||
void loop() { | ||
int ret; | ||
|
||
delay(500); // wait a little | ||
|
||
ret = rtc.start_temp_conversion(); | ||
if (ret) { | ||
Serial.println("Start temperature converstion failed!"); | ||
return; | ||
} | ||
|
||
int counter = MAX_LOOP_COUNTER; // max wait time | ||
do { | ||
delay(1); | ||
if (rtc.is_temp_ready() == 0) { // returns 0 on success | ||
break; // means converstion done, so break | ||
} | ||
} while(--counter); | ||
|
||
if (counter == 0) { | ||
Serial.println("Timeout occur!"); | ||
} else { | ||
float temp = 0; | ||
ret = rtc.get_temp(temp); | ||
if (ret) { | ||
Serial.println("Temperature read failed!"); | ||
} else { | ||
Serial.print("Conversion time: "); | ||
Serial.print( MAX_LOOP_COUNTER - counter ); | ||
Serial.print(" ms"); | ||
|
||
Serial.print(" "); | ||
Serial.print("Temperature: "); | ||
Serial.print(temp, 2); | ||
Serial.println(" Celsius"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include <AnalogRTCLibrary.h> | ||
|
||
MAX31328 rtc(&Wire, MAX3128_I2C_ADDRESS); | ||
|
||
char time_char_buffer[40]; | ||
struct tm rtc_ctime; | ||
|
||
void setup() { | ||
int ret; | ||
|
||
Serial.begin(115200); | ||
Serial.println("---------------------"); | ||
Serial.println("Set get rtc use case example:"); | ||
Serial.println("RTC will be set to specific value then it will be read every second"); | ||
Serial.println(" "); | ||
|
||
rtc.begin(); | ||
|
||
rtc_ctime.tm_year = 121; // years since 1900 | ||
rtc_ctime.tm_mon = 10; // 0-11 | ||
rtc_ctime.tm_mday = 24; // 1-31 | ||
rtc_ctime.tm_hour = 15; // 0-23 | ||
rtc_ctime.tm_min = 10; // 0-59 | ||
rtc_ctime.tm_sec = 0; // 0-61 | ||
// | ||
rtc_ctime.tm_yday = 0; // 0-365 | ||
rtc_ctime.tm_wday = 0; // 0-6 | ||
rtc_ctime.tm_isdst = 0; // Daylight saving flag | ||
|
||
ret = rtc.set_time(&rtc_ctime); | ||
if (ret) { | ||
Serial.println("Set time failed!"); | ||
} | ||
} | ||
|
||
void loop() { | ||
int ret; | ||
|
||
delay(1000); // wait a little | ||
|
||
ret = rtc.get_time(&rtc_ctime); | ||
if (ret) { | ||
Serial.println("get_time failed!"); | ||
} else { | ||
strftime(time_char_buffer, 40, "%F %T", &rtc_ctime); | ||
Serial.println(time_char_buffer); | ||
} | ||
} |
Oops, something went wrong.