Skip to content

Instantly share code, notes, and snippets.

@knowblesse
Last active June 21, 2021 05:12
Embed
What would you like to do?
%% GSR_arduino_matlab
% Galvanic Skin Response - Matlab integration script
% 2021 Knowblesse
%% Setup connection
ard = arduino('COM6','Mega2560'); % COM port must be provided manually!
% and this code should be run no more than once, unless you cleared the
% value.
%% Setup DAQ parameters
fs = 20; % sampling frequency (Hz)
acquisition_points = 100; % number of data points to acquire
verbose = false; % if true, it prints out recording values
%% Setup DAQ
fprintf('Total %d datapoints will be acquired during %.2f minute(s)\n',acquisition_points, 1/fs*acquisition_points/60);
dataset = zeros(acquisition_points, 2); % first column : timepoint, second column : datapoint
fig = figure(1);
clf;
ax = plot(dataset(:,2));
%% Begin Acquisition
tic
for i = 1 : acquisition_points
dataset(i,2) = readVoltage(ard, 'A0');
dataset(i,1) = toc;
ax.YData = dataset(:,2);
drawnow;
if verbose, fprintf('%03.2f : %.2f V\n',dataset(i,1), dataset(i,2)), end
pause(1/fs);
end
%% Redraw data with interpolation
plot(dataset(:,1), dataset(:,2),'Color',[0.5, 0.5, 0.5]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment