VC0706 Camera module Problem

I created some Serial.print in the adafruit library.

In the new console log i attached you can see every return and values in every function.
Tell me if it is usefull or if i should do something different.

new_console report.txt (474 KB)

Adafruit_VC0706.cpp (22 KB)

Snapshot.ino (3.67 KB)

The return -1 in getimagesize funtion happens because the runcommand function returns false and it returns false because it steps in this if (line 606 approximatelly):

if (readResponse(resplen, 200) != resplen){
    return false;
  }

the resplen is equal to 6 so readResponse(6,200) !=6
as you can see in the console the readResponse funtion returns the bufferLen which is 0 in this case and 0!=6 so it steps into the if and returns -1.

So I removed the return -1 line and now the getimagesize return the camerabuff[5] which i believe is supposed to be the answer from the camera module from the setimagesize function and even if i change the image size in the sketch ( i mean this) :

  //cam.setImageSize(VC0706_640x480);        // biggest
  //cam.setImageSize(VC0706_320x240);        // medium
  cam.setImageSize(VC0706_160x120);          // small

The camerabuff[5] value is always 51 (DEC) where in the library it is defined as :

#define VC0706_640x480 0x00 (0 DEC)
#define VC0706_320x240 0x11 (17 DEC)
#define VC0706_160x120 0x22 (34 DEC)

i later changed the camerabuff[5] value to 17 (DEC) and of course the if in sketch worked

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");

and printed "image size: 320x240" as 17 is defined as VC0706_320x240.

I read a topic about this that in some vc0706 models the imagesize function doesnt work. maybe thats the case for me.

but i just want to get a picture in my sd. I dont care about the image size.
What Is your opinion?

themtsil:

if (readResponse(resplen, 200) != resplen){

return false;
 }




the resplen is equal to 6 so readResponse(6,200) !=6
as you can see in the console the readResponse funtion returns the bufferLen which is 0 in this case and 0!=6 so it steps into the if and returns -1.

What Is your opinion?

I think the next step is figuring out why readResponse() is returning 0. Is it not getting a response to the command? Is no data arriving from the camera? Is the command not recognized? That would tend to indicate that the library is not the right library for that particular camera.
Did you buy the camera from Adafruit? If not, did the place where you bought the camera provide a datasheet or a library?

The camera I bought is from eBay and I guess it’s not the exact model as adafruit original camera so the library isn’t 100% compatible. The only information I have is the commands I have to send in order to make the camera work.

I found what is the problem and the picture is not displayed correctly thought.
In the adafruit library in readpicture function and it’s argument is of type uint8_t and it is the address of the current write the process is (it start with address 0and increments 32 every write). In the sketch thought when it passes argument in this function it is casted as uint16_t , so it never increments that’s why I get only the top of the image. As soon as I change the type in the cast I got the half image . After the half of the image its value got 0 and my guess is that it reached it’s max value for the current type.

Here is the adafruit readpicture function:

/**************************************************************************/
/*!
    @brief Read in picture data
    @param n Number of bytes
    @returns Pointer to buffer containing n bytes of picture data
*/
/**************************************************************************/
uint8_t *Adafruit_VC0706::readPicture(uint8_t n) {
  uint8_t args[] = {0x0C,
                    0x0,
                    0x0A,
                    0,
                    0,
                    frameptr >> 8,
                    frameptr & 0xFF,
                    0,
                    0,
                    0,
                    n,
                    CAMERADELAY >> 8,
                    CAMERADELAY & 0xFF};

  if (!runCommand(VC0706_READ_FBUF, args, sizeof(args), 5, false))
    return 0;

  // read into the buffer PACKETLEN!
  if (readResponse(n + 5, CAMERADELAY) == 0)
    return 0;

  frameptr += n;

  return camerabuff;
}

And here is the lines in snapshot sketch :

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

but i have another problem now... the camera reply always start with 0x76 0x0 0x26 0x0 0x0 and sometimes it doesnt reply these exact numbers.(for example it starts with 0x77 0x0 0x26 0x0 0x0)
and there is a function for verifying the responses. and basicaly checks if the response starts with 0x76 0x0 0x26 0x0 0x0 and if not it passes out false and then the current operation stops. ( in my case the read write.) so i am left with half image or so . i believe the wrong response happens because i am running at 115200 baud rate which can cause some errors in communication. (happened to me in a previous gsm gps device i was working with. what should i do now?

Here is the verifyresponse function i was talking about:

boolean Adafruit_VC0706::verifyResponse(uint8_t command) {
  if ((camerabuff[0] != 0x76) || (camerabuff[1] != serialNum) ||
      (camerabuff[2] != command) || (camerabuff[3] != 0x0))
    return false;
  return true;
}

If SoftwareSerial is not working with your device I would recommend you get a Leonardo or Micro and use Serial1 or get a MEGA and use Serial1, Serial2, or Serial3.

So i have communications problems (weird character or just wrong) because of software serial ?

themtsil:
So i have communications problems (weird character or just wrong) because of software serial ?

You said you are getting unexpected characters. That could be a communication problem or a mistake in the library. Without the programming manual for the camera, it is hard to say. If the library is right and the communication is wrong then one possible source of error would be pushing SerialMonitor too fast. Switching to a hardware serial port is one way of eliminating that possible source of error.

How can i make this code run for hardware serial ?
I'm confused with using library and hardwareserial.
Do i have to create an object in the beggining like it does with software serial?

Adafruit_VC0706 cam = Adafruit_VC0706(&Serial1);

You can then get rid of the "SoftwareSerial" and "cameraconnection" lines.