March 29, 2024

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