unable to establish serial connection between arduino ide and matlab

hi,i want the motor to rotate initially,then i have calculated the focus image index value in matlab,i want to send the value to arduino ide and the motor should rotate and come back to focus index value.
but its not happening

4 件のコメント

barath V
barath V 2020 年 2 月 12 日
%matlab code
clc;
clear all;
CAMERA = videoinput('pointgrey', '1');
start(CAMERA);
pause(1);
a = serial('COM3','BaudRate',9600);
fopen(a);
pause(1);
fprintf(a,'%i',index)
fclose(a)
for i = 1:20
filename = sprintf('testtry%02d.jpg',i);
img = im2double(getsnapshot(CAMERA));
img = rgb2gray(img);
stop(CAMERA)
imwrite(img,filename)
end
D = 'C:\Users\PRL\Desktop\just';
S = dir(fullfile(D,'*.jpg')); % pattern to match filenames.
for k = 1:numel(S)
F = fullfile(D,S(k).name);
a(k) = bodekke(F);
end
plot(a);
[m,index] = max(a)
hold on
plot(index,m,'*')
hold off
title("bodekke with spot images")
function[addition] = bodekke(imagename)
im = double(imread(imagename))
bd = [-1 0 1]
cbd = conv2(im,bd)
squaredcbd = cbd.^2
addition = sum(squaredcbd(:))
end
Walter Roberson
Walter Roberson 2020 年 2 月 12 日
fprintf(a,'%i',index)
index is not a defined variable at that point.
barath V
barath V 2020 年 2 月 12 日
yes sir,i also get the same error i calculate the index value in matlab after i close the serial port,so only i get the error.
i tried to move the fprintf and fclose() command after second loop where i finished calculating index value,for that i get a different error.
barath V
barath V 2020 年 2 月 14 日
any ideas or help please?

サインインしてコメントする。

回答 (1 件)

カテゴリ

ヘルプ センター および File Exchange で MATLAB Support Package for Arduino Hardware についてさらに検索

製品

リリース

R2018b

質問済み:

2020 年 2 月 12 日

回答済み:

2020 年 12 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by