MATLAB: Simulink IO enabled error on Arduino Uno

arduino unoMATLABsimulink io

I am trying to use the Simulink IO enabled feature in MATLAB 2018a. The platform is an Arduino Uno. Even with the simplest example, for instance trying to read from pin 4 and displaying it I get an error although simulation mode works fine without IO enabled, and when I load the program onto the hardware it also works fine. Here is error that I see when I enable Simulink IO:
MATLAB System block 'blink2/Digital Input/Digital Input' error occurred when invoking 'setupImpl' method of 'codertarget.arduinobase.blocks.DigitalRead'. The error was thrown from '
'C:\ProgramData\MATLAB\SupportPackages\R2018a\toolbox\target\shared\ioserver\+matlabshared\+ioclient\+transport\TransportLayerAbstract.p' at line 0
'C:\ProgramData\MATLAB\SupportPackages\R2018a\toolbox\target\shared\ioserver\+matlabshared\+ioclient\IOProtocol.p' at line 0
'C:\ProgramData\MATLAB\SupportPackages\R2018a\toolbox\target\shared\ioserver\+matlabshared\+ioclient\IOProtocol.p' at line 0
'C:\ProgramData\MATLAB\SupportPackages\R2018a\toolbox\target\shared\ioserver\+matlabshared\+ioclient\+peripherals\DigitalIO.p' at line 0
'C:\ProgramData\MATLAB\SupportPackages\R2018a\toolbox\target\supportpackages\arduinobase\+codertarget\+arduinobase\+blocks\DigitalRead.p' at line 0'.
Caused by:
Transport layer object is corrupted. Try fclose(instrfind) and delete(instrfind) and then create a new hardware object

Best Answer

I have found that the problem was using a Sparkfun Redboard, which is an Arduino Uno clone. It uses a different serial port. Once I switched to an Arduino Uno the problem resovled.
Related Question