MPU6050 Arduino Uno Simulink

74 views (last 30 days)
Alexandros
Alexandros on 23 Jul 2018
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
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 ;)

Sign in to comment.

Answers (1)

Gayatri Menon
Gayatri Menon on 4 Jan 2022
Hi
You could use MPU6050 block in simulink to read data from MPU6050 sensor connected to Arduino. To use MATLAB function block to read data from sensors, please refer to the link here.
Hope this helps
Thanks
Gayatri
  1 Comment
Ana Luz Gómez Plata
Ana Luz Gómez Plata on 6 Jun 2022
Sorry, do you know how to do it, I need help:(

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!