Est. 2007 Beginner

uBASIC (CHDK)

A tiny, integer-only BASIC dialect embedded in the Canon Hack Development Kit (CHDK) that lets users automate Canon PowerShot cameras with short on-camera scripts.

Created by Adam Dunkels (original uBASIC interpreter); adapted and extended for CHDK by the CHDK community

Paradigm Procedural; imperative scripting
Typing Effectively untyped; 32-bit signed integer variables only
First Appeared 2007 (with the public release of CHDK; based on Adam Dunkels's 2006 uBASIC)
Latest Version Maintained as a component of CHDK (1.6.x is the current stable branch, reportedly released in 2022; 1.7.x is the development trunk)

uBASIC (CHDK) is a tiny, integer-only dialect of BASIC embedded inside the Canon Hack Development Kit (CHDK) — a free, community-built firmware add-on that unlocks extra features on many Canon PowerShot cameras. It is not a general-purpose programming language and was never meant to be. Instead, it exists for a single, focused purpose: letting camera owners write short scripts that run on the camera itself to automate photography — firing the shutter at intervals, reacting to motion, bracketing exposures, or stepping through the zoom — using nothing but the camera and an SD card.

CHDK does not modify a camera’s factory firmware permanently. It loads from the memory card at boot, adding an overlay of extra capabilities (RAW capture, live histograms, additional exposure control, and scripting) on top of what Canon shipped. uBASIC is the original scripting language of that overlay, and for many years it was the friendliest way for non-programmers to make a camera do something clever on its own.

History & Origins

The story of uBASIC (CHDK) has two threads that meet in 2007.

The first thread is the interpreter itself. In 2006, Swedish researcher Adam Dunkels — well known for the Contiki operating system and the lightweight uIP TCP/IP stack — wrote uBASIC, “a really tiny BASIC interpreter,” in roughly 700 lines of C. He built it during a session at the ACM/USENIX MobiSys 2006 conference as a compact scripting language for systems where memory is scarce, sometimes only a few hundred bytes of RAM. Dunkels released it under a permissive BSD-style license, which is precisely what made it attractive to embed elsewhere. (This uBASIC is unrelated to the older UBASIC written by Yuji Kida for mathematical computation — a common point of confusion.)

The second thread is CHDK. In 2007, an anonymous programmer using the handle VitalyB reverse-engineered parts of the firmware on Canon’s PowerShot cameras and publicly released the Canon Hack Development Kit. Other developers quickly joined in and broadened it. CHDK needed a way to let ordinary users automate their cameras, and Dunkels’s BSD-licensed uBASIC was small enough to fit in the extremely tight resources of a compact camera. CHDK adopted a modified version of it, and uBASIC became the project’s first scripting language.

Through the rest of 2007, the scripting side of CHDK grew rapidly. Separate development branches such as SDM appeared, motion-detection support was added, and a contributor known as Fingalo produced an expanded set of uBASIC commands specific to camera control. In 2008, the developer Velo brought Lua 5.1 to CHDK as a more powerful alternative, and from that point on both languages have coexisted in the project.

Design Philosophy

uBASIC’s design is defined almost entirely by constraint. It targets an environment with very little memory and a slow processor, controlled by someone who may never have programmed before. The result is deliberately minimal:

  1. Small enough to fit anywhere. The whole interpreter is a few hundred lines of C, so it can run inside firmware overlays with almost no headroom.
  2. Simple enough for beginners. The command set is the familiar core of classic BASIC — no objects, no modules, no libraries to learn.
  3. Do one job well. In CHDK, that job is camera automation. The language stays tiny; the interesting power lives in the CHDK-specific commands bolted onto it.

The trade-off is real. As CHDK’s own documentation and community readily acknowledge, uBASIC is very primitive compared with Lua, and experienced script authors generally prefer Lua for anything complex. uBASIC’s value is its approachability: for a simple intervalometer or a motion trigger, a few lines of BASIC are often all you need.

Key Features

Because it inherits Dunkels’s core, CHDK uBASIC supports only the essentials of BASIC:

  • Control flow: if / then / else, for / next, goto, and gosub / return.
  • Assignment and output: let for variables and print for on-screen text.
  • Integer arithmetic: mathematical expressions on whole numbers only — there is no native floating-point type.
  • Variables: originally limited to single-letter names holding 32-bit signed integers. Fingalo’s CHDK extensions expanded this so that both lower- and upper-case letters (a–z and A–Z) can be used, for a total of 52 distinct variables.

Layered on top are the CHDK-specific commands that make the language useful for photography. These include camera actions like shoot, sleep (to pause, e.g. sleep 1500 for 1.5 seconds), and button emulation such as click, press, and release; functions to read and set camera state (for example get_tv to read the current shutter value); and a powerful motion-detection command that accepts up to sixteen parameters to control sensitivity, regions, and timing.

Every script also begins with a small header of metadata comments that CHDK reads. The @title tag names the script, and @param / @default declare user-adjustable parameters that appear in the on-camera script menu, so a user can tweak values (like shot count or interval) without editing code. A minimal time-lapse illustrates the style:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
@title Interval Shooting
@param a Shots
@default a 10
@param b Interval (sec)
@default b 5

let n = 0
:loop
  shoot
  let n = n + 1
  if n >= a then end
  sleep b * 1000
goto loop

The interpreter is non-interactive — there is no REPL or command line. Scripts are written on a computer, saved to the SD card, selected from CHDK’s menu, and run on the camera.

Evolution

uBASIC (CHDK) has evolved less as a language and more as part of CHDK’s overall maturation. The early years (2007–2009) saw a proliferation of special builds, each sometimes carrying slightly different uBASIC commands; scripts written for one build did not always run on another. Around 2009 the project consolidated into a single unified development trunk, which standardized the scripting interfaces and made scripts far more portable across cameras and versions.

CHDK then moved through a series of stable branches — 1.0 and 1.1 around 2012, 1.2, and 1.3 in the years following — with 1.6.x becoming the current stable branch (1.6.1 was reportedly released in 2022) and a 1.7.x development trunk continuing after. Across these releases uBASIC has remained largely stable in its core, receiving incremental refinements (such as the expanded variable set and header options) rather than sweeping redesigns, while most new scripting energy has gone into Lua.

Current Relevance

uBASIC still ships in current CHDK builds and continues to run the large archive of community scripts accumulated on the CHDK wiki and forums over nearly two decades. For newcomers writing their first camera script, its simplicity remains a genuine advantage. For anything ambitious, though, the community consistently steers authors toward Lua, which offers real data types, functions, tables, and a far richer API.

CHDK as a whole remains an active project with a dedicated following among photographers who value the ability to turn inexpensive Canon compacts into programmable instruments. As long as those cameras and CHDK endure, uBASIC persists as their approachable, if humble, scripting entry point.

Why It Matters

uBASIC (CHDK) is a small but genuine piece of programming history — a case study in how a well-scoped, permissively licensed micro-language can escape its original niche and end up in the hands of thousands of people who would never call themselves programmers. Adam Dunkels wrote it for tiny embedded computers; CHDK put it inside cameras, where it enabled an entire subculture of DIY time-lapse, motion-triggered, and near-space photography.

Its significance is not in language design innovation — it is deliberately conservative BASIC — but in accessibility and reach. It shows how the classic BASIC idea of a friendly, learnable language for non-specialists, combined with open-source firmware hacking, can unlock creative control over consumer hardware the manufacturer never intended to expose.

Timeline

2006
Adam Dunkels writes uBASIC, a tiny BASIC interpreter in roughly 700 lines of C, intended for severely memory-constrained embedded systems and released under a BSD-style license
2007
An anonymous developer known as VitalyB publicly releases the Canon Hack Development Kit (CHDK) for Canon PowerShot cameras, which includes a modified version of Dunkels's uBASIC as its first scripting language
2007
Contributors expand CHDK scripting: the SDM branch appears around June, motion-detection work follows, and Fingalo contributes an enhanced set of uBASIC scripting commands (around September)
2008
Lua 5.1 is brought to CHDK (introduced on the forum by the developer known as Velo, around April), giving script authors a more capable alternative alongside uBASIC
2009
CHDK development consolidates into a single unified trunk, standardizing the uBASIC and Lua scripting interfaces after a period of divergent special builds
2012
CHDK reaches its 1.0 stable milestone (a build from mid-July 2012 was conserved as the 1.0.0 stable branch), with the 1.1 line following shortly after
2013
The CHDK 1.2 stable line is established, continuing to ship both uBASIC and Lua scripting
2014
CHDK 1.3 development adds refinements to uBASIC, including support for both upper- and lower-case single letters as @param variables in the script header

Notable Uses & Legacy

Time-lapse and intervalometer scripts

One of the most common uses of CHDK uBASIC is driving interval shooting: short scripts loop with sleep delays and shoot commands to capture frames at fixed intervals for time-lapse photography, all without any external trigger hardware.

Motion-detection triggering

uBASIC scripts use CHDK's motion-detection command to fire the shutter when the scene changes, a technique popular for wildlife, lightning, and high-speed photography where reaction time matters more than a human finger.

Exposure and focus bracketing

Scripts read and set camera parameters (such as shutter and aperture values) in loops to automate exposure, focus, and ISO bracketing sequences that would be tedious to perform by hand.

Near-space and kite/balloon photography

Because a cheap Canon PowerShot running a CHDK script can shoot automatically and unattended, uBASIC intervalometers have been widely used in high-altitude balloon, kite (KAP), and amateur near-space imaging projects.

Camera automation and testing

Hobbyists and researchers use uBASIC to script repeatable camera actions — pressing buttons, zooming, and capturing — to turn inexpensive point-and-shoot cameras into programmable, remotely controllable imaging devices.

Language Influence

Influenced By

BASIC Tiny BASIC

Running Today

Run examples using the official Docker image:

docker pull
Last updated: