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

**URL:** <https://forum.arduino.cc/t/serial-ttl-linksprite-camera-library-for-arduino-1-0-x/153968>\
**Category:** Sensors\
**Created:** [April 1, 2013, 12:17pm UTC](https://forum.arduino.cc/t/serial-ttl-linksprite-camera-library-for-arduino-1-0-x/153968 "2013-04-01T12:17:04Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![manufwi](https://avatars.discourse-cdn.com/v4/letter/m/c77e96/32.png) [@manufwi](https://forum.arduino.cc/u/manufwi)\
**Post date:** [April 1, 2013, 12:17pm UTC](https://forum.arduino.cc/t/serial-ttl-linksprite-camera-library-for-arduino-1-0-x/153968/1 "2013-04-01T12:17:04Z")

</div>

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](https://forum.arduino.cc/uploads/short-url/obrf4M7GYmtXboTKe4CpYIxuVjW.h) (1.11 KB)

[test\_cam\_3.ino](https://forum.arduino.cc/uploads/short-url/lUFSZUw0M6EkNIVG2Y2Mfn9hZLU.ino) (567 Bytes)

---

<div class="post-metadata">

**Author:** ![manufwi](https://avatars.discourse-cdn.com/v4/letter/m/c77e96/32.png) [@manufwi](https://forum.arduino.cc/u/manufwi)\
**Post date:** [April 1, 2013, 12:24pm UTC](https://forum.arduino.cc/t/serial-ttl-linksprite-camera-library-for-arduino-1-0-x/153968/2 "2013-04-01T12:24:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [April 1, 2013, 1:50pm UTC](https://forum.arduino.cc/t/serial-ttl-linksprite-camera-library-for-arduino-1-0-x/153968/3 "2013-04-01T13:50:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![manufwi](https://avatars.discourse-cdn.com/v4/letter/m/c77e96/32.png) [@manufwi](https://forum.arduino.cc/u/manufwi)\
**Post date:** [April 5, 2013, 1:53pm UTC](https://forum.arduino.cc/t/serial-ttl-linksprite-camera-library-for-arduino-1-0-x/153968/4 "2013-04-05T13:53:53Z")

</div>

> 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](https://code.google.com/p/linksprite-serial-cam-arduino)

Enjoy!

---

<div class="post-metadata">

**Author:** ![manufwi](https://avatars.discourse-cdn.com/v4/letter/m/c77e96/32.png) [@manufwi](https://forum.arduino.cc/u/manufwi)\
**Post date:** [April 9, 2013, 6:57pm UTC](https://forum.arduino.cc/t/serial-ttl-linksprite-camera-library-for-arduino-1-0-x/153968/5 "2013-04-09T18:57:29Z")

</div>

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)!

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [April 15, 2013, 11:03am UTC](https://forum.arduino.cc/t/serial-ttl-linksprite-camera-library-for-arduino-1-0-x/153968/6 "2013-04-15T11:03:06Z")

</div>

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...

---

<div class="post-metadata">

**Author:** ![manufwi](https://avatars.discourse-cdn.com/v4/letter/m/c77e96/32.png) [@manufwi](https://forum.arduino.cc/u/manufwi)\
**Post date:** [April 16, 2013, 2:35am UTC](https://forum.arduino.cc/t/serial-ttl-linksprite-camera-library-for-arduino-1-0-x/153968/7 "2013-04-16T02:35:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 24, 2013, 9:57am UTC](https://forum.arduino.cc/t/serial-ttl-linksprite-camera-library-for-arduino-1-0-x/153968/8 "2013-05-24T09:57:05Z")

</div>

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. 😉  
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

---

<div class="post-metadata">

**Author:** ![manufwi](https://avatars.discourse-cdn.com/v4/letter/m/c77e96/32.png) [@manufwi](https://forum.arduino.cc/u/manufwi)\
**Post date:** [May 24, 2013, 8:07pm UTC](https://forum.arduino.cc/t/serial-ttl-linksprite-camera-library-for-arduino-1-0-x/153968/9 "2013-05-24T20:07:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 24, 2013, 10:03pm UTC](https://forum.arduino.cc/t/serial-ttl-linksprite-camera-library-for-arduino-1-0-x/153968/10 "2013-05-24T22:03:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![manufwi](https://avatars.discourse-cdn.com/v4/letter/m/c77e96/32.png) [@manufwi](https://forum.arduino.cc/u/manufwi)\
**Post date:** [May 26, 2013, 1:58am UTC](https://forum.arduino.cc/t/serial-ttl-linksprite-camera-library-for-arduino-1-0-x/153968/11 "2013-05-26T01:58:01Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 31, 2013, 2:38pm UTC](https://forum.arduino.cc/t/serial-ttl-linksprite-camera-library-for-arduino-1-0-x/153968/12 "2013-05-31T14:38:51Z")

</div>

Dear manufwi,

thanks a lot for your lib and examples !!

I get the 320_240 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

---

<div class="post-metadata">

**Author:** ![manufwi](https://avatars.discourse-cdn.com/v4/letter/m/c77e96/32.png) [@manufwi](https://forum.arduino.cc/u/manufwi)\
**Post date:** [June 2, 2013, 8:52pm UTC](https://forum.arduino.cc/t/serial-ttl-linksprite-camera-library-for-arduino-1-0-x/153968/13 "2013-06-02T20:52:56Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [June 5, 2013, 11:59am UTC](https://forum.arduino.cc/t/serial-ttl-linksprite-camera-library-for-arduino-1-0-x/153968/14 "2013-06-05T11:59:50Z")

</div>

> 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.](https://code.google.com/p/sdfatlib))

Any ideas ? Thanks !!

---

<div class="post-metadata">

**Author:** ![manufwi](https://avatars.discourse-cdn.com/v4/letter/m/c77e96/32.png) [@manufwi](https://forum.arduino.cc/u/manufwi)\
**Post date:** [June 7, 2013, 11:56pm UTC](https://forum.arduino.cc/t/serial-ttl-linksprite-camera-library-for-arduino-1-0-x/153968/15 "2013-06-07T23:56:24Z")

</div>

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 😉

---

<div class="post-metadata">

**Author:** ![manufwi](https://avatars.discourse-cdn.com/v4/letter/m/c77e96/32.png) [@manufwi](https://forum.arduino.cc/u/manufwi)\
**Post date:** [June 8, 2013, 7:58pm UTC](https://forum.arduino.cc/t/serial-ttl-linksprite-camera-library-for-arduino-1-0-x/153968/16 "2013-06-08T19:58:11Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [June 11, 2013, 10:33am UTC](https://forum.arduino.cc/t/serial-ttl-linksprite-camera-library-for-arduino-1-0-x/153968/17 "2013-06-11T10:33:21Z")

</div>

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:

```cpp
#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.?

---

<div class="post-metadata">

**Author:** ![manufwi](https://avatars.discourse-cdn.com/v4/letter/m/c77e96/32.png) [@manufwi](https://forum.arduino.cc/u/manufwi)\
**Post date:** [June 14, 2013, 2:46am UTC](https://forum.arduino.cc/t/serial-ttl-linksprite-camera-library-for-arduino-1-0-x/153968/18 "2013-06-14T02:46:04Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [June 1, 2014, 9:19am UTC](https://forum.arduino.cc/t/serial-ttl-linksprite-camera-library-for-arduino-1-0-x/153968/19 "2014-06-01T09:19:59Z")

</div>

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

```cpp
#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);        
}

```

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 10:01am UTC](https://forum.arduino.cc/t/serial-ttl-linksprite-camera-library-for-arduino-1-0-x/153968/20 "2021-05-06T10:01:10Z")

</div>


