Debugging

Some debugging later, and some tweaking of the timers we get this, the timers were off by more, but there’s something weird happening at cycle 6 where the 1ms cycle ramps up well beyond what it should be.  Further digging tomorrow night.

IR Trigger test #1

So, first admission, this doesn’t work yet.  In theory everything is perfect, checking the circuit shows the IR LED is firing, the test green LED goes “blip” and the red indicates when the code is off having a kip.  However the camera is sat there like a dumb lump ignoring the IR codes through either port (there’s one front and back on the K10D).

Back to pondering on what’s happening, or not happening, whether the IR can fire fast enough or if the IR LED is up to the job or indeed should I find the black chicken to wave over the circuit to finish it off.

Diagram of Pentax IR sequence

The circuit

The Code

/*
  Pentax firing code (file : blink_test2)

  Code used with modified setup with parallel LEDs to simulate standard LED
  and IR LED for triggering K10D camera

  References:
    PIR based firing code
    http://luckylarry.co.uk/arduino-projects/arduino-motion-triggered-camera/

    Pentax IR sequence
    http://www.picbasic.co.uk/forum/showthread.php?t=14182
 */

int pinLED   = 11;
int pinIRLED = 10;

// Normally the clock cycle is 38kHz
// halfCycle == (26.32×10-6s) / 2
int halfCycle = 13;

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(pinIRLED, OUTPUT);     
  pinMode(pinLED, OUTPUT);     
}

// sets the pulse of the IR signal.
void pulseON(int pulseTime) {
  unsigned long endPulse = micros() + pulseTime;        // create the microseconds to pulse for
  while( micros() < endPulse) {
    digitalWrite(pinIRLED, HIGH);                       // turn IR on
    delayMicroseconds( halfCycle );                              // half the clock cycle for 38Khz (26.32×10-6s) - e.g. the 'on' part of our wave
    digitalWrite(pinIRLED, LOW);                        // turn IR off
    delayMicroseconds( halfCycle );                              // delay for the other half of the cycle to generate wave/ oscillation
  }
}

void pulseOFF(unsigned long startDelay) {
  // startDelay = startDelay * 1000;
  unsigned long endDelay = micros() + startDelay;       // create the microseconds to delay for
  while(micros() < endDelay);
}

void takePicture() {
  // Pentax K10D firing sequence
  // 13ms pulsing
  // 3ms silence
  // 1ms pulse + 1ms silence, looped seven times

  for (int i=0; i < 2; i++) {
    // Loop to fire the signal twice, just in case
    pulseON( 13000 );    // pulse = 13ms
    pulseOFF( 3000 );   // silence = 1ms
    // 1
    pulseON( 1000 );    // pulse = 1ms
    pulseOFF( 1000 );   // silence = 1ms
    // 2
    pulseON( 1000 );    // pulse = 1ms
    pulseOFF( 1000 );   // silence = 1ms
    // 3
    pulseON( 1000 );    // pulse = 1ms
    pulseOFF( 1000 );   // silence = 1ms
    // 4
    pulseON( 1000 );    // pulse = 1ms
    pulseOFF( 1000 );   // silence = 1ms
    // 5
    pulseON( 1000 );    // pulse = 1ms
    pulseOFF( 1000 );   // silence = 1ms
    // 6
    pulseON( 1000 );    // pulse = 1ms
    pulseOFF( 1000 );   // silence = 1ms
    // 7
    pulseON( 1000 );    // pulse = 1ms  
    pulseOFF( 1000 );   // silence = 1ms

    // slacking
    pulseOFF( 1000 );   // silence = 1ms
    pulseOFF( 1000 );   // silence = 1ms

    // defined slacking
    pulseOFF(400000);
  }
}

void blink( int thisPIN, int delayMe ) {

  digitalWrite( thisPIN, HIGH ); // Sleep LED on
  for (int i=0; i <= delayMe; i++) {
    delay( 950 );                  // 2 seconds twiddling our thumbs
    digitalWrite( thisPIN, LOW  ); // LED off
    delay( 50 );
    digitalWrite( thisPIN, HIGH ); // Sleep LED on
  }
  digitalWrite( thisPIN, LOW  ); // LED off
}

void LEDTest() {
  // Just here to prove the LEDs are up for measurement purposes.
  digitalWrite( pinIRLED, HIGH );
  digitalWrite( pinLED, HIGH );
  delay( 5000 );
  digitalWrite( pinIRLED, LOW );
  digitalWrite( pinLED, LOW );
  delay( 2000 );
}

void loop() {
  // LEDTest();

  // Click (hopefully)  
  takePicture();
  // Make the red LED go blinkitty.
  blink( pinLED, 5 );
  delay( 1000 );
  digitalWrite( pinLED, HIGH );
  delay( 500 );
  digitalWrite( pinLED, LOW );
  delay( 1000 );
}

Dances with electronics

In which your humble narrator manages to get his shiny new Arduino to make the Pentax K10D go “click”.

After some digging around I managed to find out how the remote cable on the K10D is setup, 2.5mm stereo jack.

Tip – Shutter
Ring – Focus
Sleave – Common

All nice and simple, close ring & sleave, watch the camera focus. Close tip and sleave, click. All nicely tested with a bit of wire and a nice fresh jack from Maplin. The important part of the circuit is I don’t want anything from the control side spilling over into the camera side, frying the camera would be a bad thing.

Enter the optocoupler, a nifty little device which allows control on one side to open or close a circuit on the other with no crossover of circuits.

The circuit

U1 – 4N25 optocoupler
R1 – 470 ohm
R2 – 560 ohm

Code

The code is effectively the blink test just slightly tweaked for the LED circuit, nothing exciting or sexy yet.

/*
K10D
Optocoupler based firing mechanism
*/

// Control PIN
int pinLED = 11;
int pinCAM = 10;

// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(pinLED, OUTPUT);
pinMode(pinCAM, OUTPUT);
}

void loop() {
delay( 1000 ); // Delay one second
digitalWrite(pinLED, HIGH);
digitalWrite(pinCAM, HIGH);
delay( 1000 ); // Delay one second
digitalWrite(pinLED, LOW);
digitalWrite(pinCAM, LOW);
}

Photos

Next… seeing if I can get the IR LED to fire the camera.