Skip to content

Instantly share code, notes, and snippets.

View GiovanniBalestrieri's full-sized avatar
🍣
When there is a shell, there is a way

UserK GiovanniBalestrieri

🍣
When there is a shell, there is a way
View GitHub Profile
@GiovanniBalestrieri
GiovanniBalestrieri / .m
Last active August 29, 2015 14:26
Snippet 3 - Rolling Plot Matlab Arduino Gyroscope
while (abs(Wz) < 2500)
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;
%% store and plot
@GiovanniBalestrieri
GiovanniBalestrieri / .m
Created July 28, 2015 02:36
Snippet 4 - Rolling Plot Matlab Arduino Gyroscope
% Save angular rates from the received CSV string
C = textscan(sentence,'%c %d %d %d %c','delimiter',',');
Wx = C{2};
% update the buffer
gxdata = [ gxdata(2:end) ; Wx ];
% Plot, anzi subPlot!
subplot(3,1,1);
title('X Axis Omega in deg/s');
@GiovanniBalestrieri
GiovanniBalestrieri / .m
Last active August 29, 2015 14:26
Full code - Rolling Plot Matlab Arduino Gyroscope
%% Arduino Gyroscope real time plot
% userk.co.uk
% The sensor used in this project is the L3G4200D
% !!Caution!! operative voltage: 3.3 V
clear all;
clc;
clear('instrfindall');
%% Check serial objects & Connect to Port
@GiovanniBalestrieri
GiovanniBalestrieri / .ino
Created July 30, 2015 16:16
Saving CSV data from Arduino to Matlab
void printCSVomega()
{
Serial.print("A,");
Serial.print(x);
Serial.print(",");
Serial.print(y);
Serial.print(",");
Serial.print(z);
@GiovanniBalestrieri
GiovanniBalestrieri / .ino
Created July 30, 2015 18:19
Snippet - Saving CSV data from Arduino to Matlab
void serialRoutine()
{
if(Serial.available()>0)
{
char t = Serial.read();
if (t =='T')
{
Serial.println("Ok");
}
@GiovanniBalestrieri
GiovanniBalestrieri / .m
Created July 30, 2015 18:25
Matlab Snippet - Saving CSV data from Matlab to Arduino
%% Ask desired Sample Rate in Hz
rate=input('Enter the sampleRate in Hz. Max 500Hz. Non sgravare... ');
delay = 1/rate;
str = sprintf('SampleRate fixed to: %f.', delay);
disp(str);
%% Initializinig rolling plot
buf_len = rate;
index = 1:buf_len;
@GiovanniBalestrieri
GiovanniBalestrieri / .m
Created July 30, 2015 18:34
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',',');
@GiovanniBalestrieri
GiovanniBalestrieri / .m
Created July 30, 2015 18:36
Matab Snippet - Saving CSV data from Arduino to Matlab
% wait one second then record
if numberOfSamples==rate*2 && recording
disp('saving samples to file');
gDataToWrite = [gxdata gydata gzdata];
csvwrite('samples.txt',gDataToWrite);
disp('saving file to structure');
dat.x = gxdata;
dat.y = gydata;
dat.z = gzdata;
save('samples.mat','-struct','dat');
@GiovanniBalestrieri
GiovanniBalestrieri / .m
Created July 30, 2015 18:54
Full Code - Saving CSV data from Arduino to Matlab
%% Arduino Gyroscope real time plot
% The sensor used in this project is the L3G4200D
clear all;
clc;
clear('instrfindall');
finished = false;
recording = true;
@GiovanniBalestrieri
GiovanniBalestrieri / .m
Created August 3, 2015 21:25
snippet - Basic Matlab Filter
%% Signal definition
% Sampling Frequency Fs
Fs = 350;
% Sinusoid frequency
freq = 30;
bias = 15
t = 0:1/Fs:1;
% Generate random values [min,max] = [xm,xM]