Help with Arduino Uno and Serial Camera

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

Moderators: adafruit_support_bill, adafruit

Help with Arduino Uno and Serial Camera

Postby slewis » Fri Apr 27, 2012 9:43 am

First I want to say that I am fairly new to using the Arduino.
Here is some background on the project, and what I want to accomplish. I work for a nursing home, and we are installing a new Nurse Call system. This new nurse call system uses real time tracking of residents and staff with IR, RF, and LF devices and badges that are worn by staff and residents. This has local controllers with multiple inputs and outputs on each device. These inputs and outputs can be used for a lot of different purposes including, controlling mag locks, and monitoring motion.

What we are wanting to do is place a motion detector in our Med Room. This motion detector can register movement in the room if there is not an employee badge seen by the IR sensor in the room. My plan is then to have the local controller trigger its internal relay. This relay would then send a signal to the Arduino.

What I am wanting the Ardunio to do once it receives the signal is to capture 10 images for 10 seconds with a Serial camera, store those images to the on board SD card. Then I want to be able to access that SD card from the Arduino web browser.

I have an Arduino Uno R3 ATmega328, an ethernet shield with SD card, a TTL Serial Camera (from this tutorial: http://www.ladyada.net/products/camera/)

So far since I have been waiting for the camera to get here I have setup the webserver on the Ethernet shield with this code example https://github.com/adafruit/SDWebBrowse/blob/master/SDWebBrowse.ino
The problem that I have is that I am not able to open any Jpeg files from the web browser that are stored on the SD card. Is this possible to open the images from the web browser?

Any help you guys can provide would be greatly appreciated.

-Steve
slewis
 
Posts: 4
Joined: Fri Apr 27, 2012 9:28 am

Re: Help with Arduino Uno and Serial Camera

Postby adafruit_support_bill » Fri Apr 27, 2012 10:16 am

capture 10 images for 10 seconds with a Serial camera,

It takes several seconds to capture each image & transfer it to the Arduino. So 10 in 10 seconds will not be possible.

I am not able to open any Jpeg files from the web browser that are stored on the SD card.

What error do you get? Are you able to view other files?

Assuming that server is able to read the files, you may have a problem with the content-type headers. In that example, they are hard-coded as "Content-Type: text/plain". Your browser will probably want "Content-Type: image/jpeg".
User avatar
adafruit_support_bill
 
Posts: 15995
Joined: Sat Feb 07, 2009 9:11 am

Re: Help with Arduino Uno and Serial Camera

Postby slewis » Fri Apr 27, 2012 10:50 am

The capturing 10 images for 10 seconds doesn't need to be the case, we will just need to have a few images over the course of 20-30 seconds, just so that we get a decent picture of the person.

I don't get an error when trying to open the jpegs, it just opens as text, so that is probably the cause then what it is set to text/plain. I will look at that and see if I can figure that out. Thanks for the help on that.
slewis
 
Posts: 4
Joined: Fri Apr 27, 2012 9:28 am

Re: Help with Arduino Uno and Serial Camera

Postby slewis » Fri Apr 27, 2012 11:04 am

I have tried to change the Content-Type: from text/plain to image/jpeg, it did change what I got from ÿØÿà to getting Image

I have also tried to change the code where it starts Serial.PrintIn("Opened!") to:
Code: Select all
client.println("HTTP/1.1 200 OK");
           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();

That allows will gives me an error in Firefox saying: "The image "http://172.16.1.215/test2.jpg" cannot be displayed because it contains errors. I am able to open the file directly from the SD card if it is plugged into my computer.

Any help would be appreciated.
slewis
 
Posts: 4
Joined: Fri Apr 27, 2012 9:28 am

Re: Help with Arduino Uno and Serial Camera

Postby slewis » Tue May 01, 2012 8:28 am

Is it possible instead of storing the images on the SD card to have the Arduino write the images to a file server with the Ethernet shield? If so does anyone have code examples of this?
slewis
 
Posts: 4
Joined: Fri Apr 27, 2012 9:28 am

Re: Help with Arduino Uno and Serial Camera

Postby adafruit_support_bill » Tue May 01, 2012 8:54 am

It certainly should be possible. I don't know of any examples of this.
User avatar
adafruit_support_bill
 
Posts: 15995
Joined: Sat Feb 07, 2009 9:11 am

Re: Help with Arduino Uno and Serial Camera

Postby CONTECAVOUR » Wed Jul 18, 2012 3:47 am

I have an example

Code: Select all
#include <Adafruit_VC0706.h>
#include <SoftwareSerial.h>   
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

SoftwareSerial cameraconnection = SoftwareSerial(6, 7);
Adafruit_VC0706 cam = Adafruit_VC0706(&cameraconnection);

//http://www.theshaker.org/test_nicola/image_upload.php
char serverName[] = "www.theshaker.org";

int32_t time = millis();
int32_t ritorno;
EthernetClient client;

void setup() {
  Serial.begin(38400);
  ritorno = -1;

  pinMode(10, OUTPUT);     // change this to 53 on a mega
  digitalWrite(10, HIGH);
 

  if (Ethernet.begin(mac) == 0) {
    Serial.println(F("ETH KO"));
    // no point in carrying on, so do nothing forevermore:
    while(true);
  } else
  {
     Serial.println(F("ETH OK"));
  }
 
   
  delay(1000);
   
  if (cam.begin()) {
    Serial.println(F("OK CAM"));
  } else {
    Serial.println("NO CAM");
    return;
  }
 
  //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");
 
*/ 
   
  ritorno =  takefoto();
  Serial.print("Ritorno ");
  Serial.println(ritorno);
   
}



// This is where all the magic happens...
void loop() {
 
  byte inChar;
  inChar = Serial.read();

  //Preso da DnsWebClient
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  if (inChar == 'f')
  {
    Serial.flush();
    client.flush();
    client.stop();
    ritorno = -1;     
    Serial.println("");
    Serial.println("Riscatto MI");
    cam.setImageSize(VC0706_320x240); 
    ritorno = takefoto();
  } 
 
  if (inChar == 'f')
  {
    Serial.flush();
    client.flush();
    client.stop();
    ritorno = -1;     
    Serial.println("");
    Serial.println("Riscatto HI");
    cam.setImageSize(VC0706_640x480);
    ritorno = takefoto();
  } 
 
 
}

int takefoto() {
  Serial.println("Snap in 3 secs...");
//  cam.reset();
  // 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");
 
 
  delay(3000); 
  if (! cam.takePicture())
    Serial.println("Failed to snap!");
  else
    Serial.println("Picture taken!");
   
  Serial.println("Server connecting...");   

   
//  client.stop();
  if (client.connect(serverName, 80))     {
    Serial.println("connected");
    // Make a HTTP request:
//    client.println("GET /ARDUINO/savepicture.cfm");
//    client.println();
   
   
  // Get the size of the image (frame) taken 
  uint16_t jpglen = cam.frameLength();
  Serial.print("Storing ");
  Serial.print(jpglen, DEC);
  Serial.print(" byte image.");
  uint32_t len = jpglen + 177; // 177 is the content without the image data 
 
//client.println(F("POST /path/to/script.php HTTP/1.0"));
//client.println(F("POST /ARDUINO/savepicture.cfm HTTP/1.0"));
//http://www.theshaker.org/test_nicola/image_upload.php
//www.theshaker.org
client.println(F("POST /test_nicola/image_upload.php HTTP/1.0"));
//client.println(F("POST /ARDUINO/savepicture.cfm"));
client.println(F("Host: www.theshaker.org"));
client.println(F("Content-type: multipart/form-data, boundary=UH3xBZZtzewr09oPP"));
client.print(F("Content-Length: "));
client.println(len);
client.println();
client.println(F("--UH3xBZZtzewr09oPP"));
client.println(F("content-disposition: form-data; name=\"picture\"; filename=\"cam.jpg\""));
client.println(F("Content-Type: image/jpeg"));
client.println(F("Content-Transfer-Encoding: binary"));
client.println();
 
 

  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);
   
    //Scrittura
//    imgFile.write(buffer, bytesToRead);
    client.write(buffer, bytesToRead);
//    Serial.write(buffer, HEX);   

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

client.println();
client.println(F("--UH3xBZZtzewr09oPP--"));


  time = millis() - time;
  Serial.println("done!");
  Serial.print(time); Serial.println(" ms elapsed");

 
 
  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.flush();
    client.stop();

    // do nothing forevermore:
    while(true);
  } 
 
 
 
 
  }
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
  }   
 
 
   
  return time;
 
}

CONTECAVOUR
 
Posts: 2
Joined: Wed Jul 18, 2012 3:44 am


Return to Arduino

Who is online

Users browsing this forum: Yahoo [Bot] and 7 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [102]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
BeagleBone[24]
 
Android[6]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[33]
LCDs & Displays[48]
Components & Parts[69]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[109]
 
Wireless[14]
Cables[60]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]