-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArduinoSystem.m
91 lines (69 loc) · 1.8 KB
/
ArduinoSystem.m
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
%% Arduino DRV2605L Haptic Driver
clear all
close all
clc
%% Global Variables
global effect
effect=0;
%% Initialization
fprintf('- Connecting to Device -\n');
% Connect to Arduino
dev=arduino();
fprintf('Connected to Controller\n\n');
% Setup I2C Protocol
configurePin(dev,'A4','I2C');
configurePin(dev,'A5','I2C');
% Scan I2C Devices
fprintf('- Checking Sub-systems -\n');
i2c_list=scanI2CBus(dev,0);
devStatus=[0,0];
% Check IMU Status
if any(strcmpi(i2c_list,'0x28'))
fprintf('0x28 - IMU BNO055 is found\n');
imu=i2cdev(dev,'0x28');
devStatus(1)=1;
else
fprintf('IMU not found!\n');
devStatus(1)=0;
end
% Check I2C Multiplexer
if any(strcmpi(i2c_list,'0x70'))
fprintf('0x70 - I2C Multiplexer TCA9548A is found\n');
multip=i2cdev(dev,'0x70');
devStatus(2)=1;
% Check Haptic Drivers
drv_list=[0,0,0,0,0,0,0,0];
for portNo=0:1:7
tcaSelect(portNo,multip);
multip_list=scanI2CBus(dev,0);
if any(strcmpi(multip_list,'0x5A'))
fprintf(strcat('0x5A - TCA #',num2str(portNo),' Haptic Driver is found\n'));
drv_list(portNo+1)=1;
end
end
if any(strcmpi(multip_list,'0X5A'))
drv=i2cdev(dev,'0x5A');
end
clear portNo multip_list
else
fprintf('I2C Multiplexer not found\nYou may not drive multiple Haptic Actuators\n');
devStatus(2)=0;
end
% Check Overall Device Status
if all(devStatus)
fprintf('\n- All Systems Go -\n');
else
fprintf('\n- Check Your Connections -\n');
end
%% DRV2605L Haptic Driver Initializations
for i=4:1:7
tcaSelect(i,multip);
fprintf(strcat('\n-DRV2605L #',num2str(i-3),'-\n'));
DRV2605L_install(drv);
DRV2605L_calibrate(drv);
DRV2605L_library(drv);
DRV2605L_trigger(drv);
DRV2605L_effect(drv);
DRV2605L_go(drv);
pause(3);
end