VC0706 Serial Camera to Web server.

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
EVRE
 
Posts: 59
Joined: Sat Feb 18, 2012 11:21 pm

VC0706 Serial Camera to Web server.

Post by EVRE »

Building a robot to act as IP camera with RH and DS18b20 temp sensors.

Project pieces and status:
Serial Camera ( working )
Web Server(Working)
Web Server accepting input(Work in progress)
LCD Navigable interface (not started)
Real time clock (working)
Relative humidity sensor(not started)
DS18b20 temp sensor(working)
Ultra sonic range finder (historic code)
Battery Voltage (not started)
Current sensor(working)
Light Sensor(historic code)
64x128 LCD (working)
Stepper motor control (working)
Servo head control (not started)
Bluetooth connectivity (working)

I got tired of my project being put in the closet so this one is going to set on my night stand and be my alarm clock while not in other practical use :)
Project pics
Attachments
Temp sensor to two LCD displays
Temp sensor to two LCD displays
2011-02-17 00-30-44.554.jpg (120.6 KiB) Viewed 3161 times
2012-01-22 17-31-19.260.jpg
2012-01-22 17-31-19.260.jpg (604.8 KiB) Viewed 3161 times
2012-01-17 00-47-09.426.jpg
2012-01-17 00-47-09.426.jpg (178.46 KiB) Viewed 3161 times
Last edited by EVRE on Sat Mar 03, 2012 11:43 pm, edited 6 times in total.

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: VC0706 Serial Camera to Web server.

Post by adafruit »

EVRE wrote:First I have to say, to get it off my chest. If your going to sell a camera for $42 and have example code, actual make it drag and drop to work. The Snapshot.pde references the VC0706.h, but the functions it uses are in neither, they are in the SerialCamera.cpp file, but if you copy and paste those into Snapshot.pde, the IDE rejects them because they were written for something like visual studio c++.
hi there, glad to hear you got it working but the code example we have should work right out of the box, and there's no such file as " SerialCamera.cpp" in our tutorial or example. did you follow our tutorial here? http://www.ladyada.net/products/camera/ did you install the library? the library makes things a lot easier!

EVRE
 
Posts: 59
Joined: Sat Feb 18, 2012 11:21 pm

Re: VC0706 Serial Camera to Web server.

Post by EVRE »

Sorry, it was VC0706.cpp I called it SerialCamera.cpp on my computer.

How could it work out of the box?
Here is an example of a function that cannot work from snapshot.pde
cam.frameLength(); Serial connection to camera, run function to get frame length in bytes. This function is not in the snapshot.pde file, so for it to work it must be in the VC0706.h library right? Its not, its in your VC0706.cpp file.

If there is a way to reference to VC0706.cpp file within the arduino IDE I did not see it, or its over my head.

To get the functions where they could be read, I copied and pasted and tried to debug to see what else the arduino IDE wanted to make it work, that's how I got that mess of code all on one page.

EVRE
 
Posts: 59
Joined: Sat Feb 18, 2012 11:21 pm

Re: VC0706 Serial Camera to Web server.

Post by EVRE »

***I have never had a .cpp file in a library folder before, tweaking with it now. Guess that shows my level of experience with this.
Sorry for my rudeness

-EVRE

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: VC0706 Serial Camera to Web server.

Post by adafruit »

OK sounds like you're back on track :) your project should be a lot easier now!

EVRE
 
Posts: 59
Joined: Sat Feb 18, 2012 11:21 pm

Re: VC0706 Serial Camera to Web server.

Post by EVRE »

Ok, some progress today.
Been using my Seeed 328 with a Arduino Ethernet shield.
modified the code to use SdFat.h and to overwrite the old file (That was a challenge!)
Been working on getting the web server setup, I'm afraid I'm running out of ram with my 328p. It works if an image is already on the card, but crashes if it has to get a new one :(

So... moving over to my Seeed Mega 1280, camera cant be found on any pair of pins, I even tried switching the wires around. So, for now its back to the lil 328P. FYI I am not voltage dividing the signal, my professor told me that the chip would be tolerant to the signal. **please help with this, what or where should I change to get it to use the hardware serial ports on the mega 1280?

I dont know how to convert the code to use one of the other 4 hardware serial connections on the mega.
I'd be hopeful if that was working I could use the full 115200 baud rate and push the read rate from 32 to 64 bytes.. or even more? :)

BTW this would change the baud rate on the camera to 115200 right?

Code: Select all

void SetBaudRateFast(){
//0x56+0x00+0x24+0x03+0x01+0x0D+0xA6
cam.write((byte)0x56);
cam.write((byte)0x00);
cam.write((byte)0x24);
cam.write((byte)0x03);
cam.write((byte)0x01);
cam.write((byte)0x1C);
cam.write((byte)0x4C);
}[/quote]


EVRE
Last edited by EVRE on Mon Feb 20, 2012 8:32 pm, edited 2 times in total.

EVRE
 
Posts: 59
Joined: Sat Feb 18, 2012 11:21 pm

Re: VC0706 Serial Camera to Web server.

Post by EVRE »

:( I'm sunk. I cant for the life of me get the camera to work my mega board.
Since my lil 328P is resources deprived I cant get my web server working :(
Even if I did lean up the code to get just that to work, there would be no way it would have the resources to get the Relative humidity and Dallas DS18B20's temp sensors to work.

FYI: with the 328P and Web Server loaded I get garble up the serial port, move the shield to the mega and it indicates it cant find the camera. Load just the snapshot code, the mega still cant find the camera, move the shield back to the 328P, load same snapshot code, and it see's the camera :(
2012-02-20 11-37-17.429.jpg
2012-02-20 11-37-17.429.jpg (176.44 KiB) Viewed 3162 times
2012-02-20 11-35-48.564.jpg
2012-02-20 11-35-48.564.jpg (170.49 KiB) Viewed 3162 times
Ip camera web server

Code: Select all

#include <SPI.h>
#include <SdFat.h>
#include <SdFatUtil.h>
#include <Ethernet.h>
#include <SoftwareSerial.h>
#include <VC0706.h>



uint8_t bufindex;
const uint8_t maxbyte=255;
uint8_t buf[maxbyte];

byte mac[] = {
  0x90,0xA2,0xDA,0x00,0x26,0xEB};
byte ip[] = {
  192,168,2,233};
char rootFileName[] = "index.htm";
EthernetServer server(8081);

Sd2Card card;
SdVolume volume;
SdFile root;
SdFile file;
SdFat sd;

SoftwareSerial cameraconnection = SoftwareSerial(2, 3); //Camera TX RX Pins
VC0706 cam = VC0706(&cameraconnection);// pass the serial connection to the camera object

  unsigned long previousMillis = 0;
  unsigned long interval = 30000;
  unsigned long currentMillis;

#define error(s) error_P(PSTR(s))
void error_P(const char* str) {
  PgmPrint("error: ");
  SerialPrintln_P(str);
  if (card.errorCode()) {
    PgmPrint("SD error: ");
    Serial.print(card.errorCode(), HEX);
    Serial.print(',');
    Serial.println(card.errorData(), HEX);
  }
  while(1);
}

void setup() {
  Serial.begin(9600);
  PgmPrint("Free RAM: ");
  Serial.println(FreeRam());
  pinMode(10, OUTPUT);
  digitalWrite(10, HIGH);
  if (!card.init(SPI_FULL_SPEED, 4)) error("card.init failed!");
  if (!volume.init(&card)) error("vol.init failed!");
  PgmPrint("Volume is FAT");
  Serial.println(volume.fatType(),DEC);
  Serial.println();
  if (!root.openRoot(&volume)) error("openRoot failed");
  PgmPrintln("Files found in root:");
  root.ls(LS_DATE | LS_SIZE);
  Serial.println();
  PgmPrintln("Files found in all dirs:");
  root.ls(LS_R);
  Serial.println();
  PgmPrintln("Done");
  Ethernet.begin(mac, ip);
  server.begin();
}
#define BUFSIZ 100

void CaptureCameraFrame(){
   if (! cam.takePicture()){
    
    Serial.println("Failed to snap!");
    return;
  }
  else 
    Serial.println("Picture taken!");
  
  // Open the file for writing

  file.open("CAM-PIC.JPG", O_CREAT | O_TRUNC | O_RDWR);

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

  int32_t time = millis();
  pinMode(8, OUTPUT);
  // Read all the data up to # bytes!
  while (jpglen != 0) {
    // read 64 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);
    file.write(buffer, bytesToRead);
    //Serial.print("Read ");  Serial.print(bytesToRead, DEC); Serial.println(" bytes");
    jpglen -= bytesToRead;
  }
  file.close();
  cam.resumeVideo();
  Serial.println("Done!"); 
}

void cameraTimer(){
  
  if(currentMillis - previousMillis > interval) {
    previousMillis = currentMillis;  
  CaptureCameraFrame();

  }

}


void loop()
{
  currentMillis = millis();
  cameraTimer();
  char clientline[BUFSIZ];
  char *filename;
  int index = 0;
  int image = 0;
  EthernetClient client = server.available();
  if (client) {
    boolean current_line_is_blank = true;
    index = 0;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        if (c != '\n' && c != '\r') {
          clientline[index] = c;
          index++;
          if (index >= BUFSIZ)
            index = BUFSIZ -1;
          continue;
        }
        clientline[index] = 0;
        filename = 0;
        Serial.println(clientline);
        if (strstr(clientline, "GET / ") != 0) {
          filename = rootFileName;
        }
        if (strstr(clientline, "GET /") != 0) {
          if (!filename) filename = clientline + 5;
          (strstr(clientline, " HTTP"))[0] = 0;
          Serial.println(filename);
          if (! file.open(&root, filename, O_READ)) {
            client.println("HTTP/1.1 404 Not Found");
            client.println("Content-Type: text/html");
            client.println();
            file.open(&root,"404error.htm",O_READ);  //Opens the file 404error.htm from the root directory.  This is if the file doesn't exist
            int16_t c;
            while((c=file.read())>=0){  //sends file (yes it is the slow way, but if you don't have a picture, thats ok
              client.write((char)c);
            }
            file.close();
            break;
          }
          Serial.println("Opened!");
          client.println("HTTP/1.1 200 OK");
          if (strstr(filename, ".htm") != 0)
            client.println("Content-Type: text/html");
          else if (strstr(filename, ".css") != 0)
            client.println("Content-Type: text/css");
          else if (strstr(filename, ".png") != 0)
            client.println("Content-Type: image/png");
          else if (strstr(filename, ".jpg") != 0)
            client.println("Content-Type: image/jpeg");
          else if (strstr(filename, ".gif") != 0)
            client.println("Content-Type: image/gif");
          else if (strstr(filename, ".3gp") != 0)
            client.println("Content-Type: video/mpeg");
          else if (strstr(filename, ".pdf") != 0)
            client.println("Content-Type: application/pdf");
          else if (strstr(filename, ".js") != 0)
            client.println("Content-Type: application/x-javascript");
          else if (strstr(filename, ".xml") != 0)
            client.println("Content-Type: application/xml");
          else
            client.println("Content-Type: text");
          client.println();
          int16_t c;
          bufindex=0;
          while ((c = file.read()) >= 0) {
            buf[bufindex++]=((char)c);
            if(bufindex==maxbyte)
            {
              client.write(buf, maxbyte);
              bufindex=0;
            }
          }
          file.close();
          if(bufindex>0)
          {
            client.write(buf, bufindex);
          }
          bufindex=0;
        } 
        else {
          client.println("HTTP/1.1 404 Not Found");
          client.println("Content-Type: text/html");
          client.println();
          file.open(&root,"404error.htm",O_READ);  //this is if the "GET /" fails to retrieve data
          int16_t c;
          while((c=file.read())>=0)  //sends file.  still not fast.
            client.write((char)c);
          }
          file.close();
        }
        break;
      }
    }
    delay(1);
    client.stop();
  }

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: VC0706 Serial Camera to Web server.

Post by adafruit »

we dont have this library with Mega compatibilty yet. no ETA when we'll get that working, someone in the forums did get it working but we dont recall what thread it was, you might want to search for it

EVRE
 
Posts: 59
Joined: Sat Feb 18, 2012 11:21 pm

Re: VC0706 Serial Camera to Web server.

Post by EVRE »

I had read that thread earlier, but the OP did not post how he fixed the problem :( I sent a PM. I hope to hear back soon.

I'm willing to put in the effort and share my results to get this working. If you could tell me why the library isnt mega compatible, it may give me a starting point.

Ideally I would move the communication to one of the hardware serial connections. But what is ideal for me may not be ideal for others. =/

in the .cpp file:
boolean VC0706::begin(uint16_t baud) {
camera->begin(baud);
return reset();
change this to look like:?

boolean VC0706::begin() {
Serial1.begin(38400);
return reset();

I think that would be a dirty way of doing it since baud at that point would be impossible to change..

camera = ser, and ser is a pointer to an incoming variable with/from SoftwareSerial? is the trouble there in those lines? guess I would test it out, but I have to dedicate my weekday hours to studies..... ... I had fo find out the hard way, at a cost of close to 10 hrs that the mega is not compatible. I really wish those hours were better spent on this project.

No ETA hopefully doesn't mean I'm completely on my own.

Anyway, thats all I can do on this for right now.

EVRE

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: VC0706 Serial Camera to Web server.

Post by adafruit »

yup you should try just doing that replace. we need to rework the library to make it mega compatible AND uno compatible, thats tougher than just search-replace :)

EVRE
 
Posts: 59
Joined: Sat Feb 18, 2012 11:21 pm

Re: VC0706 Serial Camera to Web server.

Post by EVRE »

Started looking at this problem again, found this:
The version of SoftwareSerial included in 1.0 and later is based on the NewSoftSerial library by Mikal Hart.

Limitations

The library has the following known limitations:

If using multiple software serial ports, only one can receive data at a time.
Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69
So... why isn't changing:
SoftwareSerial cameraconnection = SoftwareSerial(2, 3); to
SoftwareSerial cameraconnection = SoftwareSerial(52, 53); working? :roll:

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: VC0706 Serial Camera to Web server.

Post by adafruit »

redownload the camera library, we've recently added mega support

EVRE
 
Posts: 59
Joined: Sat Feb 18, 2012 11:21 pm

Re: VC0706 Serial Camera to Web server.

Post by EVRE »

**SUPPER HAPPY DANCE!!!!** :D

EVRE
 
Posts: 59
Joined: Sat Feb 18, 2012 11:21 pm

Re: VC0706 Serial Camera to Web server.

Post by EVRE »

Web server and camera are getting along now!

EVRE
 
Posts: 59
Joined: Sat Feb 18, 2012 11:21 pm

Re: VC0706 Serial Camera to Web server.

Post by EVRE »

Webcam server has been working great for the last 24 hrs!
Changing uint8_t bytesToRead = min(32, jpglen); to 64 was a great speed increase.

But I would like to push it even faster.

Code: Select all

void setup(){
Serial2.begin(38400);
SetBaudRateFast();
cam.begin(115200)
}

void SetBaudRateFast(){
Serial2.write((byte)0x56);
Serial2.write((byte)0x00);
Serial2.write((byte)0x24);
Serial2.write((byte)0x03);
Serial2.write((byte)0x01);
Serial2.write((byte)0x0D);
Serial2.write((byte)0xA6);
}
Above is a snippet of relevant code, that doesn't work :(


*shrug* am I truly stuck at 38400?

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

Return to “Arduino”