MPU6050 Arduino Uno Simulink
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!!!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!!! 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!!! mpu, mpu6050, accelerometer, arduino, uno, arduino uno, simulink, matlab, gyroscope, readregister, writeregister, i2c, i2cdev MATLAB Answers — New Questions