Warning: Unexpected Warning: A timeout occurred before the Terminator was reached - Arduino

3 views (last 30 days)
I'm struggling to get to grips with MatLab's fscanf function. I have two Serial.println() within the Arduino loop:
void loop() {
sample = digitalRead(kHRM_Pin);
if (sample && (oldSample != sample)) {
Serial.println(BPM);
SDCardWrite();
}
oldSample = sample;
}
The function SDCardWrite also prints an error message in order to inform me that there was an error when writting to an SD card:
void SDCardWrite() {
...............
Serial.println("Error Writing To Card!");
}
}
I'm trying to capture the BPM variable using either fscanf(ard, '%d'); or fgetl(ard); I just keep getting various characters from the "error writing to sd card", or [] or Warning: Unsuccessful read: Matching failure in format.
More worryingly, when I try and close the serial object using fclose(ard);, MatLab hangs saying busy , then the computer (Mac) kernel crashes and restarts!

Answers (1)

Sreeram Mohan
Sreeram Mohan on 25 Sep 2014
Hi Darryl,
Suggestion 1: Did you try setting the timeout property of the serial to be of a higher value ? Just to make sure you give enough time for the serial to read ? http://www.mathworks.in/help/matlab/matlab_external/timeout.html
Suggestion 2:
In your code on the arduino it looks like the values to serial are sent only when some conditions are met. Where as on the other hand the MATLAB code is running infinitely without this knowledge and expects a string to come in to it.
Instead could you send an error on serial say a Serial.println("error"); in the else part of the Arduino code and filter these errors out and only take datas that are not having the errors ?
This would definitely prove to be a better method to remove the warning that you are observing !
Hope this helps !!
Sreeram Mohan
  1 Comment
Darryl
Darryl on 25 Sep 2014
Hi Sreeram,
Sorry, but I have completely re-edited my post as I have other problems that are related to the previous post.
I simplified the Serial prints within the Arduino loop and got rid of the error message, but now have other problems.
Please see above.

Sign in to comment.

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!