Loading...
  Show Posts
Pages: 1 ... 7 8 [9] 10
121  Using Arduino / Programming Questions / Re: writing an expression for box spiral robot on: August 01, 2011, 03:28:57 pm
Thanks, once again, David. I will look at fitting these options into the existing sketch this week.

Rowland

122  Using Arduino / Programming Questions / writing an expression for box spiral robot on: July 31, 2011, 06:33:36 am
I want a simple stepper driven robot device to push buttons (cross configuration) on a hand controller, controlling two perpendicular axis. Thinking 2D,  turning right and moving forward only.

An arm attached to the stepper shaft sweeps over the pushbuttons activating them. To move forward two steps the arm sweeps left then right and vice versa. To turn right, the arm sweeps over two adjacent buttons, going clockwise.

The sequence to do this is as follows - where -1 == left sweep and 1 == right sweep. 2 ==  right and right again. The arm travels 90deg with each sweep.

Each sequence is repeated before being incremented and actioned twice - and so on in the following pattern - a box spiral.

2, -1, 2, -1, 2, -1, 1, -1, 2, -1, 1, -1, 2, -1, 1, -1, 1, -1, 2, -1,1,-1,1,-1, 2,...

I am baffled as to how to express this to run as a for or while statement or other expression.

Why am I doing this? Besides moving an imaging sensor between shots to increase signal to noise ratio in the finished image, the instrument is practically a collectors item. It has a +ve earth! And I don't want to affect it cosmetically.

A bit left field, but thanks for looking.

Rowland.


 
123  Using Arduino / Programming Questions / Re: exiting a loop - terminating process. on: July 30, 2011, 09:18:30 pm
I found that it is possible for the session to end with the camera locked into an exposure. Also, I've used long unsigned time for the delays, because int doesn't handle the long times required of this program. long works too - does it really matter - there are no negative numbers to consider as far as timing is concerned.

The sketch finished up looking like this.
Code:
#include <Stepper.h>

 Change the next five lines as required
 
 */

//change number of motor steps to suit motor
#define motorSteps 200
int steps = 50;
int rpm = 5;

//change sessiontime =
// (exposuretime+mirrordelay+motortime+printdelay)*exposures
// dithering time = 3000; time print delay = 1000;
long unsigned sessiontime = 15408000;

//change this line to set exposure time.
long unsigned exposuretime = 420000; //milliseconds

//change this line to set mirror delay
long unsigned mirrordelay = 4000;

//change this line to set dither speed

long unsigned time;

int shutterPin = 8;

int mirrorPin = 11;

bool exposing = false;

//Stepper
#define motorPin1 4
#define motorPin2 5
#define motorPin3 6
#define motorPin4 7

//initialize stepper library
Stepper stepper(motorSteps, motorPin1,motorPin2,motorPin3,motorPin4);

//LED
int ledPin = 13; //if its on dithering is in progress

void setup() {
  pinMode(shutterPin, OUTPUT);
  pinMode(mirrorPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  Serial.begin(115200);
}
void loop() {
  {
    digitalWrite(mirrorPin, HIGH);
    delay(mirrordelay);
    digitalWrite(shutterPin, HIGH);
    delay(exposuretime);
  }
  digitalWrite(shutterPin, LOW);
  digitalWrite(mirrorPin, LOW);
  exposing = false;
  if (exposing == false) //shutter closed
  { //dither
    digitalWrite(ledPin, HIGH);
    stepper.setSpeed(rpm);
    stepper.step(steps);
    {
      Serial.print("Time: ");
      time = millis();
      Serial.println(time);
      delay(1000);
      time = millis();
      if (time >= sessiontime)
      {
        digitalWrite(shutterPin, LOW);
        digitalWrite(mirrorPin, LOW);
        {
          while(1){
          }
        }
      }
    }
  }
}
124  Using Arduino / Programming Questions / Re: exiting a loop - terminating process. on: July 30, 2011, 06:43:00 pm
David. I think we crossed paths.

You are correct. In the meantime, I've solved it another way - board time vs sessiontime. Thanks again for your help.

Rowland.
125  Using Arduino / Programming Questions / Re: exiting a loop - terminating process. on: July 30, 2011, 06:33:08 pm
Actually, stepping away from the problem, I can see that I've made things difficult for myself. It's very simple - thanks David.

The board will not stop while the stepper is active - a session time of 30 seconds means a board time of ~34 seconds with delays. This is accounted for in the imaging run, with significant delays between exposures.

Thanks again

Code:
#include <Stepper.h>
 Change the next five lines as required
 
 */

//change number of motor steps to suit motor
#define motorSteps 200

//change number of frames to shoot
long sessiontime = 30000;


//change this line to set exposure time.
int exposuretime = 2000; //milliseconds

//change this line to set mirror delay
int mirrordelay = 1000;

//change this line to set dither speed
int ditherspeed = 10;

long unsigned time;

int settle = 1000;

int shutterPin = 8;

int mirrorPin = 11;

bool exposing = false;

//Stepper
#define motorPin1 4
#define motorPin2 5
#define motorPin3 6
#define motorPin4 7

//initialize stepper library
Stepper stepper(motorSteps, motorPin1,motorPin2,motorPin3,motorPin4);

//LED
int ledPin = 13; //if its on dithering is in progress

void setup() {
  pinMode(shutterPin, OUTPUT);
  pinMode(mirrorPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
}
void loop() {
  {
    digitalWrite(mirrorPin, HIGH);
    delay(mirrordelay);
    digitalWrite(shutterPin, HIGH);
    delay(exposuretime);
  }
  digitalWrite(shutterPin, LOW);
  digitalWrite(mirrorPin, LOW);
  exposing = false;
  if (exposing == false) //shutter closed
  { //dither
    digitalWrite(ledPin, HIGH);
    stepper.setSpeed(5);
    stepper.step(50);
    delay(settle);
    {
      time = millis();               // time board has been running
      if (time >= sessiontime) // this only works with >= for this application
        while(1){
        }
    }
  }
}
126  Using Arduino / Programming Questions / Re: exiting a loop - terminating process. on: July 30, 2011, 05:05:03 pm
Quote
The while(1) { } here will just loop forever, until you shut down/reset your Arduino.

I have tried this several ways.

the offending line appears to be

Code:
unsigned long currentMillis = millis();

Code:
//placed here the loop terminates after 2 iterations.
unsigned long currentMillis = millis();

// pin setting prior to while is redundant

      if (currentMillis - previousMillis > sessiontime)
     
        while (1) {
        }
      }
    }
  }
}


Code:
// written this way the loop continues
 if (currentMillis - previousMillis > sessiontime)

        while (1) {
        }
      }
    }
  }
}

All I want to do is check the time the board has been running and terminate the process once the session time is up.

127  Using Arduino / Programming Questions / Re: exiting a loop - terminating process. on: July 30, 2011, 05:51:51 am
My apologies. Here is the full sketch comments and all. I'm self taught and this is my second production sketch. I'm sure that it can do with polish.

Thanks for the feedback. I have tried the examples provided without success. Use of while statements exits the loop on the first iteration.

Given that this sketch is fairly simple and only needs to shutdown after a prescribed period of time, I have adapted the blink without delay script. The only criteria needed to define the number of exposures is how long the board has been running.

Number of frames could also be used. I've tried both methods without success, and for, while, switch, goto, break..

Thanks again.


Code:
#include <Stepper.h>
/*Ditherbot/Sparehand. Adapted from DoubleArmDrive sketch 2007 -
 http://www.synergous.com
 
 This sketch automates multiple long exposure imaging using a
 Canon DSLR Camera and stepper driven Ditherbot/Sparehand, pressing
 4 pushbutton switches on the hand controller of an equatorial mount.
 I want to keep it in its original condition.

 The image sequencing and dithering is independent of any equatorial
 mount electronics/software and hardware, which is negatively earthed -
 an antique.
 
 Dithering - moving the camera between shots so that subsequent images
 does not fall on the same sensor pixels -  improves image quality.
 The Ditherbot/Sparehand repositioning in RA and DEC, between exposures.
 
 The stepper motor is bipolar - some rewriting will be needed for
 3 wire reluctance motors out of CDROM drives. Unipolars
 require different electronics.
 
 A pdf of the very basic motor shield (PCB) can be downloaded from
 http://www.synergous.com - see the Double Arm Drive page - its near
 the bottom of the page under the Electronics sub-heading.
 
 Change the next 5 lines as required for motor resolution, session time, exposure,
mirror delay and dither speed. It should only be necessary to change session time
thereafter.
Rule of thumb, timing not critical - e.g 8 x 7 minute exposures provides 30 seconds
between exposures per hour; that is, 32 frames in 4 hours - set for 4 hours 15 minutes
for full 4 hours of exposure.
 */

//change number of motor steps to suit motor
#define motorSteps 200

//change the session time
long sessiontime = 10000;

//change this line to set exposure time.
int exposuretime = 2000; //milliseconds

//change this line to set mirror delay
int mirrordelay = 1000;

//change this line to set dither speed
int ditherspeed = 10;

long previousMillis = 0;

int shutterPin = 8;

int mirrorPin = 11;

bool exposing = false;

//Stepper
#define motorPin1 4
#define motorPin2 5
#define motorPin3 6
#define motorPin4 7

//initialize stepper library
Stepper stepper(motorSteps, motorPin1,motorPin2,motorPin3,motorPin4);

//LED
int ledPin = 13; //on indicates dithering in progress

void setup() {
  pinMode(shutterPin, OUTPUT);
  pinMode(mirrorPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
}
void loop() {
  {
    digitalWrite(mirrorPin, HIGH);
    delay(mirrordelay);
    digitalWrite(shutterPin, HIGH);
    exposing = true; //shutter open - probably superfluous  
    if (exposing == true) //safe guard - probably superfluous
    { //no dither
      stepper.setSpeed(0); // just don't want the stepper moving
      stepper.step(0);        // it's stationary anyway - think about removing these lines
      digitalWrite(ledPin, LOW);
      delay(exposuretime);
    }
    digitalWrite(shutterPin, LOW);
    digitalWrite(mirrorPin, LOW);
    exposing = false;
    if (exposing == false) //shutter closed - same superfluous?
    { //dither
      digitalWrite(ledPin, HIGH);
      stepper.setSpeed(5);
      stepper.step(50);
    }
    unsigned long currentMillis = millis();
    if(currentMillis - previousMillis > sessiontime)
    {
      digitalWrite(shutterPin, LOW);
      digitalWrite(mirrorPin, LOW);
      stepper.setSpeed(0);
      stepper.step(0);
    }
  }
}
128  Using Arduino / Programming Questions / exiting a loop - terminating process. on: July 29, 2011, 07:46:08 pm
Hi. Completely noob question - confused. In the code below I want to count the number of void loop() iterations then terminate by setting all pins LOW. I need to make sure that all is 'dead' before switching off the power to the board.

I have adapted this sketch from a previous project in which switches were sensed. This program will run for hours in the middle of the night unattended - imaging the stars on an equatorial mount. Yet to write the code for wake - for the time being an external timer.

I don't think I understand the while and for expressions - try as I may - either the process terminates after 1 iteration or keeps going or terminates after 5 iterations where I have a constant of 3 (I have not been able to replicate this last behaviour).

// only the relevant stuff
Code:
const int iterations = 3;
int var = 0;

void loop(){
// Locks up camera mirror, waits then opens camera shutter, takes shot, then a stepper repositions the camera for next shot - this all works fine.

// Now I want to terminate camera and stepper activation by setting all pins low.
}
for (var=0; var < iterations; var++);{

// this where I get stuck - something in here to set all pins LOW and stop all processes
// based on number of iterations declared...
}
// set all pins LOW here.
}
}

Thanks for looking smiley

129  Forum 2005-2010 (read only) / Syntax & Programs / Re: Separating delay() to particular functions on: September 16, 2010, 11:31:43 pm
Si and PaulS. Thanks for your time - much appreciated and very helpful. On the right track now.

130  Forum 2005-2010 (read only) / Syntax & Programs / Re: Separating delay() to particular functions on: September 16, 2010, 03:56:27 pm
I've removed all the 'and' statements - I see what you mean about nesting. Same issue - what am I missing here?

declare pins HIGH in setup first and removed the nesting.

Quote
void setup() {

  pinMode(mirrorpin, OUTPUT);    
  pinMode(shutterpin, OUTPUT);
  digitalWrite(mirrorpin, HIGH);
  digitalWrite(shutterpin, HIGH);
}

void loop() {
  
      delay(wait);
      // Mirror lock up
      digitalWrite(mirrorpin, LOW);
      delay(mirror);
      // release shutter
      digitalWrite(shutterpin, LOW);
      delay(shutter); // Exposure time
      // Close shutter and mirror
      digitalWrite(shutterpin, HIGH);
      digitalWrite(mirrorpin, HIGH);
}
      
131  Forum 2005-2010 (read only) / Syntax & Programs / Re: Separating delay() to particular functions on: September 16, 2010, 02:39:34 pm
I would expect this to work, but it doesn't. The syntax is now correct I believe, but summing of delay statements is still a problem, particularly with the mirror. And depending on the location of delay even within a block summing is present in various combinations.

Quote
void loop() {

  {/*Camera active state - mirror and shutter open? Was it left on during manual focus - precaution*/
    mirrorval = digitalRead(mirrorpin);
    shutterval = digitalRead(shutterpin);
    if (mirrorval != HIGH && shutterval != HIGH)

    {// Close mirror and shutter for next round
      digitalWrite(mirrorpin, HIGH);
      digitalWrite(shutterpin, HIGH);
      delay(wait); wait 5 seconds before mirror lock up
    }
    {// make sure mirror and shutter closed - edification?
      mirrorval = digitalRead(mirrorpin);
      shutterval = digitalRead(shutterpin);
      if (shutterval == HIGH && mirrorval == HIGH)
      {
        // Mirror lock up
        digitalWrite(mirrorpin, LOW);
        delay(mirror); //wait 3 seconds before releasing shutter
      }

      {// make sure mirror locked up - edification?
        mirrorval = digitalRead(mirrorpin);
        shutterval = digitalRead(shutterpin);
        if (mirrorval == LOW && shutterval == HIGH)
        {
          // release shutter
          digitalWrite(shutterpin, LOW);
          delay(shutter); // wait exposure time - several minutes
        }                      
      }
    }
  }
}
132  Forum 2005-2010 (read only) / Syntax & Programs / Separating delay() to particular functions on: September 16, 2010, 02:35:03 am
This is my second attempt at programming, and I'm having trouble with the use of the delay() statement.

I want a dslr camera to wait for a few seconds before mirror lockup, and then wait for a few more seconds to release the shutter, and then wait some more to take a picture. Then close the shutter and mirror and start all over again - endlessly.

Hardware is working perfectly thanks to the guys on the forum, I just cant get the timing of the mirror and shutter right. Tried separating with else and else if and thought of using a separate void loop instance for either the shutter or mirror... wasn't too successful.

I understand that there may be other parts of the program that need improvement - for now I'd really like to get to the bottom of the hardware timing issue associated with the use of delay()

Code:
Quote
/* An intervalometer script for Canon DSLR 1000D.
 Change int mirror and int shutter variables to adjust exposure times.
Once the mirror is locked it will remain locked until the shutter is closed.
 */

int mirrorval;         // Read this value
int shutterval;        // Read this value

int wait = 3000;        // Switch off opportunity
int mirror = 3000;        // Mirror lock up/focus wait time
int shutter = 6000;        // Shutter release wait time


int mirrorpin = 5;      // Mirror lock up/focus
int shutterpin = 6;      // Shutter

void setup() {

  pinMode(mirrorpin, OUTPUT);    
  pinMode(shutterpin, OUTPUT);
  // noted not set HIGH - controls optocoupler pins
  // other side of optocoupler is camera
}

void loop() {

  //Is the camera active - taking a shot.
  mirrorval = digitalRead(mirrorpin);
  shutterval = digitalRead(shutterpin);
  if (mirrorpin != HIGH && shutterpin != HIGH);
  delay(wait);

  {
    // If yes close the mirror and shutter
    digitalWrite(mirrorpin, HIGH);
    digitalWrite(shutterpin, HIGH);

  }

  // make sure mirror and shutter closed - precautionary?
  mirrorval = digitalRead(mirrorpin);
  shutterval = digitalRead(shutterpin);
  if (shutterval == HIGH && mirrorval == HIGH);
 
  {

    // Mirror lock up and wait 3 seconds for vibration to cease
    digitalWrite(mirrorpin, LOW);
    delay(mirror);
  }
  {
    // make sure mirror is locked up - is this really necessary?
    mirrorval = digitalRead(mirrorpin);
    shutterval = digitalRead(shutterpin);
    if (mirrorval == LOW && shutterval == HIGH);

    // release shutter
    digitalWrite(shutterpin, LOW);
    //delay(shutter); // Exposure time
  }
}
133  Forum 2005-2010 (read only) / Syntax & Programs / Re: Setting pin HIGH then LOW on: May 05, 2009, 07:14:56 am
Thanks. That makes sense now. All working. Motor stepping forward, reverse and stop.

134  Forum 2005-2010 (read only) / Syntax & Programs / Re: Setting pin HIGH then LOW on: May 04, 2009, 03:36:41 am
Mike. Thanks for your reply. I have since found a site that addresses newbie questions.
http://sheepdogguides.com/arduino/aht0button.htm
135  Forum 2005-2010 (read only) / Syntax & Programs / Setting pin HIGH then LOW on: May 03, 2009, 03:11:22 am
Just a quick question. Having set an INPUT HIGH, by momentarily applying 5v, it seems that the pin stays HIGH.

Should digitalWrite(pin, LOW) be used to set the pin LOW in this case, or is there another way of doing it?

geoland.
Pages: 1 ... 7 8 [9] 10