Error using Arduino (line 1) Internal error: The initialization of the server code is incorrect.

20 visualizzazioni (ultimi 30 giorni)
Hi,
I'm trying to connect Arduino MEGA 2560 to Matlab 2021b on windows 10. The connection type is USB.
a=arduino('COM3','mega2560')
I installed the supported hardware package for both Matlab and Simulink.
Then, I put 'a=arduino' on matlab, but it keeps saying there's an error:
Error using Arduino (line 1)
Internal error: The initialization of the server code is incorrect.
I checked the Board and Port (under tools in Arduino IDE) and they're all correct.
I've been trying to fix it for couple hours, but it just never works...
Does any one know how to fix it?

Risposte (1)

Chetan
Chetan il 27 Set 2023
It appears that you are encountering an issue while connecting with the Arduino board and getting an error while initialization.
This issue might occur if the hardware is not getting reset correctly because of the smaller delay time.
The issue can be resolved by changing the "delayValue" to 10 in "getResetDelayHook()" in "arduino.m". The file can be found by executing the following code snippet in the MATLAB Command Window:
which -all Arduino
The code for the method getResetDelayHook() in "arduino.m" looks like the following:
function delayValue = getResetDelayHook(obj)
% workaround for Arduino Mega on Linux taking longer time to reset, explained in g1638539
if(obj.ConnectionType==matlabshared.hwsdk.internal.ConnectionTypeEnum.Serial)
if ispc || ismac
delayValue = 2;
else
delayValue = 10;
end
else
%The reset on the DTR line is via Serial only
delayValue = 0;
end
end
Change the value of delayValue inside the if statement (if ispc ismac) to 10. This will give the board more time to get reset and after that connection can be established.
For more details read the following MathWorks Document:
I hope these suggestions help you resolve the issue you are facing.

Categorie

Scopri di più su Arduino Hardware in Help Center e File Exchange

Tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by