Yes but I need to send the camera a command to see if its responding, don’t I?
Ive been using this code I got from someone named al2lo and it wasnt working. I was so sick of this that I tried moving the Vcc pin to the camera to 3.3V instead of 5V. I believe I got a camera response.
I had added some Serial.prints as marker1,2 & 3 in the sendCommand definition like so:
Here is the code I tried:
#include <SoftwareSerial.h>
class JPEGCamera{
public:
JPEGCamera();
void begin(void);
int reset(char * response);
int getSize(char * response, int * size);
int takePicture(char * response);
int stopPictures(char * response);
int readData(char * response, int address);
private:
int sendCommand(const char * command, char * response, int length);
};
const char GET_SIZE[5] = {0x56, 0x00, 0x34, 0x01, 0x00};
const char RESET_CAMERA[4] = {0x56, 0x00, 0x26, 0x00};
const char TAKE_PICTURE[5] = {0x56, 0x00, 0x36, 0x01, 0x00};
const char STOP_TAKING_PICS[5] = {0x56, 0x00, 0x36, 0x01, 0x03};
char READ_DATA[8] = {0x56, 0x00, 0x32, 0x0C, 0x00, 0x0A, 0x00, 0x00};
const int read_size=32;
SoftwareSerial cameraPort(4,5);
JPEGCamera::JPEGCamera(){}
void JPEGCamera::begin(void){
//Camera baud rate is 38400
cameraPort.begin(38400);
}
//=======
int JPEGCamera::reset(char * response){
return sendCommand(RESET_CAMERA, response, 4);
}
int JPEGCamera::takePicture(char * response){
return sendCommand(TAKE_PICTURE, response, 5);
}
int JPEGCamera::stopPictures(char * response)
{
return sendCommand(STOP_TAKING_PICS, response, 5);
}
int JPEGCamera::getSize(char * response, int * size)
{
int count=0;
//Send the GET_SIZE command string to the camera
count = sendCommand(GET_SIZE, response, 5);
//Read 4 characters from the camera and add them to the response string
for(int i=0; i<4; i++)
{
while(!cameraPort.available());
response[count+i]=cameraPort.read();
}
//Set the number of characters to return
count+=4;
//The size is in the last 2 characters of the response.
//Parse them and convert the characters to an integer
*size = response[count-2]*256;
*size += (int)response[count-1] & 0x00FF;
//Send the number of characters in the response back to the calling function
return count;
}
int JPEGCamera::sendCommand(const char * command, char * response, int length){
char c=0;
int count=0;
//Clear any data currently in the serial buffer
cameraPort.flush();
//Send each character in the command string to the camera through the camera serial port
for(int i=0; i<length; i++){
cameraPort.write(*command++);
}
Serial.print("marker1");
//Get the response from the camera and add it to the response string.
for(int i=0; i<length; i++)
{
while(!cameraPort.available());
Serial.print("marker2");
*response++=cameraPort.read();
count+=1;
Serial.print("marker3");
}
//return the number of characters in the response string
return count;
}
int JPEGCamera::readData(char * response, int address)
{
int count=0;
//Flush out any data currently in the serial buffer
cameraPort.flush();
//Send the command to get read_size bytes of data from the current address
for(int i=0; i<8; i++)cameraPort.write(READ_DATA[i]);
cameraPort.write(address>>8);
cameraPort.write(address);
cameraPort.write((uint8_t)0x00);
cameraPort.write((uint8_t)0x00);
cameraPort.write((uint8_t)(read_size>>8));
cameraPort.write(read_size);
cameraPort.write((uint8_t)0x00);
cameraPort.write((uint8_t)0x0A);
//Print the data to the serial port. Used for debugging.
/*
for(int i=0; i<8; i++)Serial.print(READ_DATA[i]);
Serial.print(address>>8rt.write);
Serial.print(addressrt.write);
Serial.print(0x00rt.write);
Serial.print(0x00rt.write);
Serial.print(read_size>>8rt.write);
Serial.print(read_sizert.write);
Serial.print(0x00rt.write);
Serial.print(0x0Art.write);
Serial.println();
*/
//Read the response header.
for(int i=0; i<5; i++){
while(!cameraPort.available());
cameraPort.read();
}
//Now read the actual data and add it to the response string.
count=0;
while(count < read_size)
{
while(!cameraPort.available());
*response++=cameraPort.read();
count+=1;
}
//Return the number of characters in the response.
return count;
}
//=======
JPEGCamera camera;
char response[32];
unsigned int count=0;
int size=0;
int address=0;
int eof=0;
void setup()
{
pinMode(10, OUTPUT); // set the SS pin as an output (necessary!)
digitalWrite(10, HIGH); // but turn off the W5100 chip!
//Setup the camera, serial port and memory card
camera.begin();
Serial.begin(9600);
Serial.println("Starting");
Serial.println("Starting 1");
//Reset the camera
Serial.println("Starting 2");
count=camera.reset(response);
Serial.write(response);
delay(5000);
Serial.println("Starting 3");
//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);
//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 Serial Monitor
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;
}
Serial.print("Done.");
}
void loop()
{
}
I was only getting marker1 and marker2. And as for the ones in the setup() I was only getting up to Starting1 and Starting2.
In a moment of desperation I moved the camera’s Vcc pin into Arduino from 5V to 3.3V and I got this:
Quote
Starting
Starting 1
Starting 2
marker1marker2marker2marker2marker2marker34
Starting 3
marker1marker2marker2marker2marker2marker2marker3.
marker1marker2marker2marker2marker2marker2marker3
Which means that not only did I get past marker3, but I also got Starting3. This should mean the camera is responding, right?
So I went back and I tried the original linksprite sketch now with the 3.3V pin and Im still only getting 00.
It seems the camera is not responding.