improper serial communication with arduino and image acquisition not working?help needed

2 次查看(过去 30 天)
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-10
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.

社区

更多回答在  Power Electronics Control

类别

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