Hi everyone,
I have a project that involve moving and triggering my canon dslr camera with arduino uno. Being honest, I went a bit empirically there.
This is a quick description of my system: one nema 23 is moving the camera on the X axis, two nema 23 are used to move the Y axis. Each have a PB6600 driver. The movement is a simple grid pattern programmed with “for loop”: move one step in a given direction, take a shot, move.. etc. then go back to initial position. The push button is used to start or restart the pattern. The SystemLED is on when the system is moving. I found what seemed like an IR led in my stuff and used it to trigger the camera. Since I did not have the spec of the thing, I assumed something like 1.5V, 20mA. I used the multiCameraIrControl library (Arduino/libraries/multiCameraIrControl at master · dharmapurikar/Arduino · GitHub) to take care of the signal.
I provide the diagram in attachment.
I tested the “IR module” with a simple loop:
test=
“
void loop() {
myCamera.shotnow();
delay(500);
}
”
And check that it worked continuously without fail. So the IR Led, Camera and Control library are fine.
BUT
When my final code is running, there is a ~ 25% rate of failure (i.e. camera not triggering).
Here it is:
#include <multiCameraIrControl.h>
Canon DSLR(12); /* IR led */
volatile bool systemState = false;
volatile byte systemLedState = LOW;
volatile long switchTime = 0;
volatile long prevSwitchTime = 0;
// Define stepper motor connections and steps per revolution:
const int interruptPin = 2;
const int XdirPin = 3;
const int XstepPin = 4;
const int YdirPin = 5;
const int YstepPin = 6;
volatile int systemLedPin = 13;
const int stepsPerRevolution = 1600;
const int debouncingDelay = 400;
void setup() {
// Declare pins as output:
for (byte i = 3; i < 14; i++) {
pinMode(i, OUTPUT);
}
pinMode(interruptPin, INPUT);
// Set the spinning direction CW/CCW:
digitalWrite(XdirPin, HIGH);
digitalWrite(YdirPin, HIGH);
digitalWrite(systemLedPin, systemLedState);
attachInterrupt(digitalPinToInterrupt(interruptPin), switchOn, RISING);
systemState = false;
}
void switchOn() {
switchTime = millis();
if (switchTime - prevSwitchTime > debouncingDelay) {
prevSwitchTime = switchTime;
systemState = !systemState;
systemLedState = !systemLedState;
}
}
void sendpulse(byte stepPin, int pulsefreq) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(pulsefreq);
digitalWrite(stepPin, LOW);
delayMicroseconds(pulsefreq);
}
void course(byte stepPin, int steps, int pulsefreq) {
for (int i = 0; i < steps; i++) {
// These four lines result in 1 step:
if (!systemState) {return;}
sendpulse(stepPin, pulsefreq);
}
}
void scanStage() {
bool Xdir = LOW;
bool Ydir = LOW;
//Set the spinning direction clockwise
digitalWrite(YdirPin, Ydir);
digitalWrite(XdirPin, Xdir);
for (byte i = 0; i < 6; i++){
course(YstepPin, 100, 400); /* commented out in debug */
delay(250);
DSLR.shotNow();
delay(250);
for (byte j = 0; j < 6; j++){
course(XstepPin, 100, 400); /* commented out in debug */
delay(250);
DSLR.shotNow();
delay(250);
}
Xdir = !Xdir;
digitalWrite(XdirPin, Xdir);
}
digitalWrite(YdirPin, !Ydir);
course(YstepPin, 600, 400); /* commented out in debug */
}
void loop() {
digitalWrite(systemLedPin, systemLedState);
// Run once then stop system
if (systemState){
digitalWrite(systemLedPin, systemLedState);
scanStage();
systemState = false;
systemLedState = LOW;
}
}
I used my phone camera to check that the IR led was blinking each time, which it does, even when the camera is not responding. The failure is random (I cannot predict the step that will miss). To debug, I commented out the "course" function calls in the loops (i.e the loops will be executed, the SystemLED will be on, the camera will be trigger but the motors won’t move). The camera is now taking all the shots.
A working hypothesis is that the led may require 100mA instead of 20mA and that it should not be powered by a digital pin. What is theoretically happening in my IR led circuit ? The digital pin provide 5V and up to 40mA right. There should be 3.5 V at the 220 ohm resistor, so ~15 mA in the circuit right ?
BUT
I ruled out signal strength (because not a problem in test and debug, plus I moved the led just in front of the receiver without improvement). The camera can follow the triggering rate (I tested with a manual IR command, also debug occurs at a higher rate that normal function). If I don’t power the motors but still call the "course" function, I still miss some shots, so this has to do with emitting the pulses to move the steppers. But because the pulses are not emitted when the shot is triggered, I don't understand how this could be a problem :o.
So, I am under this impression than this has something to do with the signal being corrupted. Any ideas of what could go wrong and how to fix ?
Cheers,
MM