Arduino serial sensor data

6 次查看(过去 30 天)
Caserace
Caserace 2019-3-4
Hi, using Arduino Uno to output sensor data to the serial monitor . Here I am using a GY-521 module. I followed some previous direction for proper arduino code with a /t character so Matlab can easily distinguish each value. All of this works, until 512 bytes are recieved. At which point, the serial monitor stops. I can have continous displaying if I use Python but then I have to have another step to convert that to Matlab workspace. Below is the Matlab code - this was found here, I just modified it a little for my needs. Once I get to 512 bytes it stops, and I get an error. If I run delete(instrfindall); % close the serial port, then restart it everything will work again until 512 bytes. How can I overcome this so continous monitoring can occur?
Thanks
arduin=serial('COM3','BaudRate',115200); % create serial communication object on port COM18
arduin.InputBufferSize = 1024;
fopen(arduin); % initiate arduino communication
while(arduin.BytesAvailable <= 0) %wait until Arduino outputs data
disp('Waiting For Data to Start coming')
end
ax = [];
ay = [];
az = [];
for i=1:50 %while if constant acquisition is needed.
sSerialData = fscanf(arduin); %read sensor
flushinput(arduin);
t = strsplit(sSerialData,'\t'); % same character as the Arduino code
ax(i,1) = str2double(t(1));
ay(i,1) = str2double(t(2));
az(i,1) = str2double(t(3));
end

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB Support Package for Arduino Hardware 的更多信息

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by