Trying to send big data throug serial ports and Arduino
1 view (last 30 days)
Show older comments
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 Comments
Answers (0)
See Also
Categories
Find more on MATLAB Support Package for Arduino Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!