Help needed on using Arduino mega UART (Tx/Rx)

Hi, anyone can help me on how to use the Tx/Rx on the Arduino mega.

I am connecting a vga camera to the Tx/Rx pin and intend to get it to take a photo whenever a button which is connected to the Arduino is pushed.

I am thinking of saving the photo file in the SD slot provided by the Arduino ethernet shield.

Thanks

I am connecting a vga camera

Your vga camera came in a plain white box labeled "vga camera"? Or, did it come from a manufacturer with a name and a model number?

intend to get it to take a photo whenever a button which is connected to the Arduino is pushed.

And your code looks like?

Hi, thanks for your reply.

I am using uCam serial TTL JPEG camera module.

I do not have my code yet as I could not sync the camera which requires me to send a hex command "AAh 0Dh 00h 00h 00h 00h" and receive an ack "AAh 0Eh 0Dh xx 00h 00h.

I am quite a beginner with the arduino programming, please help...

HH75:
Hi, thanks for your reply.

I am using uCam serial TTL JPEG camera module.

I do not have my code yet as I could not sync the camera which requires me to send a hex command "AAh 0Dh 00h 00h 00h 00h" and receive an ack "AAh 0Eh 0Dh xx 00h 00h.

I am quite a beginner with the arduino programming, please help...

I clicked all the links in your reply. Nothing happened.

I looked at your code. It looks pretty skimpy to me.

Hi,

I am quite sloppy with my programming..my basic startup looks something like this:
My camera is connected to the Rx0 and Tx0, 3.3V and Gnd of the arduino.

String Sync = "AA 0D 00 00 00 00";
String Ack;

void setup(){

Serial.begin(14400); // Sets the data rate at 14400 baud, camera baud rate minimum 14400

}

void loop(){

Serial.write(Sync); //Send sync command to camera
delay(5000); // Wait 5 secs
Serial.println(Ack); // Read acknowledge from camera
}

String Sync = "AA 0D 00 00 00 00";

Where did you get the idea that the camera wants a String?

Do yourself a huge favor, and forget that the String class exists.

It is HIGHLY unlikely that the camera responds to a bunch of characters, whether in a String or a string.

It is far more likely that the camera expects a collection of bytes, containing 0xAA, 0x0D, 0x00, etc.

Hi, sorry for my poor grasps in the programming field...

I am using the codes below however I am still unable to receive any reply from the camera... Can you advise me?

#include <SoftwareSerial.h>
#define CMD_SIZE 6

SoftwareSerial camera(10, 11); // RX - Mega limits RX pin, TX

static const byte CMD_PREFIX = 0xAA;
static const byte CMD_SYNC = 0x0D;
static const byte CMD_ACK = 0x0E;

byte _command[CMD_SIZE];
byte _receive_cmd[CMD_SIZE];

int attempts = 0;

void setup(){
Serial.begin(9600);
camera.begin(14400);
Serial.println(camera.available());
Serial.println("Starting...");
delay(10000);
if(!sync()) {
Serial.println(" failed");
}
}

void loop(){

}

boolean sync() {
bool success = false;
int attempts = 0;
// manual indicates we might need 60 attempts at syncing
while(attempts < 60) {
createCommand(CMD_SYNC, 0x00, 0x00, 0x00, 0x00);
Serial.println("Command created!");
sendCommand();
delay(200);
receiveReply();

if(_receive_cmd[1] == CMD_ACK && _receive_cmd[2] == CMD_SYNC) {
receiveReply();
if(_receive_cmd[1] == CMD_SYNC) {
camera.flush();
createCommand(CMD_ACK, CMD_SYNC, 0x00, 0x00, 0x00);
sendCommand();
return true;
}
else {
return false;
}
}
attempts++;
}
return success;
}

void createCommand(byte cmd, byte param1, byte param2, byte param3, byte param4 ) {
_command[0] = CMD_PREFIX;
_command[1] = cmd;
_command[2] = param1;
_command[3] = param2;
_command[4] = param3;
_command[5] = param4;
}

void sendCommand() {
Serial.println("Sending command:");
for(int i = 0; i < 6; i++) {
camera.write(command*);*
//camera.print(command*,BYTE);
Serial.println(_command);*

* }*

}
boolean receiveReply() {
* delay(1000);*
* if( camera.available() > 0 )*
* {*
* for(int i = 0;i < 6; i++) {*
receive_cmd = camera.read();
* }
return true;
Serial.print("Reply is available");
}
else {
return false;
Serial.print("Reply is not available");
}
}*_

 if( camera.available() > 0 )
  {
    for(int i = 0;i < 6; i++) {
      _receive_cmd = camera.read();
    }

If there is at least one byte, read all 6. No, I don't think so, Hal.