Reports.Linkspritejpegcolorcamera History

Hide minor edits - Show changes to output

Changed lines 8-9 from:
Beauty of this camera is, it is easy to set up and you can save your images to an SD card. Refresh time for shooting a picture is about 4-5sec. If you are planing to write it to an SD card you should give it something around 8sec. to take a picture and save it to a file.
to:
Beauty of this camera is, it is easy to set up and you can save your images to an SD card. Refresh time for shooting a picture is about 4-5sec. If you are planing to write it to an SD card you should give it something around 8sec. to take a picture and save it to a file. Also, it is possible to change the dimensions, compression of the file and the baudrate of the communication. Serial information about these are all included in the manual.
Deleted line 150:
Deleted lines 179-182:
//Print the response to the 'TAKE_PICTURE' command.
// Serial.write((const uint8_t*)response, count);
// Serial.println();
Changed lines 182-185 from:
//Print the size
// Serial.print("Size: ");
// Serial.println(size);
to:
Deleted line 183:
// Serial.println("Make Directory: /Images");
Deleted line 186:
Changed lines 189-199 from:
// Read in the most recent photo
/*
for (uint8_t i = 0; i < 100; i++) {
filename[12] = i/10 + '0';
filename[13] = i%10 + '0';
if (!MemoryCard.exists(filename)){
break;
}
}
*/
to:
Deleted line 198:
//Check the response for the eof indicator (0xFF, 0xD9). If we find it, set the eof flag
Changed lines 219-221 from:
delay(3000); // necessary?

//sendPhoto(filename);
to:
delay(3000);
Changed line 251 from:
And this is the processing side of the code
to:
And this is the processing side of the code. You need to include an image with the name "loading.jpg" to data folder in your processing sketch folder
Changed line 358 from:
println("send s");
to:
println("send S");
Changed lines 230-232 from:
Serial.print('E');
Serial.print('O');
Serial.print('F
');
to:
Serial.print('EOF');
Changed lines 255-258 from:
Serial.print('E');
Serial.print('O');
Serial.print('F');
to:
Serial.print('EOF');
Changed lines 274-291 from:




to:
And this is the processing side of the code
(:source lang=arduino tabwidth=4 :)


/* Copied from
http://processing.org/discourse/yabb2/YaBB.pl?num=1271281000
REQUESTS
1. Add Text field to enter filename to read in
2. Test for JPG and TXT filenames
3. Add camera commands via serial
*/
/* Then modified by Adam Harvey Jan 08, 2011 */


import processing.serial.*;

Serial myPort;
int i = 1;

String ImageFilename = "Photo_" + year() + "_" + day() + "_" + month() + "-" + hour() + "_" + minute() + "_" + second() + "_" + millis() + ".jpg";
int CharE = 69;
int CharO = 79;
int CharF = 70;
int TotalBytes = 0;
Boolean imageLoading = false;
Boolean imageReceived = false;
long startTime;
PImage cameraImg,loadingImg;

byte[] Photo = {
};

void setup()
{
size(320,240);
//Set and open serial port
myPort = new Serial( this, Serial.list()[0], 115200 );
myPort.clear();
loadingImg = loadImage("loading.jpg");
}

void draw()
{
// Import Picture
if(imageLoading) {
loadPhoto(); // must be polled every time
image(loadingImg,0,0);
}
else if(imageReceived) {
image(cameraImg, 0, 0);
}
}

void loadPhoto() {

byte[] buffer = new byte[64];

while( myPort.available() > 0 )
{

int readBytes = myPort.readBytes(buffer);

for( int i = 0; i < readBytes; i++ )
{

TotalBytes = TotalBytes + 1;

Photo = append( Photo, buffer[i] );

if ( TotalBytes > 2 && Photo[TotalBytes-3] == CharE && Photo[TotalBytes-2] == CharO && Photo[TotalBytes-1] == CharF ) {

// Save picture to file
if( Photo.length > 10 && !imageReceived ) {
print( "Writing to disk " );
print( Photo.length );
println( " bytes ..." );
saveBytes( ImageFilename, Photo );
println( "DONE!" );
println("Time: " + ((millis() - startTime)/1000.0) + "s");

// Open Picture

cameraImg = loadImage(ImageFilename);
imageReceived = true;
imageLoading = false;
//Clear the array
Photo = null; // clear array

//Clear totalbytes
TotalBytes = 0;

//Flush serial port
myPort.clear();

return;
}
}
}
}
}

void initiatePhotoTransfer() {
startTime = millis();
imageReceived = false;
imageLoading = true;
Photo = new byte[0];
TotalBytes = 0;
println("send s");
myPort.write('S');
}
void captureAndSend() {
startTime = millis();
imageReceived = false;
imageLoading = true;
Photo = new byte[0];
TotalBytes = 0;
println("send T");
myPort.write('T');
}
void keyPressed() {
if( key == 'S' && imageLoading == false) {
initiatePhotoTransfer();
}
else if(key == 'T')
captureAndSend();
}


(:sourceend:)
Changed lines 111-112 from:
to:
Also, if you want to take pictures by using Processing, [[http://ahprojects.com/|Adam Harvey]] wrote and example code that takes pictures and saves is through a Processing sketch. He is also using call and response methods to take picture. Here is the Arduino side of his code:
(:source lang=arduino tabwidth=4 :)

/*
From Sparkfun.com
Modified by Adam Harvey Dec. 25, 2010

*/

#include <MemoryCard.h>
#include <SdFat.h>
#include <JPEGCamera.h>
#include <NewSoftSerial.h>

//Create an instance of the camera
JPEGCamera camera;

//Create a character array to store the cameras response to commands
char response[32];
//Count is used to store the number of characters in the response string.
unsigned int count=0;
//Size will be set to the size of the jpeg image.
int size=0;
//This will keep track of the data address being read from the camera
int address=0;
//eof is a flag for the sketch to determine when the end of a file is detected
//while reading the file data from the camera.
int eof=0;
int takeNewPhoto = 0;
boolean takingPhoto = 0;
boolean sendingPhoto = 0;
char filename[] = "/Images/IMG_01.TXT";

void setup()
{
Serial.begin(115200);
camera.begin();
count=camera.reset(response);
delay(3000); // necessary?
//Reset the camera

MemoryCard.begin();
//establishContact(); // send a byte to establish contact until receiver responds
}

void loop()
{
if (Serial.available() > 0) {
// get incoming byte:
int inByte = Serial.read();
if(inByte == 'S')
{
sendPhoto(filename);
}
else if(inByte == 'T'){
takeAndSendPhoto();
}
}

}

void takeAndSendPhoto(){
if(takingPhoto)return;
address = 0;
eof = 0;
size = 0;
count = 0;
takingPhoto = true;
//Take a picture
count=camera.takePicture(response);
//Print the response to the 'TAKE_PICTURE' command.
// Serial.write((const uint8_t*)response, count);
// Serial.println();

//Get the size of the picture
count = camera.getSize(response, &size);
//Print the size
// Serial.print("Size: ");
// Serial.println(size);

// IMG
// Serial.println("Make Directory: /Images");
char *imgDir = "/Images/";
if (!MemoryCard.exists(imgDir))
MemoryCard.makeDir("/Images/");

int c;
int filenum = 0;
// Read in the most recent photo
/*
for (uint8_t i = 0; i < 100; i++) {
filename[12] = i/10 + '0';
filename[13] = i%10 + '0';
if (!MemoryCard.exists(filename)){
break;
}
}
*/

MemoryCard.open(filename, true);

//Starting at address 0, keep reading data until we've read 'size' data.
while(address < size)
{
//Read the data starting at the current address.
count=camera.readData(response, address);
//Store all of the data that we read to the SD card
for(int i=0; i<count; i++){
//Check the response for the eof indicator (0xFF, 0xD9). If we find it, set the eof flag
if((response[i] == (char)0xD9) && (response[i-1]==(char)0xFF))eof=1;
//Save the data to the SD card
MemoryCard.file.print(response[i], BYTE);
Serial.print( (char) response[i] , BYTE);
//If we found the eof character, get out of this loop and stop reading data
if(eof==1)break;
}

address+=count;
if(eof==1){
Serial.print('E');
Serial.print('O');
Serial.print('F');
break;
}
}


MemoryCard.close();

takingPhoto = false;
count=camera.reset(response);
delay(3000); // necessary?

//sendPhoto(filename);
}


void sendPhoto(char filename[]){

if(sendingPhoto)return;
sendingPhoto = true;
MemoryCard.open(filename);
int b;
while((b = MemoryCard.file.read()) >= 0) {
Serial.print( (char) b , BYTE);
}
Serial.print('E');
Serial.print('O');
Serial.print('F');

MemoryCard.close();
sendingPhoto = false;
}

void setImageName(int a, int b){
filename[12] = (char) (a+48);
filename[13] = (char) (b+48);
}

void establishContact() {
while (Serial.available() <= 0) {
Serial.print('A', BYTE); // send a capital A
delay(300);
}
}

(:sourceend:)
















Changed lines 15-18 from:
to:
(:source lang=arduino tabwidth=4 :)

/*
JPEG Camera Example Sketch
The sketch will take a picture on the JPEG Serial Camera and store the jpeg to an SD card
on an SD Shield
Written by Ryan Owens
SparkFun Electronics

Hardware Notes:
This sketch assumes the arduino has the microSD shield from SparkFun attached.
The camera Rx/Tx should be attached to pins 2 and 3.
IMPORTANT: The JPEG camera requires a TTL level shifter between the camera output
and the arduino. Bypassing this may damage the Arduino pins.
*/

//This example requires the MemoryCard, SdFat, JPEGCamera and NewSoftSerial libraries
#include <MemoryCard.h>
#include <SdFat.h>
#include <JPEGCamera.h>
#include <NewSoftSerial.h>

//Create an instance of the camera
JPEGCamera camera;

//Create a character array to store the cameras response to commands
char response[32];
//Count is used to store the number of characters in the response string.
unsigned int count=0;
//Size will be set to the size of the jpeg image.
int size=0;
//This will keep track of the data address being read from the camera
int address=0;
//eof is a flag for the sketch to determine when the end of a file is detected
//while reading the file data from the camera.
int eof=0;

void setup()
{
//Setup the camera, serial port and memory card
camera.begin();
Serial.begin(9600);
MemoryCard.begin();

//Reset the camera
count=camera.reset(response);
delay(3000);

//Take a picture
count=camera.takePicture(response);
//Print the response to the 'TAKE_PICTURE' command.
Serial.write(response);
Serial.write(count);
Serial.println();

//Get the size of the picture
count = camera.getSize(response, &size);
//Print the size
Serial.print("Size: ");
Serial.println(size);

//Create a file called 'test.txt' on the SD card.
//NOTE: The memoryCard libary can only create text files.
//The file has to be renamed to .jpg when copied to a computer.
MemoryCard.open("/test.txt", true);
//Starting at address 0, keep reading data until we've read 'size' data.
while(address < size)
{
//Read the data starting at the current address.
count=camera.readData(response, address);
//Store all of the data that we read to the SD card
for(int i=0; i<count; i++){
//Check the response for the eof indicator (0xFF, 0xD9). If we find it, set the eof flag
if((response[i] == (char)0xD9) && (response[i-1]==(char)0xFF))eof=1;
//Save the data to the SD card
MemoryCard.file.print(response[i], BYTE);
//If we found the eof character, get out of this loop and stop reading data
if(eof==1)break;
}
//Increment the current address by the number of bytes we read
address+=count;
//Make sure we stop reading data if the eof flag is set.
if(eof==1)break;
}
//Close the file
MemoryCard.close();
Serial.print("Done.");
}

void loop()
{

}

(:sourceend:)
Changed lines 14-18 from:
After making these connections, rest is all up to your code. You definitely need to download the libraries from sparkfun.com and include them to Arduino. They also have good example codes. However, if you are new with programing and Arduino or not a C programmer, you might find these examples a bit complicated. So, I have simplified some of their examples. Here is an example that saves pictures to SD card by using [[http://www.sparkfun.com/products/9802|sparkfun micro sd board]]
to:
After making these connections, rest is all up to your code. You definitely need to download the libraries from sparkfun.com and include them to Arduino. They also have good example codes. However, if you are new with programing and Arduino or not a C programmer, you might find these examples a bit complicated. So, I have simplified some of their examples. Here is an example that saves pictures to SD card by using [[http://www.sparkfun.com/products/9802|sparkfun microSD shield]]
Deleted lines 9-10:
Arduino is using serial port to communicate with the camera. However, if you want to save this picture to an SD card or send it to processing, you need to use serial ports also. So, in this case we are using soft serial which is included in Arduino Uno.
Changed lines 13-18 from:
to:
Arduino is using serial port to communicate with the camera. However, if you want to save this picture to an SD card or send it to processing, you need to use serial ports also. So, in this case we are using soft serial which is included in Arduino Uno. As you can see from the picture, you need to connect power pin to +3.3v and ground pin to Arduino's ground pin. As I already mentioned, this time we are going to use soft serial port to communicate between Arduino and camera. We are going to connect '''TX pin to Arduinoss digital pin "2"''' and '''RX pin to Arduino's digital pin "3"'''
After making these connections, rest is all up to your code. You definitely need to download the libraries from sparkfun.com and include them to Arduino. They also have good example codes. However, if you are new with programing and Arduino or not a C programmer, you might find these examples a bit complicated. So, I have simplified some of their examples. Here is an example that saves pictures to SD card by using [[http://www.sparkfun.com/products/9802|sparkfun micro sd board]]


Changed lines 3-4 from:
Beauty of this camera is, it is easy to set up and you can save your images to an SD card.
to:
Changed lines 8-12 from:
As I said earlier, this camera is using TX/RX(Serial) connection for data transfer. However, if you want to save this picture to an SD card or send it to processing, you need to use serial ports also. So, in this case we are using soft serial which is included in Arduino Uno. LinkSprite JPEG camera is running on +3.3v which you can easily get from Arduino. Here is a picture of the camera and the pins:
to:
Beauty of this camera is, it is easy to set up and you can save your images to an SD card. Refresh time for shooting a picture is about 4-5sec. If you are planing to write it to an SD card you should give it something around 8sec. to take a picture and save it to a file.

Arduino is using serial port to communicate with the camera. However, if you want to save this picture to an SD card or send it to processing, you need to use serial ports also. So, in this case we are using soft serial which is included in Arduino Uno.

LinkSprite JPEG camera is running on +3.3v which you can easily get from Arduino. Here is a picture of the camera and the pins:
Changed lines 10-12 from:
[[Attach:linkSprite_pin|Attach:linkSprite_pin]]
to:
[[Attach:linkSprite_pin.png|Attach:linkSprite_pin.png]]
Changed lines 10-12 from:
[[Attach:linkSprite_pin.png|Attach:linkSprite_pin.png]]
to:
[[Attach:linkSprite_pin|Attach:linkSprite_pin]]
Changed lines 10-12 from:
[[Attach:TlinkSprite_pin.png|Attach:linkSprite_pin.png]]
to:
[[Attach:linkSprite_pin.png|Attach:linkSprite_pin.png]]
Changed lines 10-11 from:
[[AttachlinkSprite_pin|linkSprite_pin]]
to:
[[Attach:TlinkSprite_pin.png|Attach:linkSprite_pin.png]]
Changed lines 10-11 from:
[[AttachlinkSprite_pin||Attach:linkSprite_pin]]
to:
[[AttachlinkSprite_pin|linkSprite_pin]]
Added lines 8-11:

As I said earlier, this camera is using TX/RX(Serial) connection for data transfer. However, if you want to save this picture to an SD card or send it to processing, you need to use serial ports also. So, in this case we are using soft serial which is included in Arduino Uno. LinkSprite JPEG camera is running on +3.3v which you can easily get from Arduino. Here is a picture of the camera and the pins:
[[AttachlinkSprite_pin||Attach:linkSprite_pin]]
Added line 2:
Added line 4:
Added line 7:
[[http://www.sparkfun.com/datasheets/Sensors/Imaging/JPEG%20Camera%20Libraries.zip|You can download the libraries that you need from this link]]. Sparkfun, prepared the libraries that you need with example codes.
Changed line 1 from:
[[LinkSprite JPEG Color Camera|linkto:http://www.sparkfun.com/products/10061]] is simple camera that you can use with your Arduino projects. It is size is Size 32X32mm and you can get it for $49.95 from [[Sparkfun|http://www.sparkfun.com]].
to:
[[http://www.sparkfun.com/products/10061|LinkSprite JPEG Color Camera]] is simple camera that you can use with your Arduino projects. It is size is Size 32X32mm and you can get it for $49.95 from [[http://www.sparkfun.com|Sparkfun]].
Changed line 1 from:
[[LinkSprite JPEG Color Camera|http://www.sparkfun.com/products/10061]] is simple camera that you can use with your Arduino projects. It is size is Size 32X32mm and you can get it for $49.95 from [[Sparkfun|http://www.sparkfun.com]].
to:
[[LinkSprite JPEG Color Camera|linkto:http://www.sparkfun.com/products/10061]] is simple camera that you can use with your Arduino projects. It is size is Size 32X32mm and you can get it for $49.95 from [[Sparkfun|http://www.sparkfun.com]].
Changed line 1 from:
[[LinkSprite JPEG Color Camera||http://www.sparkfun.com/products/10061]] is simple camera that you can use with your Arduino projects. It is size is Size 32X32mm and you can get it for $49.95 from [[Sparkfun||http://www.sparkfun.com]].
to:
[[LinkSprite JPEG Color Camera|http://www.sparkfun.com/products/10061]] is simple camera that you can use with your Arduino projects. It is size is Size 32X32mm and you can get it for $49.95 from [[Sparkfun|http://www.sparkfun.com]].
Added lines 1-4:
[[LinkSprite JPEG Color Camera||http://www.sparkfun.com/products/10061]] is simple camera that you can use with your Arduino projects. It is size is Size 32X32mm and you can get it for $49.95 from [[Sparkfun||http://www.sparkfun.com]].
Beauty of this camera is, it is easy to set up and you can save your images to an SD card.
Arduino is using serial port to communicate with the camera. Refresh time for shooting a picture is about 4-5sec. If you are planing to write it to an SD card you should give it something around 8sec. to take a picture and save it to a file.