A470 won't run intervalometer script properly - Script Writing - CHDK Forum  

A470 won't run intervalometer script properly

  • 3 Replies
A470 won't run intervalometer script properly
« on: 20 / October / 2009, 22:29:43 »
I have an a470 and loaded the Accurate Intervalometer with power-saving and pre-focus script on it. It takes the pictures just fine but I am using this script because it has an option to turn the screen off after a set number of shots. I need this so I can conserve battery. I have tested this script on other cameras and the screen turns off just as it should but on the a470 the screen won't turn off. The problem is the a470 has no way to turn the screen off manually as the print button (which can be assigned to this function) is overridden by chdk so it seems this, or a similar script will be my only solution. This is an lua script and the contents are pasted below. Does anyone have any ideas of how to run an intervalometer with the lcd off?

Author: Fraser McCrossan
Tested on G9, should work on most cameras.

An accurate intervalometer script, with pre-focus and screen power off options.

 - input is frame interval plus total desired run-time (or "endless")
 - displays frame count, frame total and remaining time after each frame
   (in endless mode, displays frame count and elapsed time)
 - honours the "Display" button during frame delays (so you can
   get it running then turn off the display to save power)
 - can turn off the display a given number of frames after starting
   (might take a couple of frames longer to cycle to correct mode)
 - can pre-focus before starting then go to manual focus mode
 - use SET button to exit

 See bottom of script for main loop.

@title Time-lapse
@param s Secs/frame
@default s 5
@param h Sequence hours
@default h 0
@param m Sequence minutes
@default m 5
@param e Endless? 0=No 1=Yes
@default e 0
@param f Focus: 0=Every 1=Start
@default f 0
@param d Display off frame 0=never
@default d 0

-- convert parameters into readable variable names
secs_frame, hours, minutes, endless, focus_at_start, display_off_frame = s, h, m, (e > 0), (f > 0), d

props = require "propcase"

-- derive actual running parameters from the more human-friendly input
-- parameters
function calculate_parameters (seconds_per_frame, hours, minutes, start_ticks)
   local ticks_per_frame = 1000 * secs_frame -- ticks per frame
   local total_frames = (hours * 3600 + minutes * 60) / secs_frame -- total frames
   local end_ticks = start_ticks + total_frames * ticks_per_frame -- ticks at end of sequence
   return ticks_per_frame, total_frames, end_ticks

function print_status (frame, total_frames, ticks_per_frame, end_ticks, endless)
   local free = get_jpg_count()
   if endless then
      local h, m, s = ticks_to_hms(frame * ticks_per_frame)
      print("#" .. frame .. ", " .. h .. "h " .. m .. "m " .. s .. "s")
      local h, m, s = ticks_to_hms(end_ticks - get_tick_count())
      print(frame .. "/" .. total_frames .. ", " .. h .. "h" .. m .. "m" .. s .. "s/" .. free .. " left")

function ticks_to_hms (ticks)
   local secs = (ticks + 500) / 1000 -- round to nearest seconds
   local s = secs % 60
   secs = secs / 60
   local m = secs % 60
   local h = secs / 60
   return h, m, s

-- sleep, but using wait_click(); return true if a key was pressed, else false
function next_frame_sleep (frame, start_ticks, ticks_per_frame)
   -- this calculates the number of ticks between now and the time of
   -- the next frame
   local sleep_time = (start_ticks + frame * ticks_per_frame) - get_tick_count()
   if sleep_time < 1 then
      sleep_time = 1
   return not is_key("no_key")

-- delay for the appropriate amount of time, but respond to
-- the display key (allows turning off display to save power)
-- return true if we should exit, else false
function frame_delay (frame, start_ticks, ticks_per_frame)
   -- this returns true while a key has been pressed, and false if
   -- none
   while next_frame_sleep (frame, start_ticks, ticks_per_frame) do
      -- honour the display button
      if is_key("display") then
      -- if set key is pressed, indicate that we should stop
      if is_key("set") then
    return true
   return false

-- if the display mode is not the passed mode, click display and return true
-- otherwise return false
function seek_display_mode(mode)
   if get_prop(props.DISPLAY_MODE) == mode then
      return false
      click "display"
      return true

-- switch to autofocus mode, pre-focus, then go to manual focus mode
function pre_focus()
   local focused = false
   local try = 1
   while not focused and try <= 5 do
      print("Pre-focus attempt " .. try)
      if get_prop(18) > 0 then
    focused = true
      try = try + 1
   return focused

if focus_at_start then
   if not pre_focus() then
      print "Unable to reach pre-focus"

start_ticks = get_tick_count()

ticks_per_frame, total_frames, end_ticks = calculate_parameters(secs_frame, hours, minutes, start_ticks)

frame = 1
original_display_mode = get_prop(props.DISPLAY_MODE)
target_display_mode = 2 -- off

print "Press SET to exit"

while endless or frame <= total_frames do
   print_status(frame, total_frames, ticks_per_frame, end_ticks, endless)
   if display_off_frame > 0 and frame >= display_off_frame then
   if frame_delay(frame, start_ticks, ticks_per_frame) then
      print "User quit"
   frame = frame + 1

-- restore display mode
if display_off_frame > 0 then
   while seek_display_mode(original_display_mode) do

-- restore focus mode


Offline fe50

  • ******
  • 3147
  • IXUS50 & 860, SX10 Star WARs-Star RAWs
    • fe50
Re: A470 won't run intervalometer script properly
« Reply #1 on: 21 / October / 2009, 01:12:04 »
Hello & wellcome, hairybuffalo !

There are several things you can do...

a) You can disable the display with a simulated key press to the print button when you've assigned the "Sleep" action to the print button (from the Canon menu); outside a script you'll have to hold the button for ~ 1s to activate the 2nd function of the keys, in a script a simple click/press "print" can be used.
Read also "Some more hints" from here.

b) You can disable the LCD backlight after a shot with the set_backlight command.

c) You can disable the display by pluggin' something into the AV-OUT plug...

Re: A470 won't run intervalometer script properly
« Reply #2 on: 22 / October / 2009, 22:27:00 »
Thank you for your help. I did edit the script per your suggestion but the problem with that camera is that when it takes a picture it automatically turns the screen back on anyway. Your suggestion to plug something into the av out is so simple I am upset that I didn't think of it. That will work just fine for my purposes.

Thanks again.


Offline fe50

  • ******
  • 3147
  • IXUS50 & 860, SX10 Star WARs-Star RAWs
    • fe50
Re: A470 won't run intervalometer script properly
« Reply #3 on: 23 / October / 2009, 01:49:14 »
...but the problem with that camera is that when it takes a picture it automatically turns the screen back on anyway.
Yes - you'll have to disable the display again after after each shot then, as described in the documentation of a) and b).
This would give more batterie lifetime than the "AV-plug" method (disp. off also disables the sensor); you can also use both methods combined.


Related Topics

SimplePortal 2.3.6 © 2008-2014, SimplePortal