Get Free Shipping & Prusaments with the Prusa XL Summer Deal!
harry blackman 9
harry blackman
@HaraldSchwar_1160461
published a new model June 8 at 8:20 PM
June 8 at 8:20 PM

Ctrl + Enter to send Enter to add a new line
harry blackman 9
harry blackman
@HaraldSchwar_1160461
published a new model February 25, 2024 at 3:49 PM
February 25, 2024 at 3:49 PM

Ctrl + Enter to send Enter to add a new line
harry blackman 9
harry blackman
@HaraldSchwar_1160461
published a new model February 20, 2024 at 8:22 PM
February 20, 2024 at 8:22 PM

I literally just did this myself a few days ago, I modernized and optimized the code as well as used interrupts instead of polling the rtc every loop frame which should improve accuracy a bit more and be less intensive on the rtc and nano, feel free to use it if you want (will just have to modify pins for the ones you use and add a wire from sqw to pin 2, also there is no reason to keep a battery in the rtc since we don't need an actual time kept just counting seconds)

PS printables is removing spacing and tabs, not sure how to format in a comment

#include <RTClib.h>
constexpr uint8_t pins[4] = { 5, 6, 7, 8 };
constexpr uint8_t clock_interrupt_pin = 2;
constexpr int16_t one_minute_steps = 1536;
constexpr uint8_t delay_time = 3;
constexpr uint8_t sequence[4][4] = {
{0, 0, 1, 0},
{0, 0, 0, 1},
{1, 0, 0, 0},
{0, 1, 0, 0}
};
RTC_DS3231 rtc;
volatile bool minute_flag = false;
void Rotate(int32_t step) {
static int32_t phase = 0;
const int32_t delta = (step > 0) ? 1 : 3;
int dt = 20;
step = (step > 0) ? step : -step;
for (int j = 0; j < step; j++) {
phase = (phase + delta) % 4;
for (int i = 0; i < 4; i++) {
digitalWrite(pins[i], sequence[phase][i]);
}
delay(dt);
if (dt > delay_time)
dt--;
}
for (const auto& pin : pins)
digitalWrite(pin, 0);
}
void RotateClock() {
Rotate(-10);
Rotate(10);
Rotate(one_minute_steps);
}
void MinuteInterrupt() {
minute_flag = true;
}
void setup() {
Serial.begin(115200);
delay(1000);
for (const auto pin : pins)
pinMode(pin, 1);
if (!rtc.begin())
Serial.println("Couldn't find RTC");
else
Serial.println("RTC found!");
rtc.adjust(DateTime(2024, 02, 16, 0, 0, 00));
rtc.disable32K();
pinMode(clock_interrupt_pin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(clock_interrupt_pin), MinuteInterrupt, FALLING);
rtc.writeSqwPinMode(DS3231_OFF);
rtc.clearAlarm(1);
rtc.clearAlarm(2);
rtc.disableAlarm(1);
if (!rtc.setAlarm2(DateTime(0, 0, 0, 0, 0, 0), DS3231_A2_PerMinute)) {
Serial.println("Error, alarm wasn't set!");
} else {
Serial.print("Current time: ");
char date[] = "DDD, DD MMM YYYY hh:mm:ss";
rtc.now().toString(date);
Serial.println(date);
}
}
void loop() {
if (minute_flag) {
rtc.clearAlarm(2);
minute_flag = false;
RotateClock();
}
} (edited)

Any idea why on some (clone) nano's when I hit the reset button, it rotates the stepper twice? Also doesnt seem to keep accurate time. Is this a problem with the boards I am using or am I doing something wrong?

Ctrl + Enter to send Enter to add a new line
harry blackman 9
harry blackman
@HaraldSchwar_1160461
published a new model February 14, 2024 at 9:40 PM
February 14, 2024 at 9:40 PM

Ctrl + Enter to send Enter to add a new line
All items loaded