Help with a basic code

I am looking for someone to write a simple servo code.
Happy to pay a fair price.
I have now a big servo.
Freetronics eleven
I have it set up and running the sweep program well
I can pick out and change some variables and change timing and speed etc.
I desperately need help as I don't have time to create the code to do what I want
I go overseas working in a week and would like it done before I go.
I am very interested but a lot of other things are also needing to be done.
In an ideal world if someone could write the programme I would be very grateful.
My wish list would be as follows

Power comes on. The unit starts at 0 deg and stays there. 5 minutes moves to 10 deg then at 10 minutes to 20 deg, 15 minutes to 30 deg then at 20 minutes sweeps out continuous to 45 deg and back to 30 deg, 20 deg and 10 deg back to 0 to complete the loop.
Ideally this would happen with power switching off an on with a random timer and the unit just stopping wherever it is and then starting where it left off.
Thanks for everyones input
Gratefully appreciated.
This is very interesting stuff and can't wait to get my teeth in to it and play with it. I have many applications.
Wayne

Hello ,

This is not difficult but one question on something that is not clear. Since you are intending to turn this on and off with a power switch and it is not staying on all the time real-time events will not be possible. The Arduino does not have a battery backed RTC and so its timers would start at zero every time it was turned on and it would have no idea about the passages of time whilst it was turned off. If the loss of real-time is not important then you can store the last known position and direction into the EEPROM and then when the next 5 minute event takes place after power up advance it from there.

I can write it for you very quickly. Do you have a budget in mind for this.

Cheers Pete.

Hi Pete
Sorry I am not so literate with this.
Does that mean that that each section (deg) gets its 5 minutes then the sweep happens every 20 minutes regardless if the power has gone off and on 1 time or ten times.
So does the servo stay where it is and when the power comes back on it just carries on or does it start from that servo spot and think that is 0 degrees so the sweep ends up being in a different spot

My budget is just a fair price for time.

We can store the position of the servo and the direction of travel every time we move it. This can then be recalled when we power up. However since the Arduino does not know how long it is powered down for it has to assume that the next event will take place 5 minutes after power up and that this event is the next in the sequence of 0, 10,20,30,45,30,20,10,0 depending on what the last sequence position was stored in the EEPROM.

Cheers Pete.

whubbard:
My budget is just a fair price for time.

I PM'd you

So lets say if the power stops 1 minute before the second 5 minutes then it would retime the first 5 minutes over but if the power goes off on the 6th minute it will restart on the 5th minute or second lot of 5 minutes 5 to 10 minutes before moving to the 15 minute cycle.
Have I got that right. If so that would be good.
I would have control over the timer that powers the water pump and the arduino/servo so I can make them match.
It is to sweep leaves to one end of a pond to a filter pick up and you can push them one way and they will settle some other place away from the pick up so by sweeping will keep pushing the around until they get picked up by the drain..

Yep you have it :slight_smile:

I can paypal you when you are done
Thanks
Wayne

whubbard:
I can paypal you when you are done
Thanks
Wayne

OK leave it with me for an hour

Cheers Pete.

Thanks Mate
Its 3 AM so I am off to bed will pick up in say 5 hours

whubbard:
Thanks Mate
Its 3 AM so I am off to bed will pick up in say 5 hours

OK no worries .. here is the code

Not SUPER elegant but functional.

There are some variables you will need to play with yourself to get it turning to the exact positions that you want.
They are the numbers in the array ServoPos[]

Code Attached, have fun with it.

I have PM'ed you my PayPal details.

Cheers Pete.

Servo.ino (3.38 KB)

HI Wayne,

OK so you have the code and instructions on how to install the "time" library. Now that you have it when are you planning on paying me ?

Cheers Pete.

Hi Pete
Thanks so much....!
Its 6.00 am here.
Don't worry. there will be no problem with paying at all.
As soon as this thing move back and forth I will pay but I don't want to pay to find out I have some scribble that know one can help me with. I know it wont be that but just saying.
Sorry but as stated I am a dumb ass with all this stuff and have had limited time to play given that I got your reply last night 10 minutes before having to go out to dinner but will read and decipher the first instructions now and try to load the time library.
If you can make it easier for me with clear (do this then do that) would be great.
I have to do some stuff now and will get to it soon as I can but wanted to catch you when you were awake
I f you aswer now we can do it togeather and I will pay.
You can Type "open this, Do Taht do this ) then bingo ....Cha ching....Ha!
Thanks for your understanding Mate

Hi Wayne

I sent you a personal message with the links to the full instructions here it is again in case you have missed it somehow

Here follow this link and install the "Time" library

you can find the time library here
http://playground.arduino.cc/uploads/Code/Time.zip

Cheers Pete.

Thanks Pete
I was reading and following these and should be OK
I have to do do some stuff for an hour.
Be back and I will have a crack.
W

no worries it is my bedtime now I'll catch up in the morning

Cheers Pete.

Pete
I have it going now but it just goes left to right about 160 degrees every 5 seconds continually.
I have changed the time to 5 seconds for testing
I am not sure if this has anything to do with it.
Wayne

Here is the loaded code

#include <Time.h>

// ===================================================================================
// = library includes =
// ===================================================================================
#include <avr/eeprom.h>
#include <Servo.h>
#include <Time.h>

// ===================================================================================
// = Servo object instatiation =
// ===================================================================================
Servo oServo;

// ===================================================================================
// = Global variable to hold time and interval =
// ===================================================================================
time_t NextEvent;

#define Interval 10 //this is 600 seconds or 10 minutes

// ===================================================================================
// = Array to hold servo positions =
// = these are the servo PWM signals that you will need to tune to your servo =
// ===================================================================================
byte ServoPos[] = {0,51,102,204,255};

// ===================================================================================
// = Structure to hold state =
// ===================================================================================
struct ServoParams_t
{
byte Position;
int Direction;
} ServoParams;

// ===================================================================================
// = Setup code =
// ===================================================================================
void setup()
{
oServo.attach(9); // Attach the oServo object to use pin 9
LoadSettings(); // Read from the EEPORM
if(ServoParams.Direction > 1) ServoParams.Direction = 1; // just a bit of safety in the case of the EEPROM value being out of range
if(ServoParams.Direction < -1) ServoParams.Direction = -1; // just a bit of safety in the case of the EEPROM value being out of range
NextEvent = now() + (Interval); // Set the first interval time
}

// ===================================================================================
// = Main Program loop =
// ===================================================================================
void loop()
{
if(now() >= NextEvent)
{
NextEvent = now() + (Interval); // Set the next interval time
ServoParams.Position += ServoParams.Direction; // Increment or decrement the servo posistion array pointer
if (ServoParams.Position >= 4 || ServoParams.Position <= 0) ServoParams.Direction = -ServoParams.Direction; // check for range end and swap direction
oServo.write(ServoPos[ServoParams.Position]); // Write value to oServer Object
SaveSettings(); // Store state in EEPROM
}
}

// ===================================================================================
// = EEPROM Storage Handlers =
// ===================================================================================

void LoadSettings(void)
{
eeprom_read_block((void*)&ServoParams, (void*)(sizeof(ServoParams)), sizeof(ServoParams));
}

void SaveSettings(void)
{
eeprom_write_block((const void*)&ServoParams, (void*)(sizeof(ServoParams)), sizeof(ServoParams));
}

Hi Wayne,

Like I explained in the message i sent to you with the code you have to adjust the values in the array to match the positions that you want to see

byte ServoPos[] = {0,51,102,204,255}; each of thes represents 5,10,15,20,25 min intervals and then it moved back down again.

Cheers Pete.