Writing the Python program

Download this CodeBug photographer program to your Pi or open a text editor from a Terminal on your Raspberry Pi to write your program in:

nano codebug_camera.py

Enter the following code:

import picamera

import codebug_tether

import time

# Now set up the CodeBug connection

cb = codebug_tether.CodeBug()

cb.set_leg_io(0, 1)

# Set up the camera

with picamera.PiCamera() as camera:

    camera.resolution = (1024, 768)

    camera.start_preview()

    time.sleep(2)

    # Wait until the leg is touched

    while cb.get_input(0):

        time.sleep(0.1)

    # take the picture

    camera.capture('your_image_name.jpg')

Save your program and run it to check everything works:

python codebug_camera.py

Check your picture looks ok by viewing it in the file browser or by installing fim:

sudo apt-get install links2

Then use the following command:

links -g your_image_name.jpg

Back to top