-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArduino.m
More file actions
69 lines (63 loc) · 1.88 KB
/
Arduino.m
File metadata and controls
69 lines (63 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
% % % serialportlist("available")'
% % arduinoObj = serialport("COM6",9600);
% % configureTerminator(arduinoObj,"CR/LF");
% % flush(arduinoObj);
% % arduinoObj.UserData = struct("Data",[],"Count",1);
% % configureCallback(arduinoObj,"terminator",@readSineWaveData);
% % function readSineWaveData(src, ~)
% %
% % % Read the ASCII data from the serialport object.
% % data = readline(src);
% %
% % % Convert the string data to numeric type and save it in the UserData
% % % property of the serialport object.
% % src.UserData.Data(end+1) = str2double(data);
% %
% % % Update the Count value of the serialport object.
% % src.UserData.Count = src.UserData.Count + 1;
% %
% % % If 1001 data points have been collected from the Arduino, switch off the
% % % callbacks and plot the data.
% % if src.UserData.Count > 1001
% % configureCallback(src, "off");
% % plot(src.UserData.Data(2:end));
% % end
% % end
%
% a=arduino('com6','uno','libraries','Pololu/LSM303');
% Clearing
clear
%Init
uno = arduino;
% Hello blink
for i = 1:4
writeDigitalPin(uno, 'D3', 1);
pause(0.25);
writeDigitalPin(uno, 'D3', 0);
pause(0.25);
end
addrs = scanI2CBus(uno);
%Disable Sleep mode
mpu=device(uno,'I2CAddress','0x68'); %mpu adress is normally 0x68
writeRegister(mpu, hex2dec('6B'), hex2dec('00'), 'int16'); %reset
%Read Data
data=zeros(10000,14,'int8'); %prelocating for the speed
j=1;
Axl_1 = animatedline('Color',[1 0 0]);
Axl_2 = animatedline('Color',[0 1 0]);
Axl_3 = animatedline('Color',[0 0 1]);
legend('Axl_x','Axl_y','Axl_z');
% loop
while(true)
x=1;
for i=59:72 % 14 Data Registers for Axl,Temp,Gyro
data(j,x)= readRegister(mpu, i, 'int8');
x=x+1;
end
y = swapbytes(typecast(data(j,:), 'int16'));
addpoints(Axl_1,j,double(y(1)));
addpoints(Axl_2,j,double(y(2)));
addpoints(Axl_3,j,double(y(3)));
j=j+1;
drawnow limitrate;
end