Arduino serial sensor data
10 views (last 30 days)
Show older comments
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 Comments
Answers (0)
See Also
Categories
Find more on Arduino Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!