JPEG serial rs232 camera

Valen,

Yesterday I was posting back and forth with someone who suggested I tried a code just for testing what was coming in. I still havent gotten my cable which I had to order from the states in order to be able to connect the camera directly to my mac.

Can you help me modify the code in order to determine if the camera is working at all? Can I send the camera a simple code and read its response just to that code and determine if that response is correct?

You do not need to buy that specific FTDI cable product (from sparkfun). There are also alot of similar usb-to-serial cables/modules. The keyword to look for is “USB to Serial TTL”. TTL means the signals operate between 0 and 3.3/5 volt.

If it has such a connector as you shown before it would be a called RS232 serial and operate with voltages between 12 and -12 volt. Those are risky if your device is unknown to handle that.

As an example, this cable on Amazon should also do the trick. You may need to install appropriate drivers though for it to work. Based on PL2303 or Cp2102 chips are good. You will find dozens of these kind of serial cables on Ebay, DX.com Alibaba, etc… It usually does come from China though, so perhaps with long delivery times.

http://www.amazon.com/Armorview-PL2303H … B008AGDTA4

I can only help if you show the code. Or post a link to the forumthread where you discussed this with that person. I am not psychic you know. Well, not reliably anyway.

For testing you can indeed upload a program that bridges the two serial ports on the Arduino together and does nothing else:

I just don’t know how well the software serial library works at these relatively high baudrates.

#include <SoftwareSerial.h>

SoftwareSerial mySerial(5,6);          // Software serial port on TX pin 5, RX on pin 6

void setup() {
   Serial.begin(38400);
   mySerial.begin(38400);

}

void loop() {
   // read from hardware serial port, send to software Serial port:
   if (Serial.available()) {
     int inByte = Serial.read();
     mySerial.print(inByte, BYTE); 

   }
   // read from software serial port, send to port hardware serial port:
   if (mySerial.available()) {
     int inByte = mySerial.read();
     Serial.print(inByte, BYTE); 
   }
}

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.

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

It seems the camera is not responding.

On september 17th I posted a link to a sparkfun tutorial showing how you could send number code sequence in hexadecimal format to the serial port. With the last code I posted uploaded to your Arduino it should act as a bridge between the computer and camera. Only relaying the sent bytes and it’s response back anf forth.

As you seem to be having trouble with understanding the code, I would opt for a solution (for testing purposes only) that has as little code involved as possible. That means sending the number sequence manually with coolterm or whatever, and see if something comes back. Or, once you have the USB to TTL serial module/cable , to connect the camera directly to your computer and use coolterm to send something instead of an Arduino. Once you have found that it communicates back you can go on further by writing a basic program that does the same automatically. And build from that do to do more advanced stuff like actually getting images from it. If it doesn’t work at all (after having tried all possible baudrates) then you can consider the camera dead.

[EDIT] Or we could write a program for the Arduino that tries to listen for voltage level changes on the camera TX pin. Testing the digital level of the pin it is connected to, or measure the analog voltage of it continuously. Unless you have access to an oscilloscope, then it would be a lot easier to see what is going on in those wires.

The trick in problem solving is by going back to basics. Reduce complexity and stuff that you do not understand or goes beyond your understanding.

I believe I got a camera response.

Be more specific.

Nevermind…I didn’t!

This camera really sucks and the manufacturer is terrible at customer support.