Can someone do the work for me

I have built this Hollow Clock and the code they are using relies on the time to be kept by using the mills math. I want to keep the code the sameish, but use an RTC and every time the minute advances, advance the rotate loop to advance the hand 1 minute. I'm not good enough to rewrite someone else's code.

Any help, Thanks

// Please tune the following value if the clock gains or loses.
// Theoretically, standard of this value is 60000.
#define MILLIS_PER_MIN 59100 // milliseconds per a minute

// Motor and clock parameters
// 4096 * 90 / 12 = 30720
#define STEPS_PER_ROTATION 30720 // steps for a full turn of minute rotor


// wait for a single step of stepper
int delaytime = 2;

// ports used to control the stepper motor
// if your motor rotate to the opposite direction, 
// change the order as {2, 3, 4, 5};
int port[4] = {2, 3, 4, 5};

// sequence of stepper motor control
int seq[8][4] = {
  {  LOW, HIGH, HIGH,  LOW},
  {  LOW,  LOW, HIGH,  LOW},
  {  LOW,  LOW, HIGH, HIGH},
  {  LOW,  LOW,  LOW, HIGH},
  { HIGH,  LOW,  LOW, HIGH},
  { HIGH,  LOW,  LOW,  LOW},
  { HIGH, HIGH,  LOW,  LOW},
  {  LOW, HIGH,  LOW,  LOW}
};

void rotate(int step) {
  static int phase = 0;
  int i, j;
  int delta = (step > 0) ? 1 : 7;
  int dt = 20;

  step = (step > 0) ? step : -step;
  for(j = 0; j < step; j++) {
    phase = (phase + delta) % 8;
    for(i = 0; i < 4; i++) {
      digitalWrite(port[i], seq[phase][i]);
    }
    delay(dt);
    if(dt > delaytime) dt--;
  }
  // power cut
  for(i = 0; i < 4; i++) {
    digitalWrite(port[i], LOW);
  }
}

void setup() {
  pinMode(port[0], OUTPUT);
  pinMode(port[1], OUTPUT);
  pinMode(port[2], OUTPUT);
  pinMode(port[3], OUTPUT);
  rotate(-20); // for approach run
  rotate(20); // approach run without heavy load
  rotate(STEPS_PER_ROTATION / 60);
}

void loop() {
  static long prev_min = 0, prev_pos = 0;
  long min;
  static long pos;
  
  min = millis() / MILLIS_PER_MIN;
  if(prev_min == min) {
    return;
  }
  prev_min = min;
  pos = (STEPS_PER_ROTATION * min) / 60;
  rotate(-20); // for approach run
  rotate(20); // approach run without heavy load
  if(pos - prev_pos > 0) {
    rotate(pos - prev_pos);
  }
  prev_pos = pos;
}

There is a section for payed work. What's Your budget?

1 Like

The satisfaction of me learning from the code someone supplies. I will study it. Oh and some swamp land I own.

The goal for this forum is helping members to learn programming and grow. It's not a quick shop, private clinic, giving members new toys.
The link You posted uses cookies and that's generally not accepted among helpers.
Please extract the information and post it here.

Do you have details, drawings of the mechanism, motors etc ?
Do you have the physical parts for the clock face ?

What experience and tools do you have ?

You seem to have calls to a stepper motor library... but no library... and no function to rotate() the motor. Do you have the main sketch in an IDE with tabs of different files?

I have an Ender 3 printer
I have built all of the parts assembled it and it works with the supplied code. I have a lot of experience with electronics, but not a lot with coding. The clock will keep time ok, but I thought with an added RTC I could make it keep time very accurately.


In the mean time, have you picked out the RTC you want to use and have you bought it and have you tested it with a sample program?

Yes RTC returns correct time with sample program. All I need is the ability to trigger the rotate when the RTC changes the Min value. My problem is removing the old code and inserting something like this. Also I need to keep the power down in between movement, or the battery will never last

DateTime now = rtc.now();

  // Check if the minute has changed
  static int previousMinute = -1;
  if (now.minute() != previousMinute) {

//Trigger rotate 
 
    previousMinute = now.minute();
  }

That is very interesting. You want to watch for the minute to change, but do it without the Arduino running.

Thats just the code I want to insert. The original code is in my first post

What course is this for?

Send me the clock, or a copy of it, post a good schematic and mechanical drawings of same here and I will write the software for it to your specifications, subject to the laws of physics which may make some of your goals hard to,obtain, can't tell yet.

I might throw in some swamp land if you think that's a bad deal.

a7

Nice try :clown_face:

The original code works great, I just want it to keep time accurately. This is where I think the RTC would be a better fit.
Everything I did can be found here

try this loop..

oid loop() {
  static long prev_min = 0, prev_pos = 0;
  long mins;
  static long pos;

  static unsigned long lastSync = 1001;
  int intervalSync = 1000;
  static byte lastRealMin = 0;
  unsigned long now = millis();
  if (now - lastSync >= intervalSync) {
    lastSync = now;
    DateTime dt = rtc.now();
    if (dt.minute() != lastRealMin) {
      lastRealMin = dt.minute();
      mins++;
    }
  }

  if (prev_min == mins) {
    return;
  }
  prev_min = mins;
  pos = (STEPS_PER_ROTATION * mins) / 60;
  rotate(-20); // for approach run
  rotate(20); // approach run without heavy load
  if (pos - prev_pos > 0) {
    rotate(pos - prev_pos);
  }
  prev_pos = pos;
}

should be the same except using rtc to increment mins instead of millis..

have fun.. ~q

I'll give it a try tomorrow, Thank you

You can use the RTC alarm to wake up the Arduino every minute and move the motor, then go back to sleep.

This will reduce your battery drain by the time the motor runs divided by 60. For example, if it takes 2 seconds to run the motor, it would last 30 times longer.

See

for a start on low power.

a7

I don't see any mention of an Arduino that this code is running on. I don't see any room in the photos for one. What model is it and where is it hidden?

An alternative to an RTC could be a 32KHz watch crystal (+2x caps). However, this needs to be connected to the microprocessor's crystal pins directly, so isn't possible on any regular arduino board. You would probably need to build your own simple board using a bare chip. Attiny84 should have enough pins: