Serial read Arduino data
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Greetings to the forum. This is my first post around here. Mu main task is the following,
I am trying to read sensor data from arduino in matlab through serial port. Then I will try to calibrate my sensor but not using any of the predefined functions. I have written a simple coad that sends serial data separated by the special character \t. Then having that in mind I am trying to separate them in columns in my .m script.
Code so far is the following one :
clear all;
clc;
sFile = 'AcceDualAxis.csv';
delete(instrfindall);
s1 = serial('COM8');
s1.BaudRate = 500000;
fopen(s1);
s1.ReadAsyncMode = 'continuous';
readasync(s1);
mData = [];
time = 0;
count = 0;
tic;
while(toc<10)
sSerialData = fread(s1,1,'uchar')
sSerialData = fscanf(s1, '%c');
count = count + 1;
time(count) = toc;
flushinput(s1);
t = (str2double(strsplit(sSerialData, '\t'));
disp(t);
end
delete(instrfindall);
csvwrite(sFile,mData);
Main idea is the following one. In the near future I will try to break down specific tasks with specific functions. By sending a special character from matlab through serial to arduino I will try to read each one of the three axes and execute a specific preocedure for each one of them.
First way is the following one : By sending a special character I will try to read specific sensors ( 'R' --> read accelerometer - 'L' --> read gyroscope etc...)
Second way is the following one : Having all data in my serial monitor, then each function will try to read a specific part of the data. Lets say for example, that 'Gyro_cal' will try to read only the three first columns of data.
Each way of these have the same deadlock. When I try to call 't' for reading my data I only get the last line of them. 't' only saves my last line of data so when I try to read a specific section of them I cannot do that.
So i need some help with the following:
*Try to organize my data into columns (something that i have already achieved)
*Try to save all data in matrix form, so i can call specific lines and columns of them.
*Re- arrange them in order to cal them with the specific time that they occured ( this will be helpful for later stages of numerical integration)
Any help would be much appreciated.
Thanks in advance, sorry for any mistakes to my post.
Best wishes,
Koutsoukos Theodosis
0 comentarios
Respuestas (0)
Ver también
Categorías
Más información sobre MATLAB Support Package for Arduino Hardware en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!