Step 1

Make a directory inside your "tessel-code" folder: enter mkdir camera into your command line, then change directory into that folder: cd camera

Step 2

Plug the camera module into Tessel port A with the hexagon/icon side down and the electrical components on the top, then plug Tessel into your computer via USB.

Step 3

Install by typing npm install camera-vc0706 into the command line.

Step 4

Save this code in a text file called camera.js:

// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/publicdomain/zero/1.0/

/*********************************************
This camera example takes a picture. If a
directory is specified with the --upload-dir
flag, the picture is saved to that directory.
*********************************************/

var tessel = require('tessel');
var camera = require('camera-vc0706').use(tessel.port['A']);

var notificationLED = tessel.led[3]; // Set up an LED to notify when we're taking a picture

// Wait for the camera module to say it's ready
camera.on('ready', function() {
  notificationLED.high();
  // Take the picture
  camera.takePicture(function(err, image) {
    if (err) {
      console.log('error taking image', err);
    } else {
      notificationLED.low();
      // Name the image
      var name = 'picture-' + Math.floor(Date.now()*1000) + '.jpg';
      // Save the image
      console.log('Picture saving as', name, '...');
      process.sendfile(name, image);
      console.log('done.');
      // Turn the camera off to end the script
      camera.disable();
    }
  });
});

camera.on('error', function(err) {
  console.error(err);
});

Step 5

In your command line, tessel run camera.js --upload-dir ./
The flag --upload-dir lets you specify where to save the image. Uploading to . saves the image in the current directory. Otherwise set process.env.TESSEL_UPLOAD_DIR to run without the flag.

Take pictures!

Bonus: Change the code to take an image with a different resolution. (Hint: you might have to check the documentation.)

To see what else you can do with the camera module, see the module docs here.

Step 6

What else can you do with a camera module? Try a community-created project.


What are you making? Share your invention!

If you run into any issues you can check out the camera forums.

Choose another module

Or if you're all set, move on to Wifi.

Fork on Github