TTL Serial Camera
TTL Serial Camera
https://learn.adafruit.com/ttl-serial-camera
Overview 3
• Sample Images 4
Using CommTool 8
• Despite the software letting you change the baud rate this is a very flaky setting and even if it works, when you
power up the camera again it will reset. Some experimenters have accidentally disabled their cameras by trying
to change the baud rate. We do not suggest you mess with the baud rate settings. If you do, you may
permanently disable your camera and we will not replace it! 13
• 13
Arduino Usage 15
• Taking a Snapshot 16
• Detecting Motion 17
• Adjusting the Manual Focus 18
Python Docs 31
F.A.Q. 31
Downloads 32
• Unsupported Alternate libraries 33
Since it is a little confusing how this is both a snapshot and video camera, we'd like to
explain it in detail now. The module was initially designed for surveillance purposes.
Its meant to constantly stream TV-resolution video out of the Video pin (this is NTSC
monochrome format) and also take commands from the serial port. The serial port
commands can request that the module freeze the video and then download a JPEG
color image. So for example, normally its just displaying video to a security monitor.
When motion is detected, it would take a photo and save it to a disk for later analysis.
The module is admittedly not extremely high resolution - the maximum image size it
can take is 640x480 pixels. And it is sensitive to infrared light, which alters the color
rendition somewhat. The reason for all this is that it's meant for surveillance, not for
nature photography. However, as far as we can tell, this is the best module on the
market.
Sample Images
Here are two example images, one of outside during a cloudy day, and one inside on
a sunny day.
If you aren't planning to use the video output abilities, you can use 4 wires. We will
use red for the +5V pin, black for the Ground pin, white for the RX pin (data into the
module) and green for the TX pin (data from the module)
Most TV's and monitors require an RCA jack or plug input. We just soldered a spare
RCA jack to the camera, with black being the case ground and yellow signal. You can
get RCA cables and accessories in any hobby/electronics shop like Radio Shack.
Unfortunately, it is not possible to change the camera from NTSC to PAL - its
hardcoded by a pin soldered to the board and there's no easy way to extract it and
change it (we tried!)
Plug in the NTSC cable to your monitor, and connect the red and black power wires to
We have some NTSC television modules in the Adafruit shop you can use to test with
(https://adafru.it/aM5)
Using CommTool
To use the Comm Tool, a windows utility, we need to set up a serial link to the camera.
There's two ways we suggest doing this. One is to use something like an FTDI friend
or other USB/TTL serial converter. If you have an Arduino you can 'hijack' the serial
chip (FTDI chip or similar) by uploading a blank sketch to the Arduino:
// empty sketch
void setup()
{
}
void loop()
Note: 'Hijacking' the serial port only works on Arduinos with a separate USB
interface, like the Uno. It won't work on a Leonardo!
//Leo_passthru
// Allows Leonardo to pass serial data between
// fingerprint reader and Windows.
//
// Red connects to +5V
// Black connects to Ground
// Green goes to Digital 0
// White goes to Digital 1
void setup() {
Serial1.begin(57600);
Serial.begin(57600);
}
void loop()
{
while (Serial.available())
Serial1.write(Serial.read());
while (Serial1.available())
Serial.write(Serial1.read());
}
Note the 10K resistor divider, the camera's serial data pins are 3.3v logic and its a
good idea to divide the 5V down so that its 2.5V. Normally the ouput from the digital
0 pin is 5V high, the way we connected the resistors is so the camera input (white
wire) never goes above 3.3V
Now download and install the VC0706 CommTool software (see below in the
Download section)
Start up the software and select the COM port that the Arduino is on.
Note it says VC0703 - we don't know precisely why the DSP is programmed with a
different number - its one of those mysteries! Still, you should get a response
The next button you should press is near the bottom FBUF CTRL.
Next press Read (next to Sel File) to read the jpeg image off the camera
You might notice there's a dropdown for changing the baud rate. By default the
baudrate is 38400 baud.
The only other thing we suggest checking out is the Image Property button, which will
let you adjust settings for the camera, we bumped up our saturation a bit to get better
images. Dragging the sliders will make the video output change immediately so this is
a handy place to get a TV connected up so you can check out how it works
Arduino Usage
Next up, we will wire the camera to our microcontroller (in this case an Arduino). This
is pretty similar to the above except we will be using two digital pins and a software
serial port to talk to the camera. To save images, you'll need some sort of external
storage like our microSD breakout board (http://adafru.it/254).
For the weatherproof camera, the white and green wires are swapped on some
cameras! So please flip the white and green wires indicated if using the metal
camera. Red should still be connected to +5 and Black to Ground
If you're using Arduino v23 or earlier, you'll also need to install the NewSoftSerial
library. Download it by clicking this link (https://adafru.it/aM7) and install it as you did
the Adafruit_VC0706 library. Arduino 1.0 has this built in now (called SoftwareSerial)
Taking a Snapshot
OK now you're finally ready to run the snapshot demo. Open up the Arduino IDE and
select File-> Examples-> Adafruit_VC0706-> Snapshot sketch and upload it to the
Arduino. Open up the serial monitor and you can see the sketch will take a 640x480
photo and save it to the microSD card. You can then pop the card into your computer
to see the JPG file
There are a few things you can change once you get it working. One is changing the
pins the camera uses. You can use any two digital pins, change this line:
You can also change the snapshot image dimension to 160x120, 320x240 or 640x480
by changing these lines:
// Set the picture size - you can choose one of 640x480, 320x240 or 160x120
// Remember that bigger pictures take longer to transmit!
cam.setImageSize(VC0706_640x480); // biggest
//cam.setImageSize(VC0706_320x240); // medium
//cam.setImageSize(VC0706_160x120); // small
Simply uncomment the size you want, and comment out the others. Bigger pictures
will take longer to snap, so you will want to think about how fast you need to grab
data and save it to the disk
Detecting Motion
A neat thing that the camera has built in is motion detection. It will look for motion in
the video stream and alert the microcontroller (by sending a serial data packet) when
motion is detected. IN this way you can save a bit of cash and skip on having a PIR
sensor (although a PIR sensor will be better at detecting warm mammalian things).
// Motion detection system can alert you when the camera 'sees' motion!
cam.setMotionDetect(true); // turn it on
//cam.setMotionDetect(false); // turn it off (default)
You'll need to 'poll' the camera to ask it when motion is detected, by calling motionD
etected()- it will return true if motion was recently detected, and false otherwise.
You can use this camera with any CircuitPython microcontroller board or with a
computer that has GPIO and Python thanks to Adafruit_Blinka, our CircuitPython-for-
Python compatibility library (https://adafru.it/BSN).
Here you have two options: An external USB-to-serial converter, or the built-in UART
on the Pi's TX/RX pins. Here's an example of wiring up the USB-to-serial converter (ht
tps://adafru.it/dDd):
If you want to use the built-in UART, you'll need to disable the serial console and
enable the serial port hardware in raspi-config. See the UART/Serial section of the
CircuitPython on Raspberry Pi guide (https://adafru.it/CEk) for detailed instructions on
how to do this.
All single board computers are a bit different. Some expose the serial port/UART,
others have it soft connected to the console, while others do not allow UART use
by the user. Please see your board documentation to see what using your board
UART may entail.
First make sure you are running the latest version of Adafruit CircuitPython (https://
adafru.it/Amd) for your board.
Next you'll need to install the necessary libraries to use the hardware--carefully follow
the steps to find and install these libraries from Adafruit's CircuitPython library bundle
(https://adafru.it/ENC). The Welcome to CircuitPython guide has a great page on how
to install the library bundle (https://adafru.it/ABU).
• adafruit_vc0706.mpy
• adafruit_sd.mpy
• adafruit_bus_device
Before continuing, make sure your board's lib folder has the adafruit_vc0706.mpy,
adafruit_sd.mpy, and adafruit_bus_device files and folders copied over.
Once that's done, from your command line run the following command:
If your default Python is version 3 you may need to run 'pip' instead. Just make sure
you aren't trying to use CircuitPython on Python 2.x, it isn't supported!
import time
import board
import busio
import digitalio
import storage
import adafruit_sdcard
import adafruit_vc0706
# Configuration:
SD_CS_PIN = board.D10 # CS for SD card (SD_CS is for Feather Adalogger)
IMAGE_FILE = "/sd/image.jpg" # Full path to file name to save captured image.
# Will overwrite!
# Set the baud rate to 115200 for fastest transfer (its the max speed)
vc0706.baudrate = 115200
# Take a picture.
print("Taking a picture in 3 seconds...")
time.sleep(3)
print("SNAP!")
if not vc0706.take_picture():
raise RuntimeError("Failed to take picture!")
You should see output like the following as the program prints information about the
camera and saves an image to the micro SD card:
Be aware saving the image to the card takes some time, as the data is transferred
over both a serial connection from the camera and the SPI connection to the micro SD
card. A full image capture at 640x480 pixels takes about 30 seconds, but might take
longer depending on your board and micro SD card speed.
Woo hoo, that's all there is to the basics of capturing an image with the serial TTL
camera and CircuitPython! Let's look at the code in a tiny bit more detail to
understand the usage.
First the example needs to setup the SD card and mount it on the filesystem. This is
all boilerplate code from the CircuitPython SD card guide (https://adafru.it/CaX) (highly
recommended to read it too!):
# Configuration:
SD_CS_PIN = board.D10 # CS for SD card (SD_CS is for Feather Adalogger)
IMAGE_FILE = '/sd/image.jpg' # Full path to file name to save captured image.
# Will overwrite!
Now the VC0706 module is setup and an instance of the VC0706 class is created.
Notice we need to create a UART device on whatever pins have hardware support
and then this is passed to the camera creator.
Once the VC0706 instance is created you can read some interesting properties, like
the version string:
Or even set and get the size of the image (640x480, 320x240, 160x120):
Now the real fun, you can capture an image! This works by first telling the camera to
'freeze' the current image frame in memory with the take_picture function. Then
you need to make a loop that calls the read_picture_into function repeatedly to
grab buffers of image data from the camera. Once you have image data it's up to you
to do something with it, like write it to a SD card file (although you don't have to do
that, you could send it to a web service or do other fun thing!).
The code in this example will capture an image and then save it to a file on the SD
card:
# Take a picture.
print('Taking a picture in 3 seconds...')
time.sleep(3)
print('SNAP!')
if not vc0706.take_picture():
raise RuntimeError('Failed to take picture!')
One thing to be aware of is that the size of the buffer passed to read_picture_into
must be a multiple of 4. This is an requirement of the camera hardware itself. In
addition, it must be below 100 to fit within an internal buffer. Stick with using a value
of 32 like the example here shows!
That's all there is to capturing and saving an image to an SD card using CircuitPython!
Also be aware internal storage is quite limited on some boards. The non-express
boards only have ~64kb or space and a single 640x480 JPEG image from the camera
can occupy 50 kilobytes of more of space alone! You likely only want to save images
to the internal storage for Express boards that have 2 megabytes of space, however
even on those boards take care to not store too many images as they will quickly add
up
To get started first follow the steps on the CircuitPython Storage page of the
CircuitPython Essentials guide (https://adafru.it/DlE) to enable writing to internal
storage. In particular edit the boot.py on your CIRCUITPY drive (creating it if it doesn't
exist) and add these lines:
import digitalio
import board
import storage
switch = digitalio.DigitalInOut(board.D5)
switch.direction = digitalio.Direction.INPUT
switch.pull = digitalio.Pull.UP
Remember once you remount("/") you cannot edit code over the USB drive anymore!
That means you can't edit boot.py which is a bit of a conundrum. So we configure the
boot.py to selectively mount the internal filesystem as writable based on a switch or
even just alligator clip connected to ground. Like the CPU temperature guide shows (
https://adafru.it/BuV). In this example we're using D5 but select any available pin.
This code will look at the D5 digital input when the board starts up and if it's
connected to ground (use an alligator clip or wire, for example, to connect from D5 to
board ground) it will disable internal filesystem writes and allow you to edit code over
the USB drive as normal. Remove the alligator clip, reset the board, and the boot.py
will switch to mounting the internal filesystem as writable so you can log images to it
again (but not write any code!).
Remember when you enable USB drive writes (by connecting D5 to ground at startup)
you cannot write files to the internal filesystem and any code in your code.py that
attempts to do so (like the example below) will fail. Keep this in mind as you edit
code, once you modify code you need to remove the alligator clip, reset the board to
re-enable internal filesystem writes, and then watch the output of your program.
If you ever get stuck, you can follow the steps mentioned in https://
learn.adafruit.com/cpu-temperature-logging-with-circuit-python/writing-to-the-
filesystem to remove boot.py from the REPL if you need to go back and edit code!
Now we can use a slightly modified version of the example that will save to the
internal filesystem instead of a SD card. The code is exactly the same as for SD cards
except instead of mounting the SD card and opening a file there, we open a file on
the internal storage. The exact same VC0706 functions and control loop are used
because Python's read and write functions don't care if they're writing to a SD card or
internal storage--it's all the same to Python!
import time
import busio
import board
import adafruit_vc0706
# Set this to the full path to the file name to save the captured image. WILL
OVERWRITE!
# CircuitPython internal filesystem configuration:
IMAGE_FILE = "/image.jpg"
# USB to serial adapter configuration:
# IMAGE_FILE = 'image.jpg' # Full path to file name to save captured image. Will
overwrite!
# Raspberry Pi configuration:
# IMAGE_FILE = '/home/pi/image.jpg' # Full path to file name to save image. Will
overwrite!
# Note you can also read the property and compare against those values to
# see the current size:
size = vc0706.image_size
if size == adafruit_vc0706.IMAGE_SIZE_640x480:
print("Using 640x480 size image.")
elif size == adafruit_vc0706.IMAGE_SIZE_320x240:
# Take a picture.
print("Taking a picture in 3 seconds...")
time.sleep(3)
print("SNAP!")
if not vc0706.take_picture():
raise RuntimeError("Failed to take picture!")
To comment out a line of code, put a '#' before the line of code. To uncomment a
line of code, delete the '# ' (including the space!) before the line of code.
# import serial
Raspberry Pi / Linux
If using a Raspberry Pi, uncomment the following lines (if you're using a different
single board computer, you may need to update the serial port!):
# import serial
Python Docs
Python Docs (https://adafru.it/GBi)
F.A.Q.
Can I change the baud rate on this Camera?
You might notice there seems to be a command for changing the baud rate. By
default the baudrate is 38400 baud.
Despite the software letting you change the baud rate this is a very flaky setting
and even if it works, when you power up the camera again it will reset. Some
experimenters have accidentally disabled their cameras by trying to change the
A more natural rendering can be achieved using an IR blocking filter such as a B+W
486 (https://adafru.it/d2t). (Thanks to forum member azhilyakov for the comparison
photos!)
Downloads
VC0706 Comm Tool - Windows control software (https://adafru.it/wcC) (works in
Parallels in MacOSX. We do not have source code for this tool in order to directly port
it to Mac/Linux)