ArCOM-read

Description

Reads values from Arduino using an ArCOM serial port

  • Reads scalar values or arrays

  • Reads signed and unsigned integers of 8, 16 or 32 bits.

Syntax

Data = ArCOM('read', Port, nValues, Datatype, nValues2, Datatype2...)

Parameters

  • Port: An ArCOM serial port struct, created with ArCOM('open'...).

  • nValues: The number of values to read

  • Datatype: A string specifying the data type to read:

    • 'uint8'

    • 'uint16'

    • 'uint32'

    • 'int8'

    • 'int16'

    • 'int32'

  • nValuesN, DatatypeN: Optionally, additional scalars or arrays of data can be read, using pairs of additional data and datatype arguments.

Returns

  • Data: A MATLAB variable containing the data read from Arduino, of the specified data type. If multiple arrays are returned, format Data as [Data1, Data2] = ArCom('read'...

Example

% 1. This reads a 32-bit unsigned integer from Arduino. Arduino is connected to an ArCOM serial port in the current workspace, named MyPort.

MyInteger = ArCOM('read', MyPort, 1, 'uint32');

% 2. This reads a 100-sample waveform from Arduino as signed 16-bit integers.

MyWaveform = ArCOM('read', MyPort, 100, 'int16');

% 3. This reads an 8-bit code, 10 16-bit samples and 50 32-bit timestamps.

[opCode, samples, timestamps] = ArCOM('read', MyPort, 1, 'uint8', 10, 'int16', 50, 'uint32');