MPU6050 Arduino Uno Simulink
98 views (last 30 days)
Show older comments
I have a code to get the MPU6050 working using Matlab, but now I would like to run it on Simulink, but I keep hitting dead ends. Here is my Matlab code if anyone out there can help me:
%%setup
a=arduino;
mpu=i2cdev(a,'0x68');
writeRegister(mpu, hex2dec('B6'), hex2dec('00'), 'int16'); %reset
data=zeros(10000,14,'int8'); %prelocating
j=1;
%%loop
while(true)
x=1;
for i=59:72 % 14 Data Registers for Accel,Temp,Gyro
data(j,x)= readRegister(mpu, i, 'int8');
x=x+1;
end
y=swapbytes(typecast(data(j,:), 'int16'));
acc_x(j)=double(y(1));
acc_y(j)=double(y(2));
acc_z(j)=double(y(3));
j=j+1;
end
How can I write this in SIMULINK? The loop is the easy part, I can just put it into a Matlab function block (except for readRegister)... I just can't figure out the setup part in Simulink at all. I have tryed using the I2C Read block, but to no avail. Please help. And before you ask, I do have both the Arduino packages installed (for Matlab, and Simulink).
Again Please HELP!!!
2 Comments
Jose Hernandez
on 12 Dec 2020
Edited: Jose Hernandez
on 12 Dec 2020
@fatima zohra soussi Install and use Matlab 2020b, then install Arduino support package,then go to Simulink and go to Arduino blocks, go to sensors blocks and check which sensors are available ;)
Answers (1)
See Also
Categories
Find more on Modeling in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!