Send message to Arduino device from MATLAB
sends a command to the Command Handler implemented by your add-on library with a
user-specified acknowledgement timeout.
Create a command, and use
send it to the Arduino® hardware.
Get the parent Arduino object.
arduinoObj = obj.Parent;
Define the library name.
libName = 'ExampleAddon/HelloWorld';
Define the command ID, and create data to send.
commandID = obj.READ_COMMAND; dataIn = ;
Send the message.
[dataOut, payloadSize] = sendCommand(obj, libName, commandID, dataIn);
Show the result in the MATLAB® command line.
libName— Name of library
Name of library defined in the custom class, specified as a character vector.
commandID— Unique command identifier
Unique command identifier, specified as a number. This number must match the ID in the command handler defined in your custom library header file.
dataIn— Array of integers
An array of integers, specified as a vector. The size of
different for different boards. The below table specifies the size of
dataIn for different boards :
|Leonardo, Micro||150 bytes|
|MKR1000, MKR1010, MKR Zero, Mega2560,MegaADK, Due, Nano 33 IoT||720 bytes|
|Uno, Nano, Pro Mini, Digital Sandbox||57 bytes|
Each byte is limited to an unsigned integer between 0 and 255. Any values greater than 255 must be converted into two unsigned integers between 0 and 255, and will be sent as two separate bytes.
timeout— timeout duration
Timeout duration, specified as a numeric value that is the number
of seconds to wait for an acknowledgement from the server code. Specifying
a timeout duration blocks the MATLAB command line until the
is met. The default is 5 seconds if timeout is not specified.
dataOut— Data returned
Data returned, as an array of doubles
payloadSize— Length of output returned
Length of the output returned by
as a number.