Skip to content

Instantly share code, notes, and snippets.

@GiovanniBalestrieri
Created July 30, 2015 18:34
Show Gist options
  • Save GiovanniBalestrieri/ab58330fc25d1b4f355b to your computer and use it in GitHub Desktop.
Save GiovanniBalestrieri/ab58330fc25d1b4f355b to your computer and use it in GitHub Desktop.
Matab Snippet - Saving CSV data from Arduino to Matlab
fprintf(xbee,'M') ;
notArrived = false;
try
while (get(xbee, 'BytesAvailable')~=0 && ~notArrived)
% read until terminator
sentence = fscanf( xbee, '%s'); % this reads in as a string (until a terminater is reached)
if (strcmp(sentence(1,1),'A'))
notArrived = true;
%decodes "sentence" seperated (delimted) by commaseck Unit')
C = textscan(sentence,'%c %d %d %d %c','delimiter',',');
Wx = C{2};
Wy = C{3};
Wz = C{4};
% [gx, gy, gz] = [x, y, z];
gxdata = [ gxdata(2:end) ; double(Wx) ];
gydata = [ gydata(2:end) ; double(Wy) ];
gzdata = [ gzdata(2:end) ; double(Wz) ];
numberOfSamples = numberOfSamples + 1
end
end
catch exeption
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment