Go Down

Topic: Code error on camera JPEG ttl sketch (Read 13788 times) previous topic - next topic

aarg

#90
Nov 13, 2015, 02:08 am Last Edit: Nov 13, 2015, 02:10 am by aarg
Are your TX and RX reversed maybe?

You shouldn't have started another thread. This belongs with the first one.
  ... with a transistor and a large sum of money to spend ...
Please don't PM me with technical questions. Post them in the forum.

Marciokoko

#91
Nov 13, 2015, 02:59 am Last Edit: Nov 13, 2015, 03:35 am by Marciokoko
Do you know if I can merge them or does an admin have to do it?

How do I delete this one?

Marciokoko

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?

DuaneDegn

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.

Marciokoko

Oh, sorry, I meant its the TTL version. 

Marciokoko

#95
Nov 13, 2015, 07:20 pm Last Edit: Nov 13, 2015, 07:21 pm by Marciokoko Reason: image
Hey guys, it was suggested to me that I need to use an FTDI chip converter thing :-(  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?

DuaneDegn

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?

Marciokoko

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.

Marciokoko

#98
Nov 13, 2015, 11:12 pm Last Edit: Nov 13, 2015, 11:13 pm by Marciokoko Reason: image
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.

Marciokoko

\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?

DuaneDegn

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.

Marciokoko

Mine is this one: https://www.sparkfun.com/products/11610

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. 

DuaneDegn

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.

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?

Marciokoko

picture taken?  What sketch is that from? 

Anyway, I dont see anything in the serial monitor.

DuaneDegn

#104
Nov 14, 2015, 06:55 am Last Edit: Nov 14, 2015, 06:57 am by DuaneDegn
picture taken?  What sketch is that from? 
Both of the sketches you attached to post 97 include the line:

Code: [Select]
     Serial.print("picture taken");

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.

Code: [Select]
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.

Code: [Select]
/* 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.

Go Up