I have a trouble in programming to read and write data of the VCNL4010 sensor through a serial port in Matlab. I use a VCNL4010 sensor and Arduino Uno to measure two values including ambient light and height. These values will be transported via a serial port to monitor in real time, as well as save to analyzing later. I have tried many codes but it seemed to not work well. Could you help me to solve them? Thank you so much.
global arduino; global i;
try fopen(arduino); % Open Serial Port Object disp('Serial port is opened'); catch err fclose(instrfind); error('Make sure you select the correct COM Port where the Arduino is connected.'); end
%% Read buffer data delaySec = 0.01; for i = 1: 10 pause(delaySec); arduino.RecordDetail = 'verbose'; arduino.RecordName = 'MySerialFile.txt'; record(arduino,'on') out = fscanf(arduino) end record(arduino,'off')
fclose(arduino); disp('Serial port is closed');