Skip to content

Instantly share code, notes, and snippets.

@mhanuel26
Created March 17, 2020 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhanuel26/035d9ea8bfbd31291fea943bc0c20425 to your computer and use it in GitHub Desktop.
Save mhanuel26/035d9ea8bfbd31291fea943bc0c20425 to your computer and use it in GitHub Desktop.
Matlab script to communicate with RSL10 and get sensor values
% a clean start
clear all;
pause on;
% list all bluetooth devices
list = blelist;
% Address is the Bluetooth device address
% Address = "E5FFFF221194"; RSL10 Eval board
Address = "60C0BF2891E6"; %RSL10 SENS baord
%connect to our device
try
b = ble(Address);
catch
warning('cannot connect to peripheral device');
return
end
% we can have a programatically way to extract this characteristics
% rxc = characteristic(b, "E093F3B5-00A3-A9E5-9ECA-40016E0EDC24", "E093F3B5-00A3-A9E5-9ECA-40026E0EDC24");
rxc = characteristic(b, "E093F3B5-00A3-A9E5-9ECA-40016E0EDC24", "E093F3B6-00A3-A9E5-9ECA-40026E0EDC24");
% txc = characteristic(b, "E093F3B5-00A3-A9E5-9ECA-40016E0EDC24", "E093F3B5-00A3-A9E5-9ECA-40036E0EDC24");
txc = characteristic(b, "E093F3B5-00A3-A9E5-9ECA-40016E0EDC24", "E093F3B7-00A3-A9E5-9ECA-40036E0EDC24");
global i;
global dv;
global gv;
record_length = 8;
sample_rate = 5; %samples per second.
rsamples = record_length*sample_rate;
i = 1;
dv = zeros(10,4);
gv = zeros(10,4);
subscribe(rxc);
rxc.DataAvailableFcn = @displayCharacteristicData;
disp('start acquisition loop');
% request data every sampling period
while true
write(txc, 'A/AO/A');
% write(txc, 'G/AO/AR');
if(i > rsamples)
return;
else
pause(1/sample_rate);
i = i + 1;
end
end
function displayCharacteristicData(src,evt)
global i;
global dv;
global gv;
[data,timestamp] = read(src,'oldest');
c = char(data);
cs = split(c, '/');
packet = char(cs(1));
switch packet
case 'A'
% disp('received accelerometer data');
acc = split(cs(2), ',');
dv(i, 1) = str2double(acc(1));
dv(i, 2) = str2double(acc(2));
dv(i, 3) = str2double(acc(3));
dv(i, 4) = i;
case 'G'
% disp('received GYROSCOPE data');
gyro = split(cs(2), ',');
gv(i, 1) = str2double(gyro(1));
gv(i, 2) = str2double(gyro(2));
gv(i, 3) = str2double(gyro(3));
gv(i, 4) = i;
case '9'
disp('received ALS-NOA1305 data');
case '7'
disp('received HUMIDITY data');
case '5'
disp('received PRESSURE data');
otherwise
disp('not implemented response');
end
% disp(data);
% disp(timestamp);
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment