Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.

Digital Camera Using Arduino Uno and TTL Serial Camera
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Digital Camera Using Arduino Uno and TTL Serial Camera

by ebryan9 on Thu Aug 06, 2020 5:45 pm

Hello, I have been working on a project based off of the Snapshot example code from the TTL Serial Camera library, but have been having trouble. I have tried to modify the code and wiring so that the board is powered by a battery and photos can be taken by pushing a momentary push button. I tested the sd card using the SD examples and the ttl camera using the snapshot code.

When I adjusted the code to use a push button, I only get empty photos or a pixelated image.

Code: Select all | TOGGLE FULL SIZE
// This is a basic snapshot sketch using the VC0706 library.
// On start, the Arduino will find the camera and SD card and
// then snap a photo, saving it to the SD card.
// Public domain.

#include <Adafruit_VC0706.h>
#include <SPI.h>
#include <SD.h>
const int buttonPin = 6;
int buttonState = 0;  // variable for reading the pushbutton status
#if defined(__AVR__) || defined(ESP8266)

// On Uno: camera TX connected to pin 2, camera RX to pin 3:
#include <SoftwareSerial.h>         
SoftwareSerial cameraconnection(2, 3);

#define cameraconnection Serial1


Adafruit_VC0706 cam = Adafruit_VC0706(&cameraconnection);

// SD card chip select line varies among boards/shields:
// Adafruit SD shields and modules: pin 10
#define chipSelect 10
void setup() {
    pinMode(buttonPin, INPUT);  // initialize the pushbutton pin as an input:

  // When using hardware SPI, the SS pin MUST be set to an
  // output (even if not connected or used).  If left as a
  // floating input w/SPI on, this can cause lockuppage.
#if !defined(SOFTWARE_SPI)
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
  if(chipSelect != 53) pinMode(53, OUTPUT); // SS on Mega
  if(chipSelect != 10) pinMode(10, OUTPUT); // SS on Uno, etc.

SD.begin(chipSelect);//begin sd card communication


void loop() {
   buttonState = digitalRead(buttonPin);

  if (buttonState == HIGH)


  // Create an image with the name IMAGExx.JPG
  char filename[13];
  strcpy(filename, "IMAGE00.JPG");
  for (int i = 0; i < 100; i++) {
    filename[5] = '0' + i/10;
    filename[6] = '0' + i%10;
    // create if does not exist, do not open existing, write, sync after write
    if (! SD.exists(filename)) {
  // Open the file for writing
  File imgFile =, FILE_WRITE);

  // Get the size of the image (frame) taken 
  uint16_t jpglen = cam.frameLength();

  int32_t time = millis();
  pinMode(8, OUTPUT);
  // Read all the data up to # bytes!
  byte wCount = 0; // For counting # of writes
  while (jpglen > 0) {
    // read 32 bytes at a time;
    uint8_t *buffer;
    uint8_t bytesToRead = min((uint16_t)32, jpglen); // change 32 to 64 for a speedup but may not work with all setups!
    buffer = cam.readPicture(bytesToRead);
    imgFile.write(buffer, bytesToRead);
     //Serial.print("Read ");  Serial.print(bytesToRead, DEC); Serial.println(" bytes");
    jpglen -= bytesToRead;

  time = millis() - time;


Do I need to add a delay somewhere to allow the photo to process? I'm not sure what I have done wrong. I have attached a sketch of the circuit.
Thank you!
Sdcard1.png (127.46 KiB) Viewed 23 times

Posts: 1
Joined: Thu Aug 06, 2020 5:28 pm

Please be positive and constructive with your questions and comments.