Serial Port Timing Issues

9 views (last 30 days)
Fritz Sonnichsen
Fritz Sonnichsen on 3 Jul 2022
Answered: Fritz Sonnichsen on 4 Jul 2022
I am trying to establish serial communications between an Arduino and a WIN10 machine. I am using the USB / FTDI arduino connection.
The arduino code is simple-it listens on the serial port, and when ANYthing arrives it simply sends out a phrase. I tested this on a windows serial terminal and it works fine--entering any character returns the phrase. I use the LED on the board to show that data arrived. (see attached zip)
Now, coding the Matlab side, it works sporadically. In the attached code and I show a work around--issue the character to the arduino twice, and wait 2 seconds in between sends. The LED lights both times. Waiting a smaller amout of time generally (but not aways) results in a "Not returned within Timeout" condiiton.
I am expecting that this is some type of timing problem-the MATLAB session is not "listening" in time. I did not see any timing settings in the serialport command. And trying to code a wait on NumBytesAvailable hung matlab as well.
Any ideas appreciated
Fritz

Answers (1)

Fritz Sonnichsen
Fritz Sonnichsen on 4 Jul 2022
Here is a further clarification on this problem. In the attached code things run as expected--however-I must start with a pause(3) after issuing the serialport command. Apparently matab is slow here and needs time to finish the serial setup. I assume this is a bug-it should wait until it is ready. I do not see anything in the doc that has a wait after issuing the command.
Not pertinent here but worth mentioning: I also see an issue with the "terminator" command. The formalities of serial communications do not require a terminator and in fact in computer-to-computer communications this is often not wanted. However viewing other posts it seems as though matlab forces the terminator.
Fritz

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!