TTL Serial Camera: Created by Lady Ada
TTL Serial Camera: Created by Lady Ada
TTL Serial Camera: Created by Lady Ada
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)
If you have the weatherproof version of this camera, it comes prewired with the following:
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 +5V supply - you should get
monochrome video output on the monitor immediately!
We have some NTSC television modules in the Adafruit shop you can use to test with (https://adafru.it/aM5)
// 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!
If you're using a Leonardo, Micro, Yun, or other ATmega32U4-based controller, use this Leo_passthru sketch instead
of the "blank" sketch.
//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.
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!
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
We suggest testing the microSD card first. Check out our microSD breakout board tutorial and verify that you can read
from the card by listing the files. Once you have verified the microSD card wiring, you can come back here and install
the VC0706 camera library.
Visit the Github repository here. (https://adafru.it/aM6) To download. click the DOWNLOADS button in the top right
corner, rename the uncompressed folder Adafruit_VC0706. Check that the Adafruit_VC0706 folder contains
Adafruit_VC0706.cpp and Adafruit_VC0706.h Place the Adafruit_VC0706 library folder your
arduinosketchfolder/libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the
IDE.
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
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).
Load up the File-> Examples-> Adafruit_VC0706-> MotionDetect sketch and upload it to the Arduino. It will take a
photo immediately because it just turned on. Then wait a few minutes and wave you hand in front of the camera, it will
take another photo.
// 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 motionDetected()- 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 (https://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).
After downloading the bundle, copy the necessary libraries from the bundle:
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.
Next connect to the board's serial REPL (https://adafru.it/Awz) so you are at the CircuitPython >>> prompt.
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!
You should see output like the following as the program prints information about the camera and saves an image to
the micro SD card:
Exit the REPL and power down the board, then remove the SD card and connect it to your computer. You should see
an image.jpg file saved on it, and inside will be a picture captured from the camera:
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!):
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:
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!
Example Code for saving to internal file system (CircuitPython or Linux / SBC)
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!
Regardless of which set up you're using, you'll need to comment out the following line:
# 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
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 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!
This is a pretty slow UART camera, it can take up to 30 seconds to transfer an image! It is meant for snapshots or
time-lapse type photography, not for any kind of real-time analysis
Because it was designed for surveillance, the sensitivity of the camera extends into the infrared range. This means
that objects that reflect or emit infrared rays will appear lighter than the do to the human eye. In some cases the
image will appear washed out and almost monochromatic.
A more natural rendering can be achieved using an IR blocking filter such as a B+W 486. (Thanks to forum member
azhilyakov for the comparison photos!)