I'm trying to interface (1) LinkSprite JPEG Color Camera TTL Interface - Infrared and (2) Arduino Mega 2560 connected to my laptop. While I am able to print the HEX values of the images, it takes about 30 seconds to print 1 image to the monitor. I thought that it was because I was using SoftwareSerial, so I tried HardwareSerial, but still, 30 seconds per image. Shouldn't it be faster using HardwareSerial? Just wondering, do I need a special cable connecting the arduino to my laptop?
I tried different combinations of baud rates for Serial and Serial1. (Serial.begin(9600), Serial1.begin(38400)), (Serial.begin(38400), Serial1.begin(38400)) etc... This doesn't work when I set Serial1 anything higher than 38400. (It should be able to go higher..) Also, do I have to increase baud rate by a certain interval namely, 9600, 19200, 38400, 57600, 74880, 115200, 230400, 250000?
#include <SoftwareSerial.h>
byte incomingbyte;
//Configure pin 2 and 3 as soft serial port
//SoftwareSerial Serial1 = SoftwareSerial(2, 3);
int a=0x0000, //Read Starting address
j=0,
k=0,
count=0;
uint8_t MH,ML;
boolean EndFlag=0;
void setup() {
Serial.begin(115200);
Serial1.begin(38400); //made changes in ChangeBaudRate()
ChangeBaudRate();[enter image description here][1]
SendResetCmd();
delay(3000);
}
void loop() {
SendTakePhotoCmd();
Serial.println("Start pic");
delay(100);
while(Serial1.available()>0) {
incomingbyte=Serial1.read();
}
byte b[32];
while(!EndFlag) {
j=0;
k=0;
count=0;
SendReadDataCmd();
delay(75); //try going up
while(Serial1.available()>0) {
incomingbyte=Serial1.read();
k++;
if((k>5)&&(j<32)&&(!EndFlag)) {
b[j]=incomingbyte;
if((b[j-1]==0xFF)&&(b[j]==0xD9))
EndFlag=1;
j++;
count++;
}
}
for(j=0;j<count;j++) {
if(b[j]<0x10)
Serial.print("0");
Serial.print(b[j], HEX);
}
Serial.println();
}
delay(3000);
StopTakePhotoCmd(); //stop this picture so another one can be taken
EndFlag = 0; //reset flag to allow another picture to be read
Serial.println("End of pic");
Serial.println();
while(1);
}
//Send Reset command
void SendResetCmd() {
Serial1.write((byte)0x56);
Serial1.write((byte)0x00);
Serial1.write((byte)0x26);
Serial1.write((byte)0x00);
}
//Send take picture command
void SendTakePhotoCmd() {
Serial1.write((byte)0x56);
Serial1.write((byte)0x00);
Serial1.write((byte)0x36);
Serial1.write((byte)0x01);
Serial1.write((byte)0x00);
a = 0x0000; //reset so that another picture can taken
}
void FrameSize() {
Serial1.write((byte)0x56);
Serial1.write((byte)0x00);
Serial1.write((byte)0x34);
Serial1.write((byte)0x01);
Serial1.write((byte)0x00);
}
//Read data
void SendReadDataCmd() {
MH=a/0x100;
ML=a%0x100;
Serial1.write((byte)0x56);
Serial1.write((byte)0x00);
Serial1.write((byte)0x32);
Serial1.write((byte)0x0c);
Serial1.write((byte)0x00);
Serial1.write((byte)0x0a);
Serial1.write((byte)0x00);
Serial1.write((byte)0x00);
Serial1.write((byte)MH);
Serial1.write((byte)ML);
Serial1.write((byte)0x00);
Serial1.write((byte)0x00);
Serial1.write((byte)0x00);
Serial1.write((byte)0x20);
Serial1.write((byte)0x00);
Serial1.write((byte)0x0a);
a+=0x20;
}
void StopTakePhotoCmd() {
Serial1.write((byte)0x56);
Serial1.write((byte)0x00);
Serial1.write((byte)0x36);
Serial1.write((byte)0x01);
Serial1.write((byte)0x03);
}
void ChangeBaudRate(){
Serial1.write((byte)0x56);
Serial1.write((byte)0x00);
Serial1.write((byte)0x24);
Serial1.write((byte)0x03);
Serial1.write((byte)0x01);
Serial1.write((byte)0x0D); // 115200 = 0x0D 0xA6
Serial1.write((byte)0xA6);
Serial1.end(); // Not really necessary
Serial1.begin( 115200 ); // change to match the camera's new baud rate
}