How to have Matlab wait for Arduino to finish execution?

8 views (last 30 days)
Is it possible to have Matlab wait for code execution on an Arduino before it proceeds without using pause? I am sending data over to an Arduino and then have Arduino do something. Is there any way for me to have Matlab wait for the execution on the Arduino then to continue? I would prefer not to use wait because I have different scenarios where the execution time on the Arduino varies.

Answers (1)

Walter Roberson
Walter Roberson on 22 Jun 2020
MATLAB has no idea how long it takes Arduino to finish actions. The only way it could know the Arduino is finished is if the Arduino tells it.
There are two basic choices:
  1. Have the arduino emit something when the action is finished, and fread() / fgets() / fgetl() the arduino serial port . Reading from a serial port waits until data is ready (or until timeout). If you take this approach you can also configure callbacks to be triggered when data is available from the serial port. This approach would work especially well if you had configured code on the arduino rather than using the convenience layer such as readDigitalPin()
  2. After sending the command to the Arduino, request a reading from the Arduino, such as reading a digital pin, knowing that the arduino will not be able to process that until it has finished the previous request. This would work better if you are using the convenience layer rather than sending code to the Arduino yourself.
  6 Comments
Walter Roberson
Walter Roberson on 1 Jul 2020
Unfortunately I have been struggling to install Arduino on my system, so I cannot test this :(
Dave
Dave on 2 Jul 2020
Hi Walter, thank you for replying and assiting with this issue. I currently have the Arduino from the Microsoft Store app installed. I think i got the code to work with a hard pause, vs reading the buffer. I can read the buffer but something is off that i haven't yet figured out. I am still working on it though.

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!