VC0706 PTC06 v1.0 Can't figure out why I can't get the FBUF lengths

Ok, I'm still really new to all of this. Originally I bought an OV7670, but was convinced that maybe I should start with an easier camera module. So, I ordered this one:

http://www.ebay.com/itm/Miniature-Serial-Camera-Module-TTL-UART-interface-DC3-3V-5V-/300925192012?pt=Home_Automation_Controls_Touchscreens&hash=item46108a074c

Well, I was too excited and couldn't wait for it to get here, so I went to the RS and picked up their camera board and started experimenting. The example sketch worked, so I started digging through the protocol sheets to find the commands, study the code and write as much of it I could for myself.

Well, now I have everything going except when I execute the GET_FBUF_LEN, I get nothing but zeros. I've gone over this code 100 times and still can't seem to find where I went wrong. I'm no longer using the RS module(it was still a VC0706, but it's a LONG story), and just using the one provided in the link. I spliced the wires and soldered extension wires on so I wouldn't need to buy a 5 pin connector, then taped the connections, but I know that's not the problem because every other command comes back good.

Can anyone help? I've put 3 weeks into this so far and I just want to see it through to the end. I have no clue how to write data from an object to an SD, so I copied the example code but it still doesn't work, but it won't since I can't get a good return from the fbuf length.

I should note, I'm able to get pictures and lengths from the CommTool, just not from code.

the HEX I send to the module for fbuf length is:

56 00 34 01 00

Everything I've checked, including the worst directions ever that came with this one, show's that this is the correct information.

No code?

Read this before posting a programming question

How to use this forum

Well, I was looking more for anyone who had similar experience with this module and wondering if there was a different sequence of commands than the ones I listed for the get_fbuf_Len command that I gave. As for actual code, if it's a necessity, then I'll have to add that later when I get time as I'm about to head out the door to go
to work.

The basics are this:

void getFbufLen()
{
  sendBuffer[0] = 0x56;
  sendBuffer[1] = 0x00;
  sendBuffer[2] = 0x34;
  sendBuffer[3] = 0x01;
  sendBuffer[4] = 0x00;

  sendCount = 5;
}
[/ code]  

Like I said though, the rest of the commands work. I've debugged it, but that one doesn't seam to return

Sorry, phone froze before I could get the rest of that out. The sending code goes like this:

void bufferSend()
{
  int i = 0;
  for(i =0; i < sendCount; i ++)
  {
     rxBuffer[i ] = Serial1.read();  // no space after i, my phone made me do it
  }

That’s all I remember off the top of my head, but I’ll doublecheck it and post the rest when I’m home and have time. Basically, after that, it checks to make sure the return comes back as the first two bytes being 0x76 and 0x00.

You need to check for data available before reading it.

I was wrong with my last code I posted for the receive buffer. Here it is:

void readBuffer()
{
  boolean correct = true;
  
  if (readyRx)
    return;
      
    
  rxCount = 0;
  rxBuffer[0] = 0;
  while (Serial1.available() > 0)
  {
    rxBuffer[rxCount++] = Serial1.read();
  }
  
  if(rxBuffer[0] != 0x76)
    {
      correct = false;
      Serial.println("Protocol wrong!");
      Serial.println(rxBuffer[0], HEX);
      Serial.println(rxBuffer[1], HEX);
      Serial.println(rxBuffer[2], HEX);
      Serial.println(rxBuffer[3], HEX);
      Serial.println(rxBuffer[4], HEX);
      Serial.println(rxBuffer[5], HEX);
      Serial.println(rxBuffer[6], HEX);
      
  }
    
  if(rxBuffer[1] != 0x00)
    {
      Serial.println("Serial # wrong!");
      correct = false;
    }
    
  if(correct == true)
    readyRx = true;
    
}

I don't think I mentioned it before, but I'm using a Sain Smart Mega 2560. I have not checked out that link you posted, but I'm going to do that right now.

But I don't get anything back because the rxBuffer[0] = 0, in fact, they all equal 0 and not the return that it's supposed to be.

Ok, I read that link, as best I can right now, but you gotta understand. A lot of the c language is new to me, so it might take me awhile to decipher all of it, but with the code I used, didn't I just do that? It's pretty much the same as the example code that came with the camera. I really haven't changed much, because it worked for that.

Ok, so I read through all of this, multiple times. I get that I've been reading the data wrong, but there really isn't much info on this camera. I know that the first response should be "0x76" and looking at the example code, I'm seeing that it appears that a "0x0FF is the ending byte. I first noticed the end when I upped the rx buffer to 120 from 80. The very last 2 bytes I received was 00 and FF.

So my question is, would I need to set up the case to read 0x76 as the first byte to read and 0xFF as the last byte?

The last thing I tried as a test, froze up the arduino. Basically, it timed out during the upload. I had to pull the power. But then it uploads and runs any other sketch I try to run after I plug it back in. So I know that code is irrelevant, I was just trying something, cuz I didn't feel like I got a clear answer on here.

  while (Serial1.available() > 0)

{
    rxBuffer[rxCount++] = Serial1.read();
  }
 
  if(rxBuffer[0] != 0x76)
    {
      correct = false;
      Serial.println("Protocol wrong!");
      Serial.println(rxBuffer[0], HEX);
      Serial.println(rxBuffer[1], HEX);
      Serial.println(rxBuffer[2], HEX);
      Serial.println(rxBuffer[3], HEX);
      Serial.println(rxBuffer[4], HEX);
      Serial.println(rxBuffer[5], HEX);
      Serial.println(rxBuffer[6], HEX);
     
  }
   
  if(rxBuffer[1] != 0x00)
    {
      Serial.println("Serial # wrong!");
      correct = false;
    }

You are making a lot of assumptions in that code, like that all the serial data will arrive very quickly in one burst, which is actually very unlikely. Read again:

You need to collect data in your main loop (not like you did) and then process it when a suitable delimiter arrives.

Next time post all your code please.

Ok, so here is all the code that I was trying that froze the upload process. I just kept getting a really fast double blink on pin 13’s led. I ended up scrapping this, but the idea was to just start off with something basic, like the call for the Version. But, then I ended up screwing up the camera module with the CommTool somehow. Now it’s completely unresponsive. But, you just mentioned the delimiter which I did not have anything like that.

#include "Arduino.h"
#include <SD.h>
#include <debounce.h>

#define sendProt 0x56
#define serNum 0x00
#define returnProt 0x76
#define ver 0x11

unsigned char sendBuffer[20];
unsigned char sendCount = 0;
unsigned char rxBuffer[80];
unsigned char rxCount = 0;

void setup()
{
 Serial.begin(9600);
 Serial1.begin(38400);
 if(!SD.begin(53))
 {
   pinMode(53, OUTPUT);
   delay(500);
   if(!SD.begin(53))
   {
     Serial.println("Error initializing SdCard. Please ensure a card is inserted and reset.");
     delay(3000);
     return;
   }
 }
 else
   Serial.println("SdCard initialized!!");
 
}

void loop()
{
  // this is the call for the buffer routine
  // in theory, this should continually read from the buffer during the loop
  // it should read it all where as the other previous would only snag bits
  // and pieces
  rxBuffer[0] = 0;
  rxCount = 0;
  if (Serial1.available() != 0)
  {
    rxBuffer[rxCount++];
  }
  getVersion();
  checkReturn();
}



void getVersion()
{
  sendBuffer[0] = sendProt;
  sendBuffer[1] = serNum;
  sendBuffer[2] = ver;
  sendBuffer[3] = 0x00;
  
  sendCount = 4;
}


void checkReturn()
{
 if (rxBuffer[0] != returnProt)
 {
  Serial.println("Wrong Protocol");
  return;
 }
 else
  Serial.println("Data received!!!");
  
 if (rxBuffer[1] != serNum)
 {
  Serial.println("Wrong Serial Number");
  return;
 }
 else
   Serial.println("Data received!!!");
 
}

So, anyways, I just purchased a different camera from ebay. I think it’s a OV5642. But even when I get that, I’m still going to have the same problem with receiving the data if I don’t figure this stuff out. So, any help is appreciated.

  Serial.println("Data received!!!");

Does "Data received!!!" REALLY convey more information than "Data received"???

There is an issue with the bootloader on the Mega going into debug mode when "!!!" is received. Since it seems unlikely that what follows is debug commands, the Mega hangs waiting for debug commands.

Either modify your code to provide debug commands after the "!!!", or quit being over-dramatic.

http://snippets-r-us.com

That's why we want to see all the code.

Does "Data received!!!" REALLY convey more information than "Data received"???

Yeah, quit abusing the punctuation...

PaulS:
Does "Data received!!!" REALLY convey more information than "Data received"???

Yes, does it???

So even though that’s in quotes to only appear on the serial monitor, it will still go into debug mode? Why is that? I thought for a serial print command, it would display what’s in the quotes and that’s it.

Sorry for being over dramatic. Just would have been super excited to actually know that my code worked. Didn’t realize there was a crime in that. Not to be a jerk, but everything I read said that this forum was full of people that wanted to help and were nice. I read a lot of these posts on here and I see a lot of condescension from all you programmers. Isn’t the whole point of Arduino, the spirit of it, to make it easier for beginners to get involved? How are we supposed to know the correct way of doing things right off the bat if this is our first experience with programming? Again, not trying to be a jerk, but it just seems like there’s a lot of people on here who are just outright rude. Sorry for my lack of experience. I’m trying to learn, but I don’t need to be treated like a lesser being because I don’t know everything there is to know about programming. I may ask stupid questions(to you), but eventually, I’ll have this stuff down pat and everything will be good. I just want to learn and understand, like how you guys did when you first started and didn’t know what you were doing?

The thing is, despite Facebook, Twitter and a million chatrooms, that apart from ellipsis (which I think ought to have spaces between them anyway), there is no valid form in English consisting of two or more identical punctuation characters.

It doesn't seem unreasonable to me that an escape sequence in a very limited protocol should consist of characters that should never appear together.

The only unfortunate possible side-effect would be if the compiler happened to generate code consisting of three ore more consecutive 0x21s

xKoldFuzionx:
I see a lot of condescension from all you programmers.

Sorry if my comment was ambiguous, but it was intending to point out that using multiple queries or exclamation points in text is a completely reasonable thing to do, and in fact one of the preceding posts had done exactly the same thing. The fact that this particular bootloader treats an arbitrary sequence of printable ascii codes in the middle of the image as an escape sequence is, in my opinion, stupid. There is absolutely nothing wrong with trying to include "!!!", "..." or "???" in a printed string and it is IMO poor programming to implement a bootloader in such a way that it fails when it encounters that.

There is absolutely nothing wrong with trying to include "!!!", "..." or "???" in a printed string and it is IMO poor programming to implement a bootloader in such a way that it fails when it encounters that.

On the other hand, it is a known fact that is implemented that way. There is nothing more communicated by using one, two, or three exclamation points vs what is communicated using none. A fact is a fact, whether you are excited by it, or not.

Thank you for clearing that up. Surprisingly, I plugged that camera module back in a minute ago and it worked in CommTool, so I guess I will try again.

I removed the "!!!" from all the code, but still, it returns nothing. So I guess I'm still lost. I don't get why I can't get this thing to work, let alone why it won't return any codes. But, I guess I'm not even 100% sure that it's sending anything. I might try to upload the blank sketch and hook it up on the 0/1 pins and using CoolTerm, see if I can get it to accept commands or if it will return them that way.

Sorry if I took offense to the previous responses. I've been so worked up about this camera not working I believe I may have interpreted them wrong. I re-read them and they didn't seem the uptight to me this time. I do appreciate the help you guys are offering. This has been the most frustrating thing I've gotten myself involved in. I want to throw in the towel so many times, but I refuse to give up on this. I'm enjoying working with the arduino and electronics in general. i just wish I would have gotten involved with this stuff 15-20 years ago.

No luck with CoolTerm. If it’s sending them, it’s not giving a return. I rewrote the initial code just to test the camera version. It is as follows:

#include "Arduino.h"
#include <SD.h>
#include <debounce.h>

#define sendProt 0x56
#define returnProt 0x76
#define serNum 0x00
#define ver 0x11

unsigned char rxBuffer[80];
unsigned char sendBuffer[20];
unsigned char rxCount;
unsigned char sendCount;

const int button = 2;

void setup(){
  Serial.begin(9600);
  Serial1.begin(115200);
  delay(2500);
  clearCache();
  bufferSend();
  Serial.println("Camera connected");
  pinMode(button, INPUT);
  digitalWrite(button, HIGH);
  
}

void loop(){
  if (rxBuffer[0] != returnProt){
    rxBuffer[0] = 0;
    rxCount = 0;
  }
  while(Serial1.available() > 0){
    rxBuffer[rxCount++] = Serial1.read();
    Serial.println(rxBuffer[rxCount++], HEX);
    checkReturn();
  }
  
  
  if (buttonDelay(button)){
    Serial.println("button pressed");
    getVersion();
    delay(10);
  }
  
}

void clearCache(){
  sendBuffer[0] = sendProt;
  sendBuffer[1] = serNum;
  sendBuffer[2] = 0x36;
  sendBuffer[3] = 0x01;
  sendBuffer[4] = 0x03;
  
  sendCount = 5;
}

void getVersion(){
  
  sendBuffer[0] = sendProt;
  sendBuffer[1] = serNum;
  sendBuffer[2] = ver;
  sendBuffer[3] = 0x00;
    
  sendCount = 4;
  
  bufferSend();
}

void bufferSend(){
  int i;
  for (i=0; i<sendCount; i++){
    Serial1.write(sendBuffer[i]);
    Serial.println(sendBuffer[i], HEX);
  }
  i = 0;
}

void checkReturn(){
  if (rxBuffer[0] != returnProt){
    Serial.println("Recieved wrong protocol");
    Serial.println(rxBuffer[0], HEX);
    return;
  }
  else {
    Serial.println("Protocol correct");
  }
  if (rxBuffer[1] != serNum){
    Serial.println("Received wrong Serial Number");
    Serial.println(rxBuffer[0], HEX);
    return;
  }
  else {
    Serial.println("Serial Number correct");
  }
}

But all it returns to me is this:

56
0
36
1
3
Camera connected
0
Recieved wrong protocol
56
0
Recieved wrong protocol
56
0
Recieved wrong protocol
56
0
Recieved wrong protocol
56
0
Recieved wrong protocol
56
0
Recieved wrong protocol
56
0
Recieved wrong protocol
56
0
Recieved wrong protocol
56
0
Recieved wrong protocol
56
0
Recieved wrong protocol
56
0
Recieved wrong protocol
56
0
Recieved wrong protocol
56

That’s even before I press the button. To me, this says it’s not spitting out the right information, either by my fault, or whatever. I’m seriously about to junk this camera with a hammer. Might be the best way to cure my disappointment with this. Do any of you have any experience with this? I’ve read that these cameras are basically the same as the Adafruit VC0706, but I can’t even get their code to compile. I’m so beyond frustrated right now. Is there more that I’m doing wrong?