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

2 ビュー (過去 30 日間)
Shlok Sharma
Shlok Sharma 2020 年 1 月 28 日
回答済み: Tony Lennon 2020 年 2 月 10 日
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.

コミュニティ

カテゴリ

Help Center および File ExchangeData Acquisition Toolbox Supported Hardware についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by