Tuesday, December 15, 2009

Pentax IR Camera Remote

I've been meaning to buy/make a IR remote for my camera for a while. Pentax sell one, but it ends up close to +$50 by the time it arrives. So after some research I set about about making my own.

The first thing I was going to have to deal with was physical size. The second thing was power, the last was start up time. This meant that an arduino, no matter what flavour was just not going to work. A PICAXE would probably work, but an AVR microcontroller was the best choice as it fit all three criteria well.

The best place to start for any beginner with AVRs is this tutorial. It covers pretty much everything from the ground up. Which was fine as I had no idea where to start.

My plan was to build something based off this DIY Canon IR remote. Of course my camera was a Pentax so while the circuit was definitely helpful, the IR code itself was completely wrong.

Some digging came up with a couple of leads. The first was that there was a Sony remote code that would work. Lots of them in fact if various forums were accurate, but none of them gave a specific code, just which button on some persons remote. I had the Sony IR protocol on the arduino, but I had no idea which one. and there was literally thousands of possibilities. I hatched a cunning plan!
I could have the arduino send the codes to the camera, but would never know which one was the right one. Except that if it worked, the camera would take a picture. Add a small LCD to display the current code and problem solved!

Well it sounded good in theory. For some reason it didn't work like it should have. Hmm... back to the drawing board.

Some more digging and I found an open source Pentax remote for the Palm and as luck would have it the docs included information on the signal.

Now I was making headway.
Breaking out the arduino again I programed it to send the new code. Still no go. What the hell? Everything said that it should work but nothing. Some more investigation and I found that the IR remote mode has to be manually turned on. Ok. It works now /facepalm.

Which left me wondering if my original plan would have worked after all, if I had set the camera properly. Not that it mattered, the AVR chip awaited!

I used a attiny85 simply because that's what I had on hand. Its massive overkill for this but worked well. The attiny25 or attiny45 would work just as well.

The circuit is as simple as possible, just a battery, a button, a LED and the chip. The code itself I also modified from doc-diy's, simply changing it to match the Pentax. Some fiddling and it was all working.




Below is the code I used: LINK



// IR Remote to mimic Pentax F remote to control Pentax K100D etc cameras
#define F_CPU 7900000 // crystal frequency
#include <inttypes.h>
#include <stdlib.h>
#include <avr/io.h>
#include <avr/sleep.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#define HPERIOD 0.01524
#define RATIO 0.4
#define NPULSES 32
#define HPULSES 411
#define PULSES 7
#define LEDOFF 0b00000001
#define LEDON 0b00010111


int main(void)
{
uint16_t i;
uint8_t p;


DDRB = 0b00010110; // pin PB0 is input, pins PB1-PB4 are output
PORTB = 0b00000001; // pull-up for input pin PB0
asm volatile ("nop");
asm volatile ("nop");

for (;;)
{
for(i=0;i<HPULSES;i++)
{
PORTB = LEDON;
_delay_ms(HPERIOD);
PORTB = LEDOFF;
_delay_ms(HPERIOD);
}

_delay_ms(3); // instant

for(p=0;p<PULSES;p++)
{
for(i=0;i<NPULSES;i++)
{
PORTB = LEDON;
_delay_ms(HPERIOD);
PORTB = LEDOFF;
_delay_ms(HPERIOD);
}
_delay_ms(1);
}

_delay_ms(12);
}

}



Hardware result



As I said, this was to be as simple as possible and I think I succeeded. The case itself is a Hammond case from Altronics and is only 35 x 50 mm.

So yes the remote was working well, but I still wondered what would have happened with the Sony code scanning. I set the rig back up and started the scanning. Turns out that yes it would have worked if I had set it up properly in the first place. The scan came up with more than 45 codes between 0x000 and 0xfff. The "correct" code would be closest to 0xFE0, which equates to 7 pulses as per the PRCF documentation . The camera is very slack however so lots more work.



There were however a couple of caveats. The IR mode on the camera only stays on for so long. I think it was about 5 mins without a shot before it stops listening. But if you send the right/wrong code it can stop listening a lot earlier. This was important to know as I was planning on later building an interval meter which would allow me to do time lapse photos/movies. If the camera was going to stop listening to the interval meter after just a few minutes it wasn't going to work, I would have to use a cable remote rather than IR remote to trigger the camera.

No comments:

Post a Comment