15 Jan 2013

APM Camera power control & CHDK intervalometer

Finally I made some progress on the r/c camera control. A fairly simple and cheap solution is to solder cables to the power button of a cannon camera. Hook these up to an ATtiny85 (45 would probably do as well). The ATtiny reads a PPM signal from an r/c receiver and switches the camera on or off accordingly.

ATtiny  pin layout:


Schema:


Demo:





ATTiny Code (C++ Arduino):

/**
 * Read PPM signal
 * 
 * Decode r/c receiver PPM servo signal and turn lights on 
 * according to stick position.
 *
 * $Id$
 */

// pin setup
#define PIN_PPM  0
#define PIN_POS1 4

unsigned long duration, lastgood = 0;
int position = 0;

void setup() {
  pinMode(PIN_PPM, INPUT);
  pinMode(PIN_POS1, OUTPUT);
  digitalWrite(PIN_POS1, LOW);
}

void loop() {
  // the length of the pulse (in microseconds) or 0 if no pulse 
  // started before the timeout (unsigned long)
  duration = pulseIn(PIN_PPM, HIGH, 20000); 
  if (duration == 0)
    duration = lastgood;
  else
    lastgood = duration;
  
  position = map(lastgood, 1000, 2000, 0, 1);
  
  if (position > 0)
    digitalWrite(PIN_POS1, HIGH);
  else
    digitalWrite(PIN_POS1, LOW);
}



Intervalometer Code (lua):

--[[
rem 2013-01-13 by Simon Wunderlin, ResearchDrones LLC
@title ResearchDrones Fast Interval
@param a = interval (sec/10)
@default a 10
--]]

function camera_close()
 click "display"
 sleep(1000)
 click "display"
 sleep(1000)
 shut_down()
 sleep(5000)
end

--[[
f = get_usb_power(1)
if f == 1 then camera_close() end 
]]--
--shoot()

repeat
 start = get_tick_count()
 
 press("shoot_half")
 repeat
  sleep(50)
  until get_shooting() == true
 click("shoot_full")
 release("shoot_half")
 
 sleep(a*100 - (get_tick_count() - start))
until ( false )