improper serial communication with arduino and image acquisition not working?

조회 수: 2 (최근 30일)
barath V
barath V 2020년 1월 29일
댓글: Tony Lennon 2020년 2월 3일
i established serial communication between arduino and matlab.arduino rotates the motor ad prints "1" in the serial monitor.the serial data needs to be read by matlab and camera is triggered by matlab to capture an image.i want to control pointgrey camera using matalb?but this is not happening.
arduino code is working, but the matlab code is not working.
help required with image acquisition.pls
thanks.
%this is arduino code%
#include<Stepper.h>
int ms1 = 10;
int ms2 = 9;
int ms3 = 8;
int stepin = 6;
int dirnpin = 7;
int steps[8] = {10,12,14,16,30,40,60,100};
int k;
int numberofsteps;
boolean condition = true;
void setup()
{
pinMode(ms1,OUTPUT);
pinMode(ms2,OUTPUT);
pinMode(ms3,OUTPUT);
pinMode(stepin,OUTPUT);
pinMode(dirnpin,OUTPUT);
Serial.begin(9600);
}
void loop() {
digitalWrite(ms1,HIGH);
digitalWrite(ms2,HIGH);
digitalWrite(ms3,HIGH);
if (condition == true)
{ condition = false;
for(int k =0;k<8;)
{
barath(steps[k]);
delay(3000);
Serial.print(1);
k+=1;
}
}
}
int barath(int numberofsteps)
{
for(int j = 0;j<numberofsteps;j++)
{
digitalWrite(stepin,LOW);
digitalWrite(dirnpin,HIGH);
delay(5);
digitalWrite(stepin,HIGH);
digitalWrite(dirnpin,HIGH);
delay(5);
}
}
%matlab code%
arduino=serial('COM3','BaudRate',9600);
fopen(arduino);
TopCam = videoinput('pointgrey', '1');
start(TopCam);
for j = 1:10
commandforcamera = fscanf(arduino,'%i');
if commandforcamera < 10
TopImg = getsnapshot(TopCam);
imshow(TopImg);
end
end
stop(TopCam)
fclose(arduino)
  댓글 수: 1
Tony Lennon
Tony Lennon 2020년 2월 3일
Please, would you post this question on MATLAB Answers? It will receive more views when posted there than on the Power Electronics Control community. Thanks.

댓글을 달려면 로그인하십시오.

답변 (0개)

커뮤니티

더 많은 답변 보기:  Power Electronics Community

카테고리

Help CenterFile Exchange에서 MATLAB Support Package for Arduino Hardware에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by