TTL camera with 3.3v arduino pro mini

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
koalaabc
 
Posts: 2
Joined: Mon Apr 07, 2014 11:07 pm

TTL camera with 3.3v arduino pro mini

Post by koalaabc »

Hi everyone,
I'm currently working on a project using a ttl serial camera and arduino pro mini (ATMEGA 328, 3.3v) to take pictures and save it into a 2Gb SD card. However, images have been repeatedly saved with an error (cant open the file at all). Previously, the same setup was used with an Uno and it worked fine. Is the error due to the problem of the pro mini being 3.3v?

To address possible voltage issues, we're running the sd card module and camera module using a 3-cell li-po through a 5v regulator. That did not help to solve the problem. Perhaps you guys will have more insights! I have attached the circuit diagram and the code for your reference (sorry for the ugly handwriting!)

Thank you very much!

Code: Select all

  // 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.

// If using an Arduino Mega (1280, 2560 or ADK) in conjunction
// with an SD card shield designed for conventional Arduinos
// (Uno, etc.), it's necessary to edit the library file:
//   libraries/SD/utility/Sd2Card.h
// Look for this line:
//   #define MEGA_SOFT_SPI 0
// change to:
//   #define MEGA_SOFT_SPI 1
// This is NOT required if using an SD card breakout interfaced
// directly to the SPI bus of the Mega (pins 50-53), or if using
// a non-Mega, Uno-style board.

#include <Adafruit_VC0706.h>
#include <SD.h>

// comment out this line if using Arduino V23 or earlier
#include <SoftwareSerial.h>         

// uncomment this line if using Arduino V23 or earlier
// #include <NewSoftSerial.h>       

// SD card chip select line varies among boards/shields:
// Adafruit SD shields and modules: pin 10
// Arduino Ethernet shield: pin 4
// Sparkfun SD shield: pin 8
// Arduino Mega w/hardware SPI: pin 53
// Teensy 2.0: pin 0
// Teensy++ 2.0: pin 20
#define chipSelect 10
const int led =  8; 
int ledState = LOW;

// Pins for camera connection are configurable.
// With the Arduino Uno, etc., most pins can be used, except for
// those already in use for the SD card (10 through 13 plus
// chipSelect, if other than pin 10).
// With the Arduino Mega, the choices are a bit more involved:
// 1) You can still use SoftwareSerial and connect the camera to
//    a variety of pins...BUT the selection is limited.  The TX
//    pin from the camera (RX on the Arduino, and the first
//    argument to SoftwareSerial()) MUST be one of: 62, 63, 64,
//    65, 66, 67, 68, or 69.  If MEGA_SOFT_SPI is set (and using
//    a conventional Arduino SD shield), pins 50, 51, 52 and 53
//    are also available.  The RX pin from the camera (TX on
//    Arduino, second argument to SoftwareSerial()) can be any
//    pin, again excepting those used by the SD card.
// 2) You can use any of the additional three hardware UARTs on
//    the Mega board (labeled as RX1/TX1, RX2/TX2, RX3,TX3),
//    but must specifically use the two pins defined by that
//    UART; they are not configurable.  In this case, pass the
//    desired Serial object (rather than a SoftwareSerial
//    object) to the VC0706 constructor.

// Using SoftwareSerial (Arduino 1.0+) or NewSoftSerial (Arduino 0023 & prior):
#if ARDUINO >= 100
// On Uno: camera TX connected to pin 2, camera RX to pin 3:
SoftwareSerial cameraconnection = SoftwareSerial(2, 3);
// On Mega: camera TX connected to pin 69 (A15), camera RX to pin 3:
//SoftwareSerial cameraconnection = SoftwareSerial(69, 3);
#else
NewSoftSerial cameraconnection = NewSoftSerial(2, 3);
#endif

Adafruit_VC0706 cam = Adafruit_VC0706(&cameraconnection);

// Using hardware serial on Mega: camera TX conn. to RX1,
// camera RX to TX1, no SoftwareSerial object is required:
//Adafruit_VC0706 cam = Adafruit_VC0706(&Serial1);

void setup() {

  // 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
#else
  if(chipSelect != 10) pinMode(10, OUTPUT); // SS on Uno, etc.
#endif
#endif
  pinMode(led, OUTPUT);
  digitalWrite(led, HIGH);
  Serial.begin(9600);        
  Serial.println("VC0706 Camera snapshot test");
  
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }  
  
  // Try to locate the camera
  if (cam.begin()) {
    Serial.println("Camera Found:");
  } else {
    Serial.println("No camera found?");
    return;
  }
  // Print out the camera version information (optional)
  char *reply = cam.getVersion();
  if (reply == 0) {
    Serial.print("Failed to get version");
  } else {
    Serial.println("-----------------");
    Serial.print(reply);
    Serial.println("-----------------");
  }

  // 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

  // You can read the size back from the camera (optional, but maybe useful?)
  uint8_t imgsize = cam.getImageSize();
  Serial.print("Image size: ");
  if (imgsize == VC0706_640x480) Serial.println("640x480");
  if (imgsize == VC0706_320x240) Serial.println("320x240");
  if (imgsize == VC0706_160x120) Serial.println("160x120");

  Serial.println("Snap in 1 secs...");
  delay(1000);

  if (! cam.takePicture()) 
    Serial.println("Failed to snap!");
  else 
    Serial.println("Picture taken!");
    digitalWrite(led, LOW);
  
  // Create an image with the name IMAGExx.JPG
  char filename[18];
  strcpy(filename, "DCIM/IMAGE00.JPG");
  for (int i = 0; i < 100; i++) {
    filename[10] = '0' + i/10;
    filename[11] = '0' + i%10;
    // create if does not exist, do not open existing, write, sync after write
    if (! SD.exists(filename)) {
      break;
    }
  }
  
  // Open the file for writing
  File imgFile = SD.open(filename, FILE_WRITE);

  // Get the size of the image (frame) taken  
  uint16_t jpglen = cam.frameLength();
  Serial.print("Storing ");
  Serial.print(jpglen, DEC);
  Serial.print(" byte image.");

  int32_t time = millis();
  pinMode(10, 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(32, jpglen); // change 32 to 64 for a speedup but may not work with all setups!
    buffer = cam.readPicture(bytesToRead);
    imgFile.write(buffer, bytesToRead);
    if(++wCount >= 64) { // Every 2K, give a little feedback so it doesn't appear locked up
      Serial.print('.');
      if (ledState == LOW)
        ledState = HIGH;
       else
        ledState = LOW;
      digitalWrite(led, ledState);
      wCount = 0;
    }
    //Serial.print("Read ");  Serial.print(bytesToRead, DEC); Serial.println(" bytes");
    jpglen -= bytesToRead;
  }
  imgFile.close();

  time = millis() - time;
  Serial.println("done!");
  Serial.print(time); Serial.println(" ms elapsed");
  digitalWrite(led, HIGH);
}

void loop() {
  
}
Image
Image

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: TTL camera with 3.3v arduino pro mini

Post by adafruit_support_mike »

Check your memory usage.. IIRC, the Pro Mini uses an ATmega168, while the Uno uses the ATmega328P. You could be running into SRAM limits.

koalaabc
 
Posts: 2
Joined: Mon Apr 07, 2014 11:07 pm

Re: TTL camera with 3.3v arduino pro mini

Post by koalaabc »

hi thanks for the reply, but I don't think that is the problem as I am using an AtMega328. could it be because of other issues?

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: TTL camera with 3.3v arduino pro mini

Post by adafruit_support_mike »

In that case I'd do a head-to-head comparison of a good image and a corrupted one. Open them in a hex editor and see if you can spot any differences in file tags, lengths, etc.

User avatar
rojam06
 
Posts: 8
Joined: Sat Sep 06, 2014 4:41 pm

Re: TTL camera with 3.3v arduino pro mini

Post by rojam06 »

Hello,

I have the same problem, could you fix it?

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: TTL camera with 3.3v arduino pro mini

Post by adafruit_support_mike »

Not without more information.

What kind of hardware are you using, how do you have it connected, and what's the last thing that works as expected before things go wrong?

User avatar
rojam06
 
Posts: 8
Joined: Sat Sep 06, 2014 4:41 pm

Re: TTL camera with 3.3v arduino pro mini

Post by rojam06 »

It was working with Arduino Uno, but when I started using the Arduino Pro Mini it stops working. If I run the Example "Snapshot", I get the error "Camera not found?".

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: TTL camera with 3.3v arduino pro mini

Post by adafruit_support_mike »

Post a photo of your hardware and connections and we'll see what we can find.

User avatar
rojam06
 
Posts: 8
Joined: Sat Sep 06, 2014 4:41 pm

Re: TTL camera with 3.3v arduino pro mini

Post by rojam06 »

I also tried with Teensy 3.1, but I still having the same problem.

I used the Snapshot example included in Adafruit_VC0706 library for Arduino. I only did a modification to the original example, the chipSelect variable is now 2.

The Datalogger example from SD library is working pretty well with chipSelect = 2.

I attach a Eagle Diagram with the connections.
Attachments
TeensyCamera.JPG
TeensyCamera.JPG (40.34 KiB) Viewed 1361 times

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: TTL camera with 3.3v arduino pro mini

Post by adafruit_support_mike »

The TTL camera wants a 5v supply, and 5v devices are hit-and-miss about accepting data from 3.3v devices.

Try adding a level shifter like the 74AHCT125: https://www.adafruit.com/product/1787

That runs from a 5v supply (same as the camera) but will accept 3.3v logic signals as input and convert them to 5v output.

The Teensy 3.1's inputs are 5v tolerant, so while they can't produce 5v output, they can accept 5v input without being damaged.

User avatar
rojam06
 
Posts: 8
Joined: Sat Sep 06, 2014 4:41 pm

Re: TTL camera with 3.3v arduino pro mini

Post by rojam06 »

Thanks for your answer.

Do you have any camera that could be interfaced with the Teensy 3.1 without using a level shifter? Or have you tried using Teensy 3.1 with Raspberry Pi camera https://www.adafruit.com/products/1937 ?

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: TTL camera with 3.3v arduino pro mini

Post by adafruit_support_mike »

All out TTL cameras use the same chipset, so they'll all want the same kinds of signals.

I don't know of anyone using a PiCam with the Teensy, or any code to make the two talk to each other. The interface between the camera and the CPU on the RasPi is fairly intricate, with the CPU having direct access to the camera module's memory.

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”