Small coding project est 15 min $10 via paypal

Hi I would like to pay someone to code a simple time based sketch. I think $10 via paypal is fair; it should take no more than 15 min for someone who knows what they are doing. This may evolve into a more substantial project over time to include optical counter, rotary encoder with menus and 4 independent motors…but I need to prove out hardware capabilities first.

Objective
Run a stepper motor routine based on current time from a real time clock. I would like the motor routine to run from 07:00 to 20:00 and then rest until 07:00 when it starts again.

Current code is below the motor runs but I don’t know how to add the time constraint.

Thanks

Hardware
Arduino Uno

Adafruit Motor/ Stepper/ Servo v2

RTC Holdding DS3231 AT24C32 IIC Module Precision Real Time Clock Memory Module

#include <config.h>
#include <ds3231.h>

#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"

// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61); 

// Connect a stepper motor with 200 steps per revolution (1.8 degree)
// to motor port #2 (M3 and M4)
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2);

#define BUFF_MAX 128

uint8_t time[8];
char recv[BUFF_MAX];
unsigned int recv_size = 0;
unsigned long prev, interval = 1000;


void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Stepper test!");

  AFMS.begin(1600);  // create with the default frequency 1.6KHz
  //AFMS.begin(1000);  // OR with a different frequency, say 1KHz
  
  myMotor->setSpeed(30);  // 10 rpm   
  int stepNum = 0; stepNum < 5; stepNum++;
  
   Serial.begin(9600);
    Wire.begin();
    DS3231_init(DS3231_INTCN);
    memset(recv, 0, BUFF_MAX);
    Serial.println("GET time");
    
    //Serial.println ("Setting time");
    //parse_cmd ("T173413620122014",16); used to reset time sec,min,hrs,day of week1-7,day of month, month, year
    
}
 
void loop()  {
  
    
  
 delay(2000);
  Serial.println("Single coil steps");
  myMotor->step(1000, FORWARD, MICROSTEP);
 delay(1000); 
     
  myMotor->step(1000, BACKWARD, MICROSTEP); 
  delay(1000);
}

If you dont know how to do it then how do you know how long it will take :wink:

But basically you just need to test that the seconds in the day are greater than 25200 and less than 79200

so a bit of code like this

if (seconds() > 25200  && seconds() < 79200)
{

//run your steeper here

}

You also have to set your RTC to be the correct time and then use the time sync to sync the arduino time to the RTC.

BTW this is pseudo code and will not compile.

Cheers Pete

Pete I estimated 15 min, if that is not reasonable let me know what is. I know $10 is not a lot of $$ it's more of a token of thanks. What do you think is fair for this code? PM me if you have interest in writing the code. If the project too small and not worth your time I understand. I may have to go to Elance but I thought I would try here first.

thx
Scott

someone who can do this please reply with a minimum it appears $10 was too low. I would like to get this done and am willing to pay for it.

thanks

Quick and dirty. I’ve added three lines which you need to replace with code that works with the library you have:

#include <config.h>
#include <ds3231.h>

#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"

// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61); 

// Connect a stepper motor with 200 steps per revolution (1.8 degree)
// to motor port #2 (M3 and M4)
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2);

#define BUFF_MAX 128

uint8_t time[8];
char recv[BUFF_MAX];
unsigned int recv_size = 0;
unsigned long prev, interval = 1000;


void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Stepper test!");

  AFMS.begin(1600);  // create with the default frequency 1.6KHz
  //AFMS.begin(1000);  // OR with a different frequency, say 1KHz
  
  myMotor->setSpeed(30);  // 10 rpm   
  int stepNum = 0; stepNum < 5; stepNum++;
  
   Serial.begin(9600);
    Wire.begin();
    DS3231_init(DS3231_INTCN);
    memset(recv, 0, BUFF_MAX);
    Serial.println("GET time");
    
    //Serial.println ("Setting time");
    //parse_cmd ("T173413620122014",16); used to reset time sec,min,hrs,day of week1-7,day of month, month, year
    
}
 
void loop()  {
  // Read clock
  // If hour =>7 and Hour < 20 { 
  
 delay(2000);
  Serial.println("Single coil steps");
  myMotor->step(1000, FORWARD, MICROSTEP);
 delay(1000); 
     
  myMotor->step(1000, BACKWARD, MICROSTEP); 
  delay(1000);
  //}
}

ty dannable. I will try this out.

Hi again

So I got part of the sketch working It will turn on at 7am but I have to use only the hour (now.hour() instead of the whole time string including min and sec. I the following thinking it would contain the whole time string:
DateTime()
Time.now()
RTC.now() none worked. I cant identify the function that calls for the entire time string.

The other issue I am having is that I can’t get the process to stop once it hits 8pm. The if (now.hour()>=7) works fine to start the process but I have tried every combination I can think of to make it only work if hour = >7 AND hour<=20

here is that part of code, full code is also attached.

Thanks

if ((now.hour()<=13)) //&& (now.hour()<=20)) //starting at 7am works but ending does not.

//this workd but the “and <20 hour” is not I would like to run this from 7am to 8pm
//I have added an else statement, I suppose I could use a realy really long delay
// I did try if (now.hour()>=7) && if (now.hour()<=20)
// if (now.hour()>=7 & >20) also if (now.hour()>=7 && >=20)
{

delay(2000);
Serial.println("5 Turns CL ");
myMotor->step(1000, FORWARD, MICROSTEP);
myMotor->release();
delay(1000);

Serial.println(“5 Turns CCL”);
myMotor->step(1000, BACKWARD, MICROSTEP);
myMotor->release();
delay(10000);

}

#include <Wire.h>
#include <SPI.h>
#include <RTClib.h>
#include <RTC_DS3231.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"


RTC_DS3231 RTC;
Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2);

// easier to reference here...see .h file for more options
//#define SQW_FREQ DS3231_SQW_FREQ_1      //  0b00000000  1Hz
#define SQW_FREQ DS3231_SQW_FREQ_1024     //0b00001000   1024Hz
//#define SQW_FREQ DS3231_SQW_FREQ_4096  // 0b00010000   4096Hz
//#define SQW_FREQ DS3231_SQW_FREQ_8192 //0b00011000      8192Hz

#define PWM_COUNT 1020   //determines how often the LED flips
#define LOOP_DELAY 5000 //ms delay time in loop

#define RTC_SQW_IN 5     // input square wave from RTC into T1 pin (D5)
                               //WE USE TIMER1 so that it does not interfere with Arduino delay() command
#define INT0_PIN   2     // INT0 pin for 32kHz testing?
#define LED_PIN    9     // random LED for testing...tie to ground through series resistor..
#define LED_ONBAORD 13   // Instead of hooking up an LED, the nano has an LED at pin 13.

//----------- GLOBALS  -------------------------

volatile long TOGGLE_COUNT = 0;


//####################################################################################
// INTERRUPT SERVICE ROUTINES
//####################################################################################

//ISR(TIMER0_COMPA_vect) {
  //digitalWrite(LED_PIN, !digitalRead(LED_PIN));      // ^ 1);
//}
    
ISR(TIMER1_COMPA_vect) {
  //digitalWrite(LED_PIN, !digitalRead(LED_PIN));      // ^ 1);
  digitalWrite(LED_PIN, !digitalRead(LED_PIN));
  digitalWrite(LED_ONBAORD, !digitalRead(LED_ONBAORD)); //useful on nano's and some other 'duino's
  TOGGLE_COUNT++;
}    

ISR(INT0_vect) {
  // Do something here
  //digitalWrite(LED_PIN, !digitalRead(LED_PIN));      // ^ 1);
   //TOGGLE_COUNT++;
}


//####################################################################################
// SETUP
//####################################################################################
void setup () {
    Serial.begin(57600);
    
    pinMode(LED_PIN, OUTPUT);
    digitalWrite(LED_PIN, LOW);  
    pinMode(RTC_SQW_IN, INPUT);
    pinMode(INT0_PIN, INPUT);
    AFMS.begin(1600); 
  myMotor->setSpeed(30);  // 30 rpm   
  int stepNum = 0; stepNum < 5; stepNum++;    
    
    //--------RTC SETUP ------------
    Wire.begin();
    RTC.begin();

    if (! RTC.isrunning()) {
      Serial.println("RTC is NOT running!");
      // following line sets the RTC to the date & time this sketch was compiled
      RTC.adjust(DateTime(__DATE__, __TIME__));
    }
  
    DateTime now = RTC.now();
    DateTime compiled = DateTime(__DATE__, __TIME__);
    if (now.unixtime() < compiled.unixtime()) {
      //Serial.println("RTC is older than compile time!  Updating");
      RTC.adjust(DateTime(__DATE__, __TIME__));
    }
    
    RTC.enable32kHz(true);
    RTC.SQWEnable(true);
    RTC.BBSQWEnable(true);
    RTC.SQWFrequency( SQW_FREQ );
  
    char datastr[100];
    RTC.getControlRegisterData( datastr[0]  );
    Serial.print(  datastr );
 
  
  
    //--------INT 0---------------
    EICRA = 0;      //clear it
    EICRA |= (1 << ISC01);
    EICRA |= (1 << ISC00);   //ISC0[1:0] = 0b11  rising edge INT0 creates interrupt
    EIMSK |= (1 << INT0);    //enable INT0 interrupt
        
    //--------COUNTER 1 SETUP -------
    setupTimer1ForCounting((int)PWM_COUNT); 
    printTimer1Info();   
}


//####################################################################################
// MAIN
//####################################################################################
void loop () {
    
  
    DateTime now = RTC.now();
    
    RTC.forceTempConv(true);  //DS3231 does this every 64 seconds, we are simply testing the function here
    float temp_float = RTC.getTempAsFloat();
    int16_t temp_word = RTC.getTempAsWord();
    int8_t temp_hbyte = temp_word >> 8;
    int8_t temp_lbyte = temp_word &= 0x00FF;
    
    
    
  
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.print(' ');
    
    //Serial.print(now.month(), DEC);
    //Serial.print('/');
   // Serial.print(now.day(), DEC);
   // Serial.print(now.year(), DEC);
   // Serial.print('/');
    
    Serial.println();
    
    delay(LOOP_DELAY);
    
    //Display temps
    
    
    
    Serial.print(' ');
    Serial.print(temp_hbyte, DEC);
    Serial.print(".");
    Serial.print(temp_lbyte, DEC);
    Serial.println();
    
    Serial.println();
    
    // time constraint below
    
    //if (DateTime()>=07:00:00)  didnt work
 
    if ((now.hour()<=13)) //&& (now.hour()<=20))  //starting at 7am works but ending does not.
   
                        //this  workd but the "and <20 hour" is not  I would like to run this from 7am to 8pm
                        //I have added an else statement, I suppose I could use a realy really long delay
                        // I did try if (now.hour()>=7) && if (now.hour()<=20)
                        // if (now.hour()>=7 & >20) also if (now.hour()>=7 && >=20) 
    {
    
    delay(2000);
      Serial.println("5 Turns CL ");  
  myMotor->step(1000, FORWARD, MICROSTEP);
  myMotor->release();
 delay(1000); 
 
     Serial.println("5 Turns CCL");
  myMotor->step(1000, BACKWARD, MICROSTEP); 
   myMotor->release();
   delay(10000);
  
 
  
  //else 
// {
 //  delay (30000);
 //}
 
 
 
    
    delay(LOOP_DELAY);

Try:

if ((now.hour()>=7) && (now.hour()<=20))

That worked.

I am trying to build a very basic version of this:

Thanks

scott06903:
That worked.

I am trying to build a very basic version of this:

Building a watch winder - Christopher Ward Forum

Thanks

Very nice!