CHDK/uBASIC/Scripts

=User-written Scripts=

(I'm new to this Wikia thing, so bear with if I'm doing something wrong here. :-) )

Please add your debugged and tested scripts to this section. Reserve discussion and help for writing your script to the DISCUSSION section (tab above). Final scripts will appear on this page.
 * Scripts added here should include:
 * Camera model that you wrote it on.
 * Other camera models that it is known to work on.
 * Any special instructions that may be required for running the script.
 * Your script!


 * Since some scripts require special instructions that might be too lengthy to write into the script itself with "print" statements, I think it would be a good idea to start a common practice of including a short but informative text-file with each script, that could be saved by the same filename. Using a .TXT extension so the file may be referred to as a help-file using CHDK's "File Reader".

I'll post one here that I tweaked/wrote to provide as an example, and for you to use as a possible template if needed.

To post your own script to this main Scripts page:
 * 1) Click on the EDIT TAB at the top of the page (not the ones beside each entry).
 * 2) Scroll to the bottom of the list of scripts.
 * 3) Make sure there's a horizontal-line formatting command between your script and the last script. (using the string on a line by itself)
 * 4) Put the title of your script inside of the ==Headline Text== formatting commands. This will cause it to show up in the "Contents" box at the top of the page, so people can more easily get right to your individual script.
 * 5) Preface each line of your script with a character to retain orignal formatting. OR enclose your actual script between   (your script here)    commands for pre-formatted text.

Focus Bracketing

 * Written for/on: Powershot S3 IS, Powershot A610 with little changes in script (change "down" to "right" and "up" to "left")
 * Also works on: (unknown at this time)


 * IMPORTANT: This script does not presently work on S-Series CHDK builds #86?/#87 or later. The changes needed to make the zoom-lever more functional for manual-focus seems to be interfering in how scripts can run when the MF button is held in. Until there are some hold "[button]" / release "[button]" commands for scripting, or this can be looked into, your best bet would be to just load up an earlier version of CHDK to run this script if you have an important need for using it. You can find earlier versions here: Early Versions Archive


 * Documentation/Help (save as a small "focus-brkt.txt" file to your /SCRIPTS/ folder)

Put camera into Manual Focus mode. Make sure your focal distance is not too close to infinity or the nearest focus range of the camera. Meaning: allow some focus-space for the bracketing steps chosen so it won't bottom-out hitting a focus limit. Set your "Script shoot delay" to 0, 1, or 2 (depending how fast your camera can use this script). Set the number of bracketing steps you desire, keeping in mind that there will be twice this number of shots taken. 5 bracketing steps = 5-near + chosen-focus + 5-far, 11 shots in total. Step sizes of 2, 3, 4, and 5 work well. Shooting with the script: Put camera in  mode. HOLD DOWN YOUR MF (manual focus) BUTTON! Press shutter release.

Script Code (save as "focus-brkt.bas" to your /SCRIPTS/ folder) @title Focus Bracketing (Hold MF!) @param a Number of +/- steps @default a 2 @param b Step size @default b 2 if a<1 then let a=2 if b<1 then let b=3 print "Preparing..." for n=1 to a*b click "down" next n print "Shoot 1 of", a*2+1 shoot for s=1 to a*2 for n=1 to b        click "up" next n    print "Shoot", s+1, "of", a*2+1 shoot next s print "Finalizing..." for n=1 to a*b click "down" next n end

Unlimited Interval Shooting

 * Written for/on: Powershot S3 IS
 * Also works on: (unknown at this time)

This script was written for times where you need to use your camera for surveillance or for extended astrophotography sessions, etc. This script will run until you interrupt it by any means available. Use with caution! See the documentation below. Documentation/Help (save as a small "intvl-nolimit.txt" file to your /SCRIPTS/ folder)

This interval shooting script will repeat non-stop until you interrupt it by pressing the shutter-button (or exit the  mode with other button presses). If your camera is hooked up to an AC power-supply DO NOT leave this script running for many hours, days, or weeks as it could damage your camera! USE AT YOUR OWN RISK. It will run as long as your batteries last or as much space as you have left available on your SD card.

IMPORTANT: In CHDK versions BEFORE "test1-pre12-xxxx-100a-65" (changeset 149), it has been found that lengthy intervalometer sessions with shutter speeds below 1 second (1.3 to 15 seconds) will cause your camera to show an error code or just shut down after 2 to 12 exposures. This has been traced down the noise reduction routine in the camera (whenever you see the "busy" in the viewfinder after a long exposure). Solutions: use shutter-speeds 1-second or faster.

This problem seems to be fixed now in version test1-pre12-xxxx-100a-65 (changeset 149).

Script Code (save as "intvl-nolimit.bas" to your /SCRIPTS/ folder) @title Interval Shooting Non-stop @param a Interval (Minutes) @default a 0 @param b Interval (Seconds) @default b 5 @param c Interval (10th Seconds) @default c 0 t=a*60000+b*1000+c*100 if t<100 then let t=5000 n=1 print "Interval shooting." print "Until you interrupt it." print "Use with caution." sleep 1000 goto "shot" :shot print "Shot number", n   shoot n=n+1 sleep t   goto "shot"

Ultra Intervalometer

 * Written for/on: Powershot S3 IS
 * Also works on: Should work okay on all of them.

This intervalometer script includes a few features that should fit most any need that arises. You can set a delay in minutes and seconds to the first shot of your intervalometer sequence, the number of shots for the intervalometer sequence, as well as allowing you to flag a Yes or No "Endless" option to repeat the sequence endlessly until you interrupt it manually by pressing the shutter button or your [print]/[shortcut] button. Having this one repeat endlessly sort of supersedes my previous "Unlimited Interval Shooting" script so it could probably be removed now.(?)

My BASIC programming is 30-years rusty, and while I tested this for each option and it seems to be working just fine, if anyone runs into a problem please post about it in the DISCUSSION section (tab above), and I'll try to sort out what I did wrong. Documentation/Help (save as a small "ult_intrvl.txt" file to your /SCRIPTS/ folder)

This interval shooting script allows you to set a delay until the first shot in your intervalometer sequence as well as allowing the sequence to repeat endlessly. Use the "Endless" repeat with caution! If that flag is set it repeats non-stop until you interrupt it by pressing the shutter-button (or exit the  mode with other button presses). Word of Warning: If you are running off of an AC power-supply and going to set the endless-repeat flag do so at your own risk. You should not allow your camera to run for many hours or days as it can harm your camera! (Though I'm not sure why, other than that warning is in all the Canon manuals.)

These intervalometer scripts that use the "shoot" command (as opposed to the 'click "shoot_full"' command) also set focus and exposure before each shot (if the camera is not in Manual mode). Unlike the camera's own built-in intervalometer where exposure and focus is set for just the first shot. This allows it to compensate for all the varying conditions that can take place over the course of many minutes and hours, far surpassing Canon's concept of a useful intervalometer.

Note 1: The count-down timer for the "Delay to 1st Shot" phase won't display beyond the time you have set for your Power Saving / Display Off settings. On the S3 IS this is a maximum count-down display of 3 minutes. The script will continue running however. You just won't have a running tally of how long until the next intervalometer sequence or shot.

Note 2: The total time shown for each cycle does not take into account the shutter-speed time (at this time, but may in a future version). So if you are using long exposure times of 1 to 15 seconds, be aware that the total time for 1 Cycle will be much greater than what is displayed when first running the script. Exposures of 1.3 seconds or greater also add in a dark-frame subtraction to reduce image noise. In effect, a 15 second shutter speed actually takes 30 seconds to elapse. Until this can be figured into the script you'll just have to do some mental arithmetic if knowing a more accurate cycle time is important to you for long shutter-speeds.

IMPORTANT: In CHDK versions BEFORE "test1-pre12-xxxx-100a-65" (changeset 149), it has been found that lengthy intervalometer sessions with shutter speeds below 1 second (1.3 to 15 seconds) will cause your camera to show an error code or just shut down after 2 to 12 exposures. This has been traced down the noise reduction routine in the camera (whenever you see the "busy" in the viewfinder after a long exposure). Solutions: use shutter-speeds 1-second or faster.

This problem seems to be fixed now in version test1-pre12-xxxx-100a-65 (changeset 149).

Script Code (save as "ult_intrvl.bas" to your /SCRIPTS/ folder)

rem Ultra Intervalometer @title Ultra Intervalometer @param a Delay 1st Shot (Mins) @default a 0 @param b Delay 1st Shot (Secs) @default b 0 @param c Number of Shots @default c 5 @param d Interval (Minutes) @default d 0 @param e Interval (Seconds) @default e 0 @param f Interval (10th Seconds) @default f 5 @param g Endless? No=0 Yes=1 @default g 0 p=a*60000+b*1000 t=d*60000+e*1000+f*100 if c<1 then let c=5 if t<100 then let t=100 if g<0 then let g=0 if g>1 then let g=1 if p<0 then let p=0 z=t*c y=p+z print "1 Cycle Time:", y/60000; "min", y%60000/1000; "sec" goto "interval" :interval if p>0 then gosub "pause" print "Shot 1 of", c  shoot for n=2 to c  sleep t   print "Shot", n, "of", c   shoot next n  if g=1 then goto "interval" else end :pause n=(a*60)+b for m=1 to n  q=n-m print "Intvl Begins:", q/60; "min", q%60; "sec" sleep 930 next m  return

I timed the :pause subroutine and tweaked the sleep to 930 milliseconds to be about as accurate as possible for that loop to span 1 second for the for/print/next execution time. This was calculated on an S3 IS, your camera's uBASIC speed may vary, tweak "sleep 930" accordingly if you need more precision. (Accuracy testing hint: put your camera's display-on time to 3 minutes, set the script's Delay 1st Shot for 4 minutes, see what count-down timer line it ends on just before the screen goes blank (don't jiggle the camera or it resets the display-on time). On my S3 IS the screen went blank just as it was to start counting the 4th minute.)

Well, here's "Take 2" on the subject. I included a table of values that will help compensate for the extended dark-frame subtraction times for exposures over 1 second, and a few of the longer shutter times from 1/4 second to 1 second. So that the total cycle time is more representative. I timed these dark-frame shutter times using a stopwatch so they are prone to human error and reaction-time on my part, but they are all within 1/4th second. I was surprised to find that a 15" exposure actually took 33" to cycle. (The dark-frame exposure times used here for value h are in 10ths of a second, 210 = 21 seconds, in case you are curious how each one panned-out in timing tests.) These delays of longer than "shutter speed X 2" shows there's more going on under the hood than first suspected. But in all cases, even when shutter speeds are much faster there still seems to be a bit of a 1 to 2 second lag when you figure-in for camera processing overhead for each exposure. Use the "Cycle Time" as a general guideline, nothing more. It'll be close to within a few seconds at least. (Because I wasn't sure how much space would be taken up by the dark-frame shutter table, I tightened up the code a bit to make extra room. You might want to compare equivalent strings between this and the older version in case you want to edit the original Ultra Intervalometer for more compact code.)

v1.1 (updated 2007-05-30 c.e.) I forgot to separate the interval delay variable from the calculated time variable with the new black-frame delay times figured in. The interval delay will be accurate again if you use a shutter speed slower than 1/4th second. And a bug with 1 shot, a startup delay, and "endless" is fixed.

@title Ultra Intervalometer @param a Delay 1st Shot (Mins) @default a 0 @param b Delay 1st Shot (Secs) @default b 0 @param c Number of Shots @default c 5 @param d Interval (Minutes) @default d 0 @param e Interval (Seconds) @default e 0 @param f Interval (10th Seconds) @default f 5 @param g Endless? No=0 Yes=1 @default g 0

p=a*600+b*10 t=d*600+e*10+f if c<1 then c=5 if t<1 then t=1 if g<0 then g=0 if g>1 then g=1 if p<0 then p=0 u=t get_tv h if h=-13 then t=t+330 if h=-12 then t=t+270 if h=-11 then t=t+210 if h=-9 then t=t+170 if h=-8 then t=t+130 if h=-7 then t=t+110 if h=-6 then t=t+90 if h=-5 then t=t+70 if h=-4 then t=t+60 if h=-3 then t=t+50 if h=-2 then t=t+40 if h=-1 then t=t+35 if h=0 then t=t+18 if h=1 then t=t+15 if h=2 then t=t+13 if h=3 then t=t+11 if h=4 then t=t+10 if h=5 then t=t+8 if h=6 then t=t+6 x=p+(t*(c-1))

print "1 Cycle Time:", x/600; "min", x%600/10; "sec"

goto "interval"


 * interval

if p>0 then gosub "pause" for n=1 to c print "Shot", n, "of", c  if n>1 then sleep u*100 shoot next n if g=1 then goto "interval" else end


 * pause

n=(a*60)+b for m=1 to n q=n-m print "Intvl Begins:", q/60; "min", q%60; "sec" sleep 930 next m return

Multipurpose Bracketing

 * Written for/on: Powershot A710 IS
 * Also works on: (unknown at this time)

I use this script for taking shots of different exposures for HDR photography. This script can also take shots with varying aperture value or shutter speed. Documentation/Help (save as a small "m-p-bracketing.txt" file to your /SCRIPTS/ folder)

Before running the script, the setting(exposure, aperture, etc.) that is to be varied must be active(by pressing the erase button if necessary). This script takes a number of shots starting at the current value and increase that value for the next shoot. For example, to take 3 pictures with exposures -1, 0, and +1, set the step size to 3 and number of shots to 3. For the A710, set the script shoot delay to at least 11, other cameras should be different. Press erase button and set the exposure to -1. Then go to alt mode and run the script.

Script Code (save as "m-p-bracketing.bas" to your /SCRIPTS/ folder) @title Multipurpose Bracketing @param a Step size @default a 1 @param b Number of shots @default b 3 if a<1 then let a=1 if b<1 then let b=3 click "erase" click "erase" print "Shoot", 1, "of", b shoot for s=2 to b  for n=1 to a     click "right" next n  print "Shoot", s, "of", b   shoot next s let b=b-1 for s=1 to a*b click "left" next s   end

EV bracketing with TV and AV commands
Rem written for A710is by Stebu

There are several commands for getting and setting the aperture and the speed. They only work in Manual mode; well you can change the settings in any mode, but they are effective in manual mode, probably also in Av and Tv modes). The commands are

get_tv target set_tv_rel val set_tv val get_av target set_av_rel val set_av val

Target is the name of a variable (a, b, ..z), val is an expression. I used the following script to study the behaviour of these commands. a controls the execution a=0 reads the current settings, =1 sets Tv=b, =2 sets Av=c, =3 sets both and changes the screen display by performing half_click. a=4 runs the bracketing scritp and takes three shots with -2/3, 0 and + 2/3 corrections to the existing manual settings.

On my camera these seem to work.

rem A710is, Stebu, 17.05.2007 rem testing av and tv commands, use Manual mode @title TV_AV test @param a get setTv Av set_get brkt @default a 0 @param b TV @default b 20 @param c AV @default c 10 @param d delay (10ms) @default d 10 if a=0 then goto "read" if a=1 then goto "set_tv" if a=2 then goto "set_av" if a=3 then goto "set_get" goto "bracket" :set_get set_av c set_tv b print "AV,TV set to",c,b sleep 1000 click "shoot_half" sleep 10*d goto read :read get_av n get_tv m print "AA,TV got",n,m end :set_av set_av c print "AV set to",c end :set_tv set_tv b print "TV set to",b end :bracket rem increase light (1/3+1/3 steps) set_tv_rel 0-1 set_av_rel 0-1 shoot sleep 10*d rem decrease light to original set_tv_rel 1 set_av_rel 1 shoot sleep 10*d rem decrease light set_tv_rel 1 set_av_rel 1 shoot sleep 10*d rem back to original settings? set_tv_rel 0-1 set_av_rel 0-1 click "shoot_half" end

OMNI Intervalometer

 * Written for/on: Powershot S3 IS - CHDK Build 87 (or higher) Required
 * Also works on: S2(?) other models need the ":vid" subroutine modified.
 * Version 1.4 - Updated 2007-05-30 c.e.(see note below)

This script includes a command that only works on S-series cameras, it will not work as-is on A-series cameras. See notes below the script on how to modify this for A-series or other cameras. This version includes a few features that should fit most any need that arises. First you can select if you want to shoot single Still-Frame photos, Videos, or both. You can set a delay in minutes and seconds to the first shot of your intervalometer sequence, the number of shots for the intervalometer sequence, as well as allowing you to flag a Yes or No "Endless" option to repeat the sequence endlessly until you interrupt it manually by pressing the shutter button. Documentation/Help (save as a small "omnintrvl.txt" file to your /SCRIPTS/ folder)

This interval shooting script allows you to choose between photos, videos, or both, as well as set a delay until the first shot in your intervalometer sequence. You may also choose to repeat the sequence endlessly. Use the "Endless" repeat with caution! If that flag is set it repeats non-stop until you interrupt it by pressing the shutter-button. Word of Warning: If you are running off of an AC power-supply and going to set the endless-repeat flag do so at your own risk. You should not allow your camera to run for many hours or days as it can harm your camera! (Though I'm not sure why, other than that warning is in all the Canon manuals.)

These intervalometer scripts that use the "shoot" command (as opposed to the 'click "shoot_full"' command) also set focus and exposure before each shot (if the camera is not in Manual mode). Unlike the camera's own built-in intervalometer where exposure and focus is set for just the first shot. This allows it to compensate for all the varying conditions that can take place over the course of many minutes and hours, far surpassing Canon's concept of a useful intervalometer.

Note 1: The count-down timer for the "Delay to 1st Shot" phase won't display beyond the time you have set for your Power Saving / Display Off settings. On the S3 IS this is a maximum count-down display of 3 minutes. The script will continue running however. You just won't have a running tally of how long until the next intervalometer sequence or shot.

Note 2: If using shutter speeds longer than 1 second, then the dark-frame subtraction time is now figured into the total interval cycle-time. Use the total cycle-time as just a good approximation, as camera overhead for many frames could add up to make the total a bit different than what this script calculates.

Script Code (save as "omnintrvl.bas" to your /SCRIPTS/ folder)

@title OMNI Intervalometer @param a Photo=0 Video=1 Both=2 @default a 0 @param b Delay 1st Shot (Mins) @default b 0 @param c Delay 1st Shot (Secs) @default c 0 @param d Number of Shots/Vids @default d 5 @param e Interval (Minutes) @default e 0 @param f Interval (Seconds) @default f 0 @param g Interval (10th Seconds) @default g 5 @param h Video Minutes @default h 0 @param i Video Seconds @default i 0 @param j Endless? No=0 Yes=1 @default j 0

p=b*600+c*10 t=e*600+f*10+g v=h*600+i*10 if a<0 then a=0 if a>2 then a=2 if d<1 then d=5 if t<1 then t=1 if j<0 then j=0 if j>1 then j=1 if p<0 then p=0 if v<10 then v=10 if a=0 then v=0 u=t get_tv k if a=1 then k=-14 if a=2 then t=t+10*d if k=-13 then t=t+330 if k=-12 then t=t+270 if k=-11 then t=t+210 if k=-9 then t=t+170 if k=-8 then t=t+130 if k=-7 then t=t+110 if k=-6 then t=t+90 if k=-5 then t=t+70 if k=-4 then t=t+60 if k=-3 then t=t+50 if k=-2 then t=t+40 if k=-1 then t=t+35 if k=0 then t=t+18 if k=1 then t=t+15 if k=2 then t=t+13 if k=3 then t=t+11 if k=4 then t=t+10 if k=5 then t=t+8 if k=6 then t=t+6 x=p+(v*d)+(t*(d-1))

print "1 Cycle Time:", x/600; "min", x%600/10; "sec"

goto "interval"


 * interval

if p>0 then gosub "pause" for n=1 to d print "Shot", n, "of", d  if n>1 then sleep u*100 if a=0 then shoot if a>0 then gosub "vid" next n if j=1 then goto "interval" else end


 * pause

r=(b*60)+c for m=1 to r q=r-m print "Intvl Begins:", q/60; "min", q%60; "sec" sleep 930 next m return
 * vid

if a=2 then shoot if a=2 then sleep 1000 click "video" sleep v*100 click "video" return

I timed the :pause subroutine and tweaked the sleep to 930 milliseconds to be about as accurate as possible for that loop to span 1 second for the for/print/next execution time. This was calculated on an S3 IS, your camera's uBASIC speed may vary, tweak "sleep 930" accordingly if you need more precision. (Accuracy testing hint: put your camera's display-on time to 3 minutes, set the script's Delay 1st Shot for 4 minutes, see what count-down timer line it ends on just before the screen goes blank (don't jiggle the camera or it resets the display-on time). On my S3 IS the screen went blank just as it was to start counting the 4th minute.)

I put the routine to engage video on a separate subroutine named ":vid" so it would be easier to modify this for other cameras.

Other camera models (A-series), will have to modify this ":vid" subroutine completely, using the proper key-presses or modes and menus on their cameras. I looked at the code for another video intervalometer script, but it appears that on other cameras that you have to set your camera for video mode from a dial or something, as there are no commands in the script to engage video. If someone else would like to jump in and add a way to include video for them on this script to make it compatible to other cameras that would be great. Because you can test it, whereas I can't.

In order to get around the camera's time requirements for going into and out of different modes when choosing to shoot both still-frame and video, I had to put in a full 1 second delay between the "shoot" and click "video" commands. I compensated for this delay in the overall "print 1 Cycle Time".

p.s. I totally remapped all the variables from earlier versions, just to make this easier to follow for anyone that wants to tear it apart or make it better. Hey? Do I at least get an award for being the first to use up all 10 user-definable variables? :-)

v1.4 Update: Okay, I think I got most of the bugs worked out of it. The problem was in trying to use the old original intervalometer script as my base to work from. I had to rewrite the main :interval routine to get it to accept all these options properly, as well as keep track of total cycle-times properly for all 3 shooting modes (photo-only, video, or photo+video). It appears to be doing everything as planned, if anyone notices some main snafu, please throw a note in the "talk" section.

Next New Script Title
(body of your info and script)

↑↑ Place Next Script Above This Line ↑↑