Code error on camera JPEG ttl sketch

Ok,

  1. I dont know what you mean by the last post (85), about wanting me to verify I/O RS232 DB9 not compatible 0-5V logic?

  2. You want me to upload the code on 82 and do both (remove 5V pin UNO-CAMERA and then plug it back in && then try removing the usb cable from mac and plugging it back in) and you want me to see what shows up on the IDE Serial Monitor instead of CoolTerm. I just want to mention that its possible that nothing will happen as I tried that a while back. So Ill try removing GND on a separate test as well.

  3. What do you mean by "You do have the original vendor's code , not the JPEGCamera "library" right?" I do have the original sketch from linksprite which sends 3 commands (reset, takepicture & readdata) inside the setup/loop methods. Its the one you posted in 31 & 6 and its pretty much the same HazardsMinds posted in 35. Is that the one you mean?

Read the Note on page 15 of the spec

http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Sensors/LightImaging/UserManual.pdf[quote

author=Marciokoko link=msg=2409345 date=1443064051]
Ok,

  1. I dont know what you mean by the last post (85), about wanting me to verify I/O RS232 DB9 not compatible 0-5V logic?

Read the Note on page 15 of the spec

I would shoot an e-mail to vendor for clarification

http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Sensors/LightImaging/UserManual.pdf[quote

  1. what do they mean - camera uses RS232 internally AKA why they even need the MAX232
  2. How do us suppose to "remove MAX232"

These two item are little contradictory.

But per note - you either need to remove MAX232 or use "RS232 level converter" to go from RS232 to +5V signaling. The vendor MAY have a app note to tell what hardware to use to interface to Arduino.

  1. You want me to upload the code on 82 and do both (remove 5V pin UNO-CAMERA and then plug it back in && then try removing the usb cable from mac and plugging it back in) and you want me to see what shows up on the IDE Serial Monitor instead of CoolTerm. I just want to mention that its possible that nothing will happen as I tried that a while back. So Ill try removing GND on a separate test as well.

The "power up" response is send from camera when the power ( 3.3 or 5 V ) is first applied .
Do no ever disconnect ground as test, always the "hot" power only when testing.
Not until you answer the # 1 no sense to proceed with software.

  1. What do you mean by "You do have the original vendor's code , not the JPEGCamera "library" right?" I do have the original sketch from linksprite which sends 3 commands (reset, takepicture & readdata) inside the setup/loop methods. Its the one you posted in 31 & 6 and its pretty much the same HazardsMinds posted in 35. Is that the one you mean?

Yes, that is what I call "original" code , not the JPEGCamera libray, and it should work.

Unfortunately "they" did not code for "init (power-up)".

From the picture you posted it appears that you wired the DB9 connector (TX/RX) to Arduino.
That's OK,( but see item#1 - that would be an issue !), but if you have a real DB9 cable to connect to your PC you could just run same power up test just connecting the camera to PC serial port and get a bunch of text in your "cool" terminal.

[/quote]

Ok,

  1. I send email to manufacturer.

  2. Ok no sense in proceeding without first resolving RS232 & MAX232 issue.

  3. I dont have a DB9 connector, I dont even know what it is....Oh ok I saw what it is. Even if I had one though, I dont have a PC that I can go test that in. And even if I did, I need it to work on my mac for programming it.

So if #3 is required, I need to return this camera.

Thanks so much for all your help!

Marciokoko:
Ok,

  1. I send email to manufacturer.

  2. Ok no sense in proceeding without first resolving RS232 & MAX232 issue.

  3. I dont have a DB9 connector, I dont even know what it is....Oh ok I saw what it is. Even if I had one though, I dont have a PC that I can go test that in. And even if I did, I need it to work on my mac for programming it.

So if #3 is required, I need to return this camera.

Thanks so much for all your help!

Marciokoko:
Ok,

  1. I send email to manufacturer.

  2. Ok no sense in proceeding without first resolving RS232 & MAX232 issue.

  3. I dont have a DB9 connector, I dont even know what it is....Oh ok I saw what it is. Even if I had one though, I dont have a PC that I can go test that in. And even if I did, I need it to work on my mac for programming it.

So if #3 is required, I need to return this camera.

Thanks so much for all your help!

Marciokoko:
Ok,

  1. I send email to manufacturer.

  2. Ok no sense in proceeding without first resolving RS232 & MAX232 issue.

  3. I dont have a DB9 connector, I dont even know what it is....Oh ok I saw what it is. Even if I had one though, I dont have a PC that I can go test that in. And even if I did, I need it to work on my mac for programming it.

So if #3 is required, I need to return this camera.

Thanks so much for all your help!

I dont have a DB9 connector...
Well, you do need DB9 connector as long as you can wire correct pins on the DB9 side to you processor.
Get the MAX 232 issue resolved and than we can proceed.
You could always add RS232 to TTL converted if necessary ( about $10 max)

Admins
I have no idea why I am getting all these extra copies of the quotes!
I cannot delete them!!!!!!!!!!!!!!!!!

Ok guys, I've got my camera back from the supplier who says they tested it and it is working properly.

I also bought a second, identical unit, from a different supplier and it also gives no data to the sketch Im using, so I need some guidance on now to figure this out.

I would like to use the simplest sketch possible to determine if the camera is at least responding.

The sketch that yields no data in CoolTerm (just 0D 0A) is the attached manufacturer Linksprite sketch.

My setup is also included as an image in the attachments.

LinkSprite_cam_IR.ino (3.14 KB)

Are your TX and RX reversed maybe?

You shouldn't have started another thread. This belongs with the first one.

Do you know if I can merge them or does an admin have to do it?

How do I delete this one?

Ok I got word back from the manufacturer. The unit is working fine according to them. They sent it back. In the meantime i got an identical unit from another supplier and I get the same results.

Manufacturer/Supplier

They said I needed to use IDE 0023 and NewSoftSerial library plus the pde sketch they send. That pde sketch is the same ino I tried originally. Im attaching it here. I tried it and I get the same 0D 0A which I understand means no data. I've emailed them asking them for more options.

Again here is my setup and the sketch Im trying.

What else can I try?

_0023_JPEGLinksprite.pde (2.76 KB)

LinkSprite_cam_IR.ino (3.14 KB)

The thread title says "rs232". Is this a RS232 version of the camera of a TTL version?

If it's the RS232 version, you shouldn't connect it directly to the microcontroller's I/O pins.

Oh, sorry, I meant its the TTL version.

Hey guys, it was suggested to me that I need to use an FTDI chip converter thing :frowning: I've been reading up on FTDI and Serial, USB, TTL, RS232 etc. Its a bit much for now so bare with me.

My question is, since I have tried about 10 different sketches with 2 camera units and have yet to get a camera response, does it seem logical or likely that it is necessary to use this converter thing? I actually already have one, it must be because someone suggested it. This other person suggested today saying he has used it with his camera unit and got it to work.

So I need a little help setting it up.

What I have is a USB-TTL PL2302 module.

This is the one the user suggests:

http://www.frys.com/product/6997547?site=sr:SEARCH:MAIN_RSLT_PG

Im not sure if its the same thing first of all.

And second, I need help wiring it up. Normally I have a usb(computer) to avr cable. In this case this unit I have has 5 pins at one end (3.3,5v,tx,rx and gnd) and a usb port on the other side.

If I have to hook up the rx & tx pins to the camera, fine, but how does that connect to the avr and computer?

Marciokoko:
If I have to hook up the rx & tx pins to the camera, fine, but how does that connect to the avr and computer?

If the camera is connected to the computer why does the AVR chip need to be connected?

Oh wellbecause I dont know how to send commands to the camera without the avr running a sketch. So this means that if I use this I can only send commands to the camera directly, this is not for using with an avr? Because I need, eventually, to run a sketch on the UNO to control the camera.

Ok, I connected the camera directly to the computer using the usb-ttl, here is the picture:

I open up CoolTerm and set these options:

38400 because the camera is rated at 38400
8-n-1
I open up the Send String, select Hex and send it either of these commands, one at a time of course:

56 00 26 00 ... which should return ... 76 00 26 00

and

56 00 36 01 00 ... which should return ... 76 00 36 00 00

But neither retuns anything. As a matter of fact, CoolTerm shows its Tx light but never am Rx light. And the only light on the usb-ttl is a red power light, not a tx/rx light.

My connections are:

Camera red(Rx) to converter Tx
Camera brown(Tx) to converter Rx
Camera purple(GND) to converter GND
Camera gray 5V to converter 5V.

\o/ YEAY!

I just tested my camera with the usb-ttl converter I got. It wasnt working before because I didnt have the pl2303 driver installed. I installed it and it responded to my reset command.

So how does this relate to my sketch? Why doesnt the sketch work?

Several years ago, I purchased this thing. I just took it out of its package for the first time ever.

I downloaded your programs and I'll take a look at them. It sure looks like there's something wrong with the original code.

My camera is a RS232 version so I need to wire up a MAX232 chip or hack into the 3.3V signal on the board.

I'm not sure I'll end up being much help but I wanted you to know someone else is looking at this.

Mine is this one: LinkSprite JPEG Color Camera TTL Interface - Infrared - SEN-11610 - SparkFun Electronics

Well maybe you can help me understand this much:

The camera has only worked from my computer's usb port thru a usb-ttl converter using pl2303 drivers.

Do I need something special in my sketch that will allow the arduino to make the camera work properly? Or is the usb-ttl converter and the pl2303 drivers just something my mac needs to communicate with it but not an Arduino UNO board?

Because it doesnt seem like the camera is getting any commands (much less responding to them) when hooked up to the arduino via the sketches.

Marciokoko:
Do I need something special in my sketch that will allow the arduino to make the camera work properly? Or is the usb-ttl converter and the pl2303 drivers just something my mac needs to communicate with it but not an Arduino UNO board?

Your Mac needs the PL2303 drivers to communicate with the USB to TTL converter chip. The Arduino communicates with the camera over TTL so it just needs to send the correct commands.

Marciokoko:
Because it doesnt seem like the camera is getting any commands (much less responding to them) when hooked up to the arduino via the sketches.

It looks like the LinkSprite just needs to be updated to use the modern version of the software serial driver. I don't see anything wrong with your attempt yet but I'm attempting my own conversion to the modern driver.

I see some things in the original code which don't make sense to me.

There isn't a reason the camera shouldn't work with the Arduino.

Do you see the line "picture taken" when you run your program?

picture taken? What sketch is that from?

Anyway, I dont see anything in the serial monitor.

Marciokoko:
picture taken? What sketch is that from?

Both of the sketches you attached to post 97 include the line:

     Serial.print("picture taken");

Marciokoko:
Anyway, I dont see anything in the serial monitor.

I notice many Arduino programs seem to use 9600 baud. The programs you attached use 19200. Do you have the terminal window set to the correct baud?

I changed the baud to 115200 and added a function to dump any reply from the camera to the terminal.

If the camera replies to the reset command, the program should echo this reply to the terminal and tell you how many bytes were received.

If the program doesn't receive any input from the camera, it will display this message.

Timeout with no data from camera.
Bad News! The camera did not reply to the reset command.
Check the connections and try again.
End of program.

Here's the modified program.

/* Linksprite */

#include <SoftwareSerial.h>

#define CAMERA_RX 5
#define CAMERA_TX 4

// copied from an Adafruit program
SoftwareSerial mySerial = SoftwareSerial(CAMERA_TX, CAMERA_RX);


//SoftwareSerial mySerial(4,5);                     //Configure pin 4 and 5 as soft serial port
int cameraAddress = 0x0000;    
//uint8_t
byte addressHigh, addressLow;
boolean endFlag = 0;
const byte ZERO = 0;
const unsigned long TIMEOUT_INTERVAL = 2000;
unsigned long startWaitingTime;

/*void SendResetCmd();
void SendTakePhotoCmd();
void SendReadDataCmd();
void StopTakePhotoCmd();
*/
void setup()
{
  Serial.begin(115200); // Make sure your terminal is set to the same baud.
  mySerial.begin(38400);
}

void loop()
{
  SendResetCmd();
  
  int replySize = dumpRxToTerminal(TIMEOUT_INTERVAL); // output any returned characters
  if (replySize > 0)
  {
    Serial.print("Good News! The camera returned ");
    Serial.print(replySize);
    Serial.println(" bytes!");
    Serial.println("Waiting a few seconds before taking a picture.");
  }
  else
  {
    Serial.println("Bad News! The camera did not reply to the reset command.");
    Serial.println("Check the connections and try again.");
    Serial.println("End of program.");
    while (1) {} // endless loop
  }
  
  delay(4000);                               //After reset, wait 2-3 second to send take picture command

  SendTakePhotoCmd();
  Serial.print("picture taken");
  /*while(mySerial.available() > 0)
   {
     incomingbyte = mySerial.read();

   }  */
  byte rxBuffer[32];

  while (!endFlag)
  {
    int rxBufferIndex = 0;
    int indexK = 0;
    int countIndex = 0;
    SendReadDataCmd();

    delay(25);
    while (mySerial.available() > 0)
    {
      byte inputCharacter = mySerial.read();
      indexK++;
      if ((indexK > 5) && (rxBufferIndex < 32) && (!endFlag))
      {
        rxBuffer[rxBufferIndex] = inputCharacter;
        if ((rxBuffer[rxBufferIndex - 1] == 0xFF) && (rxBuffer[rxBufferIndex] == 0xD9)) //Check if the picture is over
          endFlag = 1;
        rxBufferIndex++;
        countIndex++;
      }
    }

    for (int i = 0; i < countIndex; i++)
    {
      if (rxBuffer[i] < 0x10)
      {
        Serial.print("0");
      }
      Serial.print(rxBuffer[i], HEX);
      Serial.print(" ");
    }                                       //Send jpeg picture over the serial port
    Serial.println();
  }
  while (1);
}

//Send Reset command
void SendResetCmd()
{
  mySerial.write(0x56);
  mySerial.write(ZERO);
  mySerial.write(0x26);
  mySerial.write(ZERO);
}

//Send take picture command
void SendTakePhotoCmd()
{
  mySerial.write(0x56);
  mySerial.write(ZERO);
  mySerial.write(0x36);
  mySerial.write(0x01);
  mySerial.write(ZERO);
}

//Read data
void SendReadDataCmd()
{
  addressHigh = cameraAddress >> 8;
  addressLow = cameraAddress; 
  mySerial.write(0x56);
  mySerial.write(ZERO);
  mySerial.write(0x32);
  mySerial.write(0x0c);
  mySerial.write(ZERO);
  mySerial.write(0x0a);
  mySerial.write(ZERO);
  mySerial.write(ZERO);
  mySerial.write(addressHigh);
  mySerial.write(addressLow);
  mySerial.write(ZERO);
  mySerial.write(ZERO);
  mySerial.write(ZERO);
  mySerial.write(0x20);
  mySerial.write(ZERO);
  mySerial.write(0x0a);
  cameraAddress += 0x20;                            //address increases 32£¬set according to buffer size
}

void StopTakePhotoCmd()
{
  mySerial.write(0x56);
  mySerial.write(ZERO);
  mySerial.write(0x36);
  mySerial.write(0x01);
  mySerial.write(0x03);
}

int dumpRxToTerminal(unsigned long timeoutInterval)
{
  unsigned long beginTimeout = millis();
  boolean firstRxFlag = 1;
  int receivedCharacters = 0;
  while (millis() - beginTimeout < timeoutInterval)
  {
    if (mySerial.available() > 0)
    {
      if (firstRxFlag)
      {
        firstRxFlag = 0;
        Serial.print("received from camera = ");
      }
      byte inputCharacter = mySerial.read();
      Serial.print(inputCharacter, HEX);
      Serial.print(" ");
      beginTimeout = millis(); // reset timer
      receivedCharacters++;
    }

  }
  if (firstRxFlag)
  {
    Serial.println("Timeout with no data from camera.");
  }
  else
  {
    Serial.println();
    Serial.println("End of received data.");
  }
  return receivedCharacters;
}

I changed some of the variable names in an attempt to better understand what the program was doing. I still don't understand the bulk of the program but at least now you should be able to see if the camera replies to the reset command.

I have not tested the program with my camera.