Trying to program a ?CAM Serial JPEG Camera w/o using a SD card

Hi, I am actually trying to program a Serial JPEG Camera without saving the image to the SD card. However, when I serial monitor the code, I received a 12, FFFFFFAAFFFFFF87432120FFFFFFE0FFFFFFAA21201010FFFFFFF0, 0 and done (I have attached a screenshot of it.). I’m having a problem with the HEX conversion. Could anyone please advise? Thank you :slight_smile:

I am using a Arduino Duemilanove Atmega328 version 1.0.3 and a ?CAM Serial JPEG Camera.

Here is my code.

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

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

//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(115200);
    //camera.begin(9600);
    //camera.begin(14400);
    //camera.begin(57600);
    //camera.begin(115200);
    Serial.begin(9600);
    
    //Reset the camera
    count=camera.sync(response);
    
    Serial.println(count);
    for (int i = 0; i < count; i++)
      Serial.print(response[i],HEX);

    Serial.println();
    delay(3000);
    
    count=camera.sync(response);
    
    Serial.println(count);
    for (int i = 0; i < count; i++)
    {
      char buf[9];
      sprintf(buf, "%X", response[i]);
      Serial.print(buf);
    }
    Serial.println();
    
    delay(3000);
    
    //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);
    
    
    //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
            Serial.write(response[i]);
            //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
     Serial.print("Done.");
     camera.end();
}

void loop()
{

}

1.jpg

AA
87
43
21
20
E0
AA
21
20
10
10
F0

The extra digits were just sign-extension.

Simplest way would be to mask the least-significant eight bits:

for (int i = 0; i < count; i++)
      Serial.print(response[i] & 255,HEX);

Correct in what sense, newbie?

Does it compile? Does it work?

What happens, compared to what you expect to happen?

How to use this forum

I'm presuming you are using a library. How about a link to the library, and all of your code?

It seems like something isn't right in the JPEGCamera code when it reads the response

Can you describe what that "something" seems to be? You expect "something", but "something" else happens. We don't know what either of those "something"s is.

... something isn't right in the JPEGCamera code when it reads the response ...

You are going to have to be a lot more explicit.

How to use this forum

How about posting all of your code, or did I ask you to do that before? And did you?

Please do not cross-post. This wastes time and resources as people attempt to answer your question on multiple threads.

Threads merged.

  • Moderator