Trying to send big data throug serial ports and Arduino
1 次查看(过去 30 天)
显示 更早的评论
Hi!
I am trying to send some data (actually the elements of an 400x600x3 matrix which I read from a jpg image) from matlab to an Arduino, and the Arduino should send it back to the PC so I could read it out from the serial port. On the Arduino I wired together the IO ports 0-1 (these are for serial communications). It works fine for a few characters but when I try to send bigger matrices I get an error:
Warning: Unsuccessful read: The specified amount of data was not returned within the Timeout period.. Assignment has more non-singleton rhs dimensions than non-singleton subscripts.
I have no idea how to move on, please can someone help me? Thanks a lot.
Matlab code:
arduinoCom = serial('COM15', 'BaudRate', 9600);
arduinoCom.Terminator = ('');
fopen(arduinoCom);
A = imread('img_lights.jpg');
[row, col, dim] = size(A);
for i=1:row
for j=1:col
for k=1:dim
strSend = char(A(i,j,k));
fprintf(arduinoCom, strSend);
B(i,j,k) = fread(arduinoCom, 1);
end
end
end
Arduino code:
void setup() {
Serial1.begin(9600);
Serial.begin(9600);
}
void loop() {
char a; char b;
if(Serial.available()){
Serial1.write(Serial.read());
}
if(Serial1.available()){
Serial.write(Serial1.read());
}
}
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File 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!