Arduino serial sensor data
6 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 MATLAB Support Package for Arduino Hardware 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!