Show Posts
Pages: 1 ... 7 8 [9] 10
121  Using Arduino / LEDs and Multiplexing / LED power switching power transistor - code hangs? on: September 17, 2011, 06:40:06 pm
Hi. I'm pretty sure this is a hardware issue and I haven't been able to solve it. Many thnks.

I am trying to control 8 leds in series (5v) through a hardware switch to illuminate a light box. Power supply is a 5 volt, 1.5 amp 7805 replacement switchmode regulator mounted on a shield powered by the 12v Vin.

It works like this.
Hardware switch ON - leds ON - camera takes a defined number of shots - leds OFF - next sequence.

The camera part and other code is working well.

I have tested the LED switching code using a single led (pin 12 and GND) to test the sequence - led ON, camera shoots 1, 2, 3, ... as defined, led OFF. The code jumps to the next sequence no problems.

However, when I switch all 8 leds ON through a power transistor my code doesn't sequence... zero nothing at all and the LEDs remain on endlessly, until the hardware switch is off.

The problem seems to be associated with switching through the power transistor. It is wired correctly, because it can be switched ON and OFF by the hardware switch, setting pin12 HIGH then LOW.

(The base is connected to the microcontrollers output. The high-current load (i.e. the leds) is attached to its power source, and then to the collector of the transistor. The emitter of the transistor is connected to ground).
Reference
http://itp.nyu.edu/physcomp/Tutorials/HighCurrentLoads

I have posted the relevant code as minimally as possible to avoid distraction. Note: the camera sequence works well and is a bit irrelevant to the LED power switching IMHO.

Code:
#define pin2 2 // hardware switch - 3 positions - different sequences
#define pin3 3 // hardware switch
#define pin12 12 // power transistor - base

void pause() {

digitalWrite(pin12, LOW);

}

void setup() {

pinmode(pin2, INPUT);
pinmode(pin3, INPUT);
pinmode(pin12, OUTPUT);

}

void loop() {

if (pin2 == LOW && pin3 == LOW) {
digitalWrite(pin12, HIGH); // LEDS light up - power transistor BASE

// camera shoot - when finished

digitalWrite(pin12, LOW); // leds should turn off here - but they don't

// next camera sequence - then all stop - no problems here

// hardware switch - pause everything
if (pin2 == HIGH && pin3 == LOW) {
pause();

}
}
122  Using Arduino / Programming Questions / Re: writing an expression for box spiral robot on: August 18, 2011, 06:51:02 am
I have set up the spiral pattern as below - frame count calling steps0, steps1... etc by  if() statements. The stepper rotates and pushes a button as it goes, stops and pushes the next button, either forward or reverse to trace out the box spiral. A bit clunky, but eminently easier for a newbie. I've implemented a wake up delay and hardware switch inputs for pause and stop along with an automatic stop after the desired number of frames is complete.

It was easier to do it this way and have control over image number instead of using a session time that had to be calculated based on image count anyway. The user can input the desired number of images and exposure time and wake up and the session time is calculated automatically and accurately.

The only issue is that 100 frames is 300 lines of code? Only 40 at the moment. This is pretty much finished for now and ready to go into production.

Code:
#include <Stepper.h>

/* Ditherbot/Sparehand.

Rowland Cheshire 2011
 
 This sketch automates multiple long exposure with a Canon DSLR
 Camera and includes a stepper driven dithering mechanism
 to press 4 pushbutton switches on a hand controller.
 
 Dithering, is moving the camera sensor between shots
 so that subsequent images does not fall on the same pixels,
 which improves final image quality. The camera will be mounted
 on an equatorial mount with the Ditherbot/Sparehand
 repositioning in RA and DEC between exposures.
 
 The image sequencing and dithering is independent of equatorial
 mount electronics which is '+ve'
 earth.
 
 Written for a bipolar/unipolar stepper motor - some
 rewriting will be needed for 3 wire variable reluctance
 motors - CDROM drives */

// Variables - set next 3 lines as required

// set number of images
#define images 40

// set exposure time
unsigned long exposure_tm = 420000; //default

// set wake up time
unsigned long wake_tm = 300000; //default

/* generally fixed variables - set and forget */

# define pre_shutter 100

#define mirror_delay 2900

#define predither_tm 2000

#define interval_tm 2000

#define motor_delay 3000

#define motorSteps 200

#define motorspeed 5

// comment out boolean statement and substitute with milliseconds if desired
unsigned long session_tm = ((exposure_tm + mirror_delay + predither_tm + motor_delay + interval_tm + pre_shutter)*images) + wake_tm;

/* fixed - no changes */

#define image_session images

#define pin2 2

#define pin3 3

#define shutter_pin 8

#define focus_pin 11 // to be implemented - manual focus

#define led_pin 13

int pinval2;

int pinval3;

int frames = 0;

int steps;

long time = millis();

/* stepper motor - dither sequence */

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

Stepper stepper(motorSteps, motorPin1,motorPin2,motorPin3,motorPin4);

/* dither pattern - call these lines sequentially */
#define steps0 50
#define steps1 50
#define steps2 -50
#define steps3 50
#define steps4 50
#define steps5 -50
#define steps6 50
#define steps7 50
#define steps8 -50
#define steps9 50
#define steps10 -50
#define steps11 50
#define steps12 50
#define steps13 -50
#define steps14 50
#define steps15 -50
#define steps16 50
#define steps17 50
#define steps18 -50
#define steps19 50
#define steps20 -50
#define steps21 50
#define steps22 -50
#define steps23 50
#define steps24 50
#define steps25 -50
#define steps26 50
#define steps27 -50
#define steps28 50
#define steps29 -50
#define steps30 50
#define steps31 50
#define steps32 -50
#define steps33 50
#define steps34 -50
#define steps35 50
#define steps36 -50
#define steps37 50
#define steps38 -50
#define steps39 50

/* focus is manual for this application
 will implement with hardware switch on/off */

// void sequences start here

/* this is the automated image capture dithering cycle. Session
 end is automatic for session time and 40 frames or pause and user
 end session */

// exposure
void cycle() {

  // mirror lock up
  digitalWrite(shutter_pin, HIGH);
  delay(pre_shutter);

  // reset camera_pin LOW, ready to fire shutter
  digitalWrite(shutter_pin, LOW);

  // hold open for 3 seconds
  delay(mirror_delay);

  // add focus here pin 11
  // press 2 - fire shutter
  digitalWrite(shutter_pin, HIGH);
  delay(exposure_tm);

  // close shutter
  digitalWrite(shutter_pin, LOW);
  delay(predither_tm);

  // dithering
  digitalWrite(led_pin, HIGH);
  frames++;
  Serial.println(frames);
  if (frames == 1)
    steps = steps0;
  if (frames == 2)
    steps = steps1;
  if (frames == 3)
    steps = steps2;
  if (frames == 4)
    steps = steps3;
  if (frames == 5)
    steps = steps4;
  if (frames == 6)
    steps = steps5;
  if (frames == 7)
    steps = steps6;
  if (frames == 8)
    steps = steps7;
  if (frames == 9)
    steps = steps8;
  if (frames == 10)
    steps = steps9;
  if (frames == 11)
    steps = steps10;
  if (frames == 12)
    steps = steps11;
  if (frames == 13)
    steps = steps12;     
  if (frames == 14)
    steps = steps13;
  if (frames == 15)
    steps = steps14;
  if (frames == 16)
    steps = steps15;
  if (frames == 17)
    steps = steps16;
  if (frames == 18)
    steps = steps17;
  if (frames == 19)
    steps = steps18;
  if (frames == 20)
    steps = steps19;
  if (frames == 21)
    steps = steps20;
  if (frames == 22)
    steps = steps21;
  if (frames == 23)
    steps = steps22;
  if (frames == 24)
    steps = steps23;
  if (frames == 25)
    steps = steps24;
  if (frames == 26)
    steps = steps25;
  if (frames == 27)
    steps = steps26;
  if (frames == 28)
    steps = steps27;
  if (frames == 29)
    steps = steps28;
  if (frames == 30)
    steps = steps29;
  if (frames == 31)
    steps = steps30;
  if (frames == 32)
    steps = steps31;
  if (frames == 33)
    steps = steps32;
  if (frames == 34)
    steps = steps33;
  if (frames == 35)
    steps = steps34;
  if (frames == 36)
    steps = steps35;
  if (frames == 37)
    steps = steps36;
  if (frames == 38)
    steps = steps37;
  if (frames == 39)
    steps = steps38;
  if (frames == 40)
    steps = steps39;

  // run stepper
  stepper.setSpeed(motorspeed);
  stepper.step(steps);

  // testing
  Serial.println(steps);
  digitalWrite(led_pin, LOW);

  // delay for next round
  delay(interval_tm);

  //testing     
  Serial.print("Time: ");
  time = millis();
  Serial.println(time);
}

// pause cycle after last cycle complete
void pause() {
  digitalWrite(shutter_pin, LOW);   
  stepper.setSpeed(0);
  stepper.step(0);
}

void end_session() {

  digitalWrite(shutter_pin, LOW);   
  stepper.setSpeed(0);
  stepper.step(0);

  while (1) {
  }
}

void setup() {

  pinMode(pin2, INPUT); // switch input
  pinMode(pin3, INPUT);
  digitalWrite(pin2, HIGH); // activate pull-up resistors
  digitalWrite(pin3, HIGH);
  pinMode(shutter_pin, OUTPUT);
  pinMode(led_pin, OUTPUT);
  Serial.begin(19200);
}

void loop() {

  // cycle exposure/dither to end of session - exits end_session
  pinval2 = digitalRead(pin2); // read pin value
  pinval3 = digitalRead(pin3);
  if (pin2 == HIGH && pin3 == HIGH ) {
    // for testing without hardware switch
    //if (millis() < session_tm) {
      cycle();
    }

    /* pause/stop - interupts exposure and completes dither cycle,
     ready for next shot in sequence */

    pinval2 = digitalRead(pin2); // read pin value
    pinval3 = digitalRead(pin3);
    while (pin2 == LOW && pin3 == HIGH) {
      pause();
    }

    /* Note: resetting the board or turning the power off will
     reset the entire session. However, the dither position will
     be retained */

    // stop - user end session
    pinval2 = digitalRead(pin2); // read pin value
    pinval3 = digitalRead(pin3);
    if (pin2 == LOW && pin3 == LOW) {
      end_session();
    }
    // end session automatically
    if (frames == 40 || frames == images || millis() >= session_tm) {
      end_session();     
    }
 }
123  Using Arduino / Programming Questions / Re: writing an expression for box spiral robot on: August 03, 2011, 04:35:41 am
Thanks David.

I get the error;

ISO C++ forbids declaration of 'seq2' with no type -

this is repeated for the values i and k in the same line.

This is how I've implemented your second code, between setup and loop.

Code:
void setup() {
  pinMode(shutterPin, OUTPUT);
  pinMode(mirrorPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  Serial.begin(115200);
}
// dither routine
 int sequence2(int reset)
{
  static seq2=-1, i=99, k=99;
  if (reset)
  {
    i = k = 99;
    return 0; // dummy value - ignore
  }
  if (k>=seq2)
  {
    ++i;
    k=-1;
  }
  if (i>=2)
  {
    i=0;
    k=-1;
    seq2+=2;
  }
  if (k++<0)
  {
    return 2;
  }
  return ( k&1 ? -1 : 1 );
}
void loop() {
124  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

125  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.


 
126  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){
          }
        }
      }
    }
  }
}
127  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.
128  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){
        }
    }
  }
}
129  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.

130  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);
    }
  }
}
131  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

132  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.

133  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);
}
      
134  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
        }                      
      }
    }
  }
}
135  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
  }
}
Pages: 1 ... 7 8 [9] 10