Go Down

Topic: [Solved] Software Serial camera on Due (Read 1 time) previous topic - next topic

wnekid

Feb 28, 2018, 11:43 pm Last Edit: Mar 01, 2018, 07:41 pm by wnekid
Hi all,

I'm attempting to use an Adafruit TTL Serial JPEG Camera (VC0706) with an Arduino Due. Although the sample code for this module was intended for an Uno (and I have successfully tested it on one) I'd like to move this project on to a Due.

The issue I'm running into is that the program is dependent on the Software Serial library which isn't intended for the Due. From what I understand this has to be done using the Due's hardware serial pins. Attempting this with the Hardware Serial library didn't lead anywhere as the Due wasn't able to find the camera.

Despite some research I haven't been able to find much information on this subject. Can anyone advise me on what else I can try to do here? The sensor is dependent on Software Serial but getting it to work on the Due is turning into a bigger problem than I intended.



Code that works on my Uno
Code: [Select]
// Snapshot example program on Uno

// Libraries
#include <Adafruit_VC0706.h>
#include <SPI.h>
#include <SD.h>
#include <SoftwareSerial.h>
// Definitions         
#define chipSelect 10


SoftwareSerial cameraconnection = SoftwareSerial(2, 3);
Adafruit_VC0706 cam = Adafruit_VC0706(&cameraconnection);

void setup() {
// Unique SPI pins for either UNO or Mega
#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

  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;
  }

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

  // Wait before taking image
  Serial.println("Snap in 1 second...");
  delay(1000);

  if (! cam.takePicture())
    Serial.println("Failed to snap!");
  else
    Serial.println("Picture taken!");
 
  // 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)) {
      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(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(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('.');
      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");
}

void loop() {
  // Rus only once
}



My attempt at circumventing the serial library (compiles and uploads but can't find camera)
Code: [Select]
// Due

// Libraries
#include <Adafruit_VC0706.h>
#include <SPI.h>
#include <SD.h>
#include <HardwareSerial.h>
// Definitions         
#define cameraconnection Serial1
#define chipSelect 10


Adafruit_VC0706 cam = Adafruit_VC0706(&cameraconnection);

void setup() {

 pinMode(10, OUTPUT);  // SD card Chip select
 pinMode(18, OUTPUT);  // Due TX pin
 pinMode(19, INPUT);   // Due RX pin

  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(38400)) {
    Serial.println("Camera Found:");
  } else {
    Serial.println("No camera found?");
    return;
  }

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

  // Wait before taking image
  Serial.println("Snap in 1/2 second...");
  delay(500);

  if (! cam.takePicture())
    Serial.println("Failed to snap!");
  else
    Serial.println("Picture taken!");
 
  // 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)) {
      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(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(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('.');
      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");
}

void loop() {
  // Rus only once
}

ard_newbie

#1
Mar 01, 2018, 06:25 am Last Edit: Jul 11, 2019, 06:42 am by ard_newbie
If you follow instructions given in the README of the Library to swap from softwareserial to hardwareserial, it should work correctly on a DUE.


https://github.com/Seeed-Studio/Camera_Shield_VC0706

wnekid

Wonderful thanks for the link, I managed to get it working with this library.

rizkipratam

Dear All











In file included from D:\Jangan ganggu\camera\error_compile\error_compile.ino:2:0:

C:\Users\LENOVO\Documents\Arduino\libraries\Adafruit_VC0706_Serial_Camera_Library/Adafruit_VC0706.h:20:29: fatal error: SoftwareSerial.h: No such file or directory

  #include "SoftwareSerial.h"

                             ^

compilation terminated.

exit status 1
Error compiling for board Arduino Due (Programming Port).



Why i'm getting this error when compiling the code??



Go Up