为什么我会收到来自硬件序列号和软件序列相同的性​​能? [英] Why am I getting the same performance from Hardware Serial and Software Serial?

查看:208
本文介绍了为什么我会收到来自硬件序列号和软件序列相同的性​​能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想接口(1)LinkSprite JPEG彩色摄像机TTL接口 - 红外和(2)的Arduino兆2560连接到我的笔记本电脑。虽然我能够打印图像的十六进制值,大约需要30秒,打印1张图像显示器。我认为这是因为我用SoftwareSerial,所以我试图HardwareSerial,不过,每幅图像30秒。使用HardwareSerial应该不是更快?只是想知道,我是否需要一个特殊的电缆连接的Arduino我的笔记本电脑?

我试过波特率为串行接口Serial1和不同的组合。 (Serial.begin(9600),Serial1.begin(38400)),(Serial.begin(38400),Serial1.begin(38400))等等......这不,当我超过38400设置接口Serial1什么更高的工作(它应该能够去更高。)另外,我必须按一定的时间间隔,增加波特率即,9600,19200,38400,57600,74880,115200,230400,250000?

 的#include< SoftwareSerial.h>字节incomingbyte;//配置引脚2和3的软串口
// SoftwareSerial接口Serial1 = SoftwareSerial(2,3);INT A = 0×0000,//读取起始地址
    J = 0,
    K = 0,
    计数= 0;
uint8_t有MH,ML;
布尔EndFlag = 0;
无效设置(){
  Serial.begin(115200);
  Serial1.begin(38400);在ChangeBaudRate()//所做的更改
  ChangeBaudRate();在这里输入的形象描述] [1]
  SendResetCmd();
  延迟(3000);
}空隙环(){
  SendTakePhotoCmd();  Serial.println(开始PIC);
  延迟(100);  而(Serial1.available()大于0){
    incomingbyte = Serial1.read();
  }
  BYTE B [32];  而(!EndFlag){
    J = 0;
    K = 0;
    计数= 0;
    SendReadDataCmd();    延迟(75); //试着往上走
    而(Serial1.available()大于0){
      incomingbyte = Serial1.read();
      ķ++;
      如果((K→5)及及(J&下; 32)及及(EndFlag)!){
        B〔J] = incomingbyte;
        如果((B [J-1] ==为0xFF)及和放大器;(二[J] == 0xD9))
        EndFlag = 1;
        J ++;
        算上++;
      }
    }    为(J = 0; J<计数; J ++){
      如果(B [J] LT;为0x10)
        Serial.print(0);
      Serial.print(B [J],HEX);
    }
    Serial.println();
  }  延迟(3000);
  StopTakePhotoCmd(); //制止这种图片,以便其他人可以采取
  EndFlag = 0; //重新设置标志,让其他图像读取
  Serial.println(PIC结束);
  Serial.println();
  而(1);
}//发送复位命令
无效SendResetCmd(){
  Serial1.write((字节)0x56);
  Serial1.write((字节)×00);
  Serial1.write((字节)值为0x26);
  Serial1.write((字节)×00);
}//发送拍摄照片的命令
无效SendTakePhotoCmd(){
  Serial1.write((字节)0x56);
  Serial1.write((字节)×00);
  Serial1.write((字节)0x36数据);
  Serial1.write((字节)为0x01);
  Serial1.write((字节)×00);  A = 0×0000; //重新设置,使另一张照片拍摄可以
}框架尺寸无效(){
  Serial1.write((字节)0x56);
  Serial1.write((字节)×00);
  Serial1.write((字节)0x34);
  Serial1.write((字节)为0x01);
  Serial1.write((字节)×00);
}//读取数据
无效SendReadDataCmd(){
  MH = A / 0x100的;
  ML =一%的0x100;  Serial1.write((字节)0x56);
  Serial1.write((字节)×00);
  Serial1.write((字节)0x32);
  Serial1.write((字节)的0x0C);
  Serial1.write((字节)×00);
  Serial1.write((字节)的0x0A);
  Serial1.write((字节)×00);
  Serial1.write((字节)×00);
  Serial1.write((字节)MH);
  Serial1.write((字节)ML);
  Serial1.write((字节)×00);
  Serial1.write((字节)×00);
  Serial1.write((字节)×00);
  Serial1.write((字节)为0x20);
  Serial1.write((字节)×00);
  Serial1.write((字节)的0x0A);  A + = 0x20的;
}无效StopTakePhotoCmd(){
  Serial1.write((字节)0x56);
  Serial1.write((字节)×00);
  Serial1.write((字节)0x36数据);
  Serial1.write((字节)为0x01);
  Serial1.write((字节)×03);
}无效ChangeBaudRate(){
  Serial1.write((字节)0x56);
  Serial1.write((字节)×00);
  Serial1.write((字节)0X24);
  Serial1.write((字节)×03);
  Serial1.write((字节)为0x01);
  Serial1.write((字节)0X0D); // 115200 = 0X0D 0xA6
  Serial1.write((字节)0xA6);  Serial1.end(); //不是真的有必要
  Serial1.begin(115200); //改变以匹配相机的新的波特率
}


解决方案

是,Arduino的与相机之间的波特率是决定性因素。 Arduino的和PC(即串行监视器窗口)之间的波特率为9600,但您可以更改为115200的code。与 Serial.begin(115200); ,并在串行监视器窗口(在角落下拉)。

Arduino的与相机之间的默认波特率为38400。虽然这个波特率,您可以将的规范)。这似乎是这个程序的目的:

 无效ChangeBaudRate(){
  Serial1.write((字节)0x56);
  Serial1.write((字节)×00);
  Serial1.write((字节)0X24);
  Serial1.write((字节)×03);
  Serial1.write((字节)为0x01);
  Serial1.write((字节)为0x1C);
  Serial1.write((字节)0x4c);
}

根据规范,这台新的波特率为57600。您可以通过改变最后的两个字节0X0D和0xA6选择115200。 ,然后您必须设置接口Serial1 来新波特率:

 无效ChangeBaudRate(){
  Serial1.write((字节)0x56);
  Serial1.write((字节)×00);
  Serial1.write((字节)0X24);
  Serial1.write((字节)×03);
  Serial1.write((字节)为0x01);
  Serial1.write((字节)0X0D); // 115200 = 0X0D 0xA6
  Serial1.write((字节)0xA6);  Serial1.end(); //不是真的有必要
  Serial1.begin(115200); //改变以匹配相机的新的波特率
}

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
}

解决方案

Yes, the baud rate between the Arduino and the camera is the determining factor. The baud rate between the Arduino and the PC (i.e., the Serial Monitor window) is 9600, but you can change that to 115200 in the code with Serial.begin(115200); and in the Serial Monitor window (pulldown in corner).

The default baud rate between the Arduino and the camera is 38400. While at that baud rate, you can send the "Change Baud Rate" command (section 9 on page 6/10 of the spec). That seems to be the purpose of this routine:

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)0x1c);
  Serial1.write((byte)0x4c);   
}

According to the spec, this sets the new baud rate to 57600. You could choose 115200 by changing the last two bytes to 0x0D and 0xA6. Then you have to set Serial1 to the new baud rate:

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
}

这篇关于为什么我会收到来自硬件序列号和软件序列相同的性​​能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆