Serial TTL Linksprite camera library (for arduino-1.0.x)

Hi all,
here is a library I built from one I found but that was pre-1.0. I also attach a test sketch which sends the picture via the serial - USB port, you just need to use a serial monitor that can save the raw stream to a file to get your picture!
The test program is for a leonardo (I use the Serial1 port for the camera) but you can adapt it to board by using a software serial port instead of the Serial1.
Note that the chBaudRate function does not seem to work, so you have to use the serial port to the camera at 38400.
Hope this helps!

JPEGCamera.h (1.11 KB)

test_cam_3.ino (567 Bytes)

I am unable to post the cpp file here! Please use PM to get it, sorry...

Thanks ! I'll start trying it once i get the pp file . thanks alot

manufwi:
Hi all,
here is a library I built from one I found but that was pre-1.0. I also attach a test sketch which sends the picture via the serial - USB port, you just need to use a serial monitor that can save the raw stream to a file to get your picture!
The test program is for a leonardo (I use the Serial1 port for the camera) but you can adapt it to board by using a software serial port instead of the Serial1.
Note that the chBaudRate function does not seem to work, so you have to use the serial port to the camera at 38400.
Hope this helps!

OK I setup a googlecode project to make it easier:

https://code.google.com/p/linksprite-serial-cam-arduino

Enjoy!

Hi all just make sure you check the last version (as of today 04/09/2013): software serial works at up to 19200 bds (there is an example sketch in the download section)!

Hi, thank you for your code...I am also working with one now...Is it possible that the camera take few images in a second?maybe 2-3fps at 160x120 resolution? Thank you very much...

Hmm I am not sure: you must do the math. First you need to transfer each picture either to a PC via serial port or to an SD card. The best you can do is 115200 bds (via HW serial, software serial is reliable only up to 19200 bds with my camera). This means around 10kB/s if everything is really smooth, so if you want to achieve 2fps a pciture must be less or up to 5kB.
Also you might want to tweak the delays in my code to push things as fast as possible.
So I think it might be doable, but you must really test it and tune the code abit if needed.
HTH
Bye
Manu

Hey,
thanks for the code.
Is it possible, that you upload the cpp-file to google code as well?

First: for my excuse, i'm a newbie. :wink:
I could get data from my camera with the help of the sparkfun-library (I updated it to 1.0), but ways to slow (about 5 characters per second! after 10 minutes I gave up).
I hope it will work better with your code, or could it be another problem?
I work with an Arduino Uno (does it make a difference to leonardo in this case?) and just simply connect the camera to my Arduino (3.3V, Software Serial).

thx,
TJ

It is there: just go to source, browse you can download both files from there. If not send your email address by PM here I will send them to you.

oh yeah, I stopped reading, when I saw "checkout". shame on me.
Thank you!

Now it works faster, but it still takes 15 - 20 sec to load one pic. Is this normal? Is my Arduino Uno too slow?
I used your software serial code, your lib and 3.3V for the camera.

thx,
TJ

hmm this sounds slow,but if you use 3.3v I think someone said that it cannot go faster than 19200 bds and if you use high quality (640x320) picture this is around 40kB so 15s is normal (19200 bds means 2kB/s at best).

Dear manufwi,

thanks a lot for your lib and examples !!

I get the 320240 images stored on my microSD card. It takes roughly 10secs to get and store the image.
Now I'd like to change the resolution to 640
480..

I see that in the examples you have commented out the chPictureSize method, except for the leonardo code.
Do you know why the chPictureSize method hangs on the UNO ?

I'm a bit afraid to tweak the library as I remember reading somewhere that sending the wrong command to the camera could brick it.

If you have any hints, please let me know.

Thanks again,
Xavier

Well I dont think it hangs on the UNO. I am sure it works on Leonardo using HW serial, I'd say you can try with UNO. Do you use HW serial or SW serial?
One remark: 640x320 is around 40kB=320kb which takes 2-3s at best to upload to arduino using HW serial (115200bds) but 18-20s at best at 19200 bds (the best rate I could use with SW serial).

manufwi:
Well I dont think it hangs on the UNO. I am sure it works on Leonardo using HW serial, I'd say you can try with UNO. Do you use HW serial or SW serial?
One remark: 640x320 is around 40kB=320kb which takes 2-3s at best to upload to arduino using HW serial (115200bds) but 18-20s at best at 19200 bds (the best rate I could use with SW serial).

Hello manufwi,

thanks I followed your advice and switched the serial connections (I have now the HW for the cam and SW for the debugging). With this configuration I managed to change the resolution to 640*480. However no matter which speed I set it always takes ~40 seconds to get and store the picture on the sd card. The speed change is effective as if I change only the camera settings without reinitiating the serial communication at the same speed (or vice versa) it doesn't work.

I don't think the bottleneck comes from writing to the sd card (using the latest fatlib from Google Code Archive - Long-term storage for Google Code Project Hosting.)

Any ideas ? Thanks !!

I will try as I really dont remember the numbers when I was testing. I'll get back to you ASAP (dont hold your breath though :wink:

OK I was only able to test at 38400bds (I dont know why but that's another story), here are my numbers: a 640x480 picture is uploaded via HW Serial port to my PC using GtkTerm, and the raw stream is displayed on the screen which might make things slower than they should, took 35s. I set both Serial ports (cam->leonardo and leonardo -> PC to 38400). So if they were both at 115200 that should have taken aroudn 12s. Remember that this is supposed twice the time as I do 2 transfers: from cam to leonardo and then to PC. You should do better as SD uses SPI and this, I suppose, is much faster than serial, right?

Hello,
I'm newbie. I downloaded your files and the complete JPEGCamera Library. When i try to upload this code to my Arduino Mega2560 (while cam is connected to RX2, TX2 i-e Serial2), i got the following error.

test_cam_3:6: error: 'JPEGCamera' does not name a type
test_cam_3.ino: In function 'void loop()':
test_cam_3:24: error: 'cam' was not declared in this scope

And the code looks like:

#include <SoftwareSerial.h>
#include <JPEGCamera.h>

SoftwareSerial sserial(17,16);
JPEGCamera cam(Serial2/*sserial*/);
char resp[10];

I also pasted both the libraries into my sketch folder. Can you please help me where i'm going wrong.?

Well at least under linux (but I am pretty sure it is the same with windows): you need to create a JPEGCamera directory into your libraries subdir of the arduino directory.
I mean, if your arduino directory (not the sketch folder, the folder where all arduino tools are) is arduino-1.0 you need to create the following directory:

arduino-1.0/libraries/JPEGCamera

and you put the 2 files (.h and .cpp) of the library there and then youre good to go (you might need to restart the arduino ide, but I am not sure).

can any one help me?
iam using arduino mega 2560 and camera ls-y201.

#include <SoftwareSerial.h> 

byte incomingbyte;

//Configure pin 2 and 3 as soft serial port
SoftwareSerial cameraSerial = SoftwareSerial(2, 3); 

int a=0x0000,  //Read Starting address     
    j=0,
    k=0,
    count=0;
uint8_t MH,ML;
boolean EndFlag=0;


void setup() { 
  Serial.begin(19200);
  cameraSerial.begin(38400);
  
  SendResetCmd();
  delay(3000);
}

void loop() {
  SendTakePhotoCmd();
  
  Serial.println("Start pic"); 
  delay(100);

  while(cameraSerial.available()>0) {
    incomingbyte=cameraSerial.read();
  }
  byte b[32];
      
  while(!EndFlag) {  
    j=0;
    k=0;
    count=0;
    SendReadDataCmd();
           
    delay(75); //try going up
    while(cameraSerial.available()>0) {
      incomingbyte=cameraSerial.read();
      k++;
      if((k>5)&&(j<32)&&(!EndFlag)) {
        b[j]=incomingbyte;
        if((b[j-1]==0xFF)&&(b[j]==0xD9))
        EndFlag=1;                           
        j++;
        count++;
      }
    }
            
    for(j=0;j<count;j++) {   
      if(b[j]<0x10)
        Serial.print("0");
      Serial.print(b[j], HEX);
    }
    Serial.println();
  }
  
  delay(3000);
  EndFlag = 0; // reset so that another picture can be taken
  Serial.println("End of pic");
  Serial.println(); 
}

//Send Reset command
void SendResetCmd() {
  cameraSerial.write((byte)0x56);
  cameraSerial.write((byte)0x00);
  cameraSerial.write((byte)0x26);
  cameraSerial.write((byte)0x00);   
}

//Send take picture command
void SendTakePhotoCmd() {
  cameraSerial.write((byte)0x56);
  cameraSerial.write((byte)0x00);
  cameraSerial.write((byte)0x36);
  cameraSerial.write((byte)0x01);
  cameraSerial.write((byte)0x00);
    
  a = 0x0000; //reset so that another picture can taken
}

void FrameSize() {
  cameraSerial.write((byte)0x56);
  cameraSerial.write((byte)0x00);
  cameraSerial.write((byte)0x34);
  cameraSerial.write((byte)0x01);
  cameraSerial.write((byte)0x00);  
}

//Read data
void SendReadDataCmd() {
  MH=a/0x100;
  ML=a%0x100;
      
  cameraSerial.write((byte)0x56);
  cameraSerial.write((byte)0x00);
  cameraSerial.write((byte)0x32);
  cameraSerial.write((byte)0x0c);
  cameraSerial.write((byte)0x00);
  cameraSerial.write((byte)0x0a);
  cameraSerial.write((byte)0x00);
  cameraSerial.write((byte)0x00);
  cameraSerial.write((byte)MH);
  cameraSerial.write((byte)ML);
  cameraSerial.write((byte)0x00);
  cameraSerial.write((byte)0x00);
  cameraSerial.write((byte)0x00);
  cameraSerial.write((byte)0x20);
  cameraSerial.write((byte)0x00);
  cameraSerial.write((byte)0x0a);

  a+=0x20; 
}

void StopTakePhotoCmd() {
  cameraSerial.write((byte)0x56);
  cameraSerial.write((byte)0x00);
  cameraSerial.write((byte)0x36);
  cameraSerial.write((byte)0x01);
  cameraSerial.write((byte)0x03);        
}