Skip to content

Instantly share code, notes, and snippets.

@ibraEssam
Created March 19, 2019 14:36
Show Gist options
  • Select an option

  • Save ibraEssam/3e6a98f209bd3cb6a36be29156b8856c to your computer and use it in GitHub Desktop.

Select an option

Save ibraEssam/3e6a98f209bd3cb6a36be29156b8856c to your computer and use it in GitHub Desktop.
%% setup
hold all
a=arduino;
mpu=i2cdev(a,'0x68'); %mpu adress is normally 0x68
writeRegister(mpu, hex2dec('B6'), hex2dec('00'), 'int16'); %reset
data=zeros(10000,14,'int8'); %prelocating for the speed
j=1;
a1 = animatedline('Color',[1 0 0]);
a2 = animatedline('Color',[0 1 0]);
a3 = animatedline('Color',[0 0 1]);
legend('Accel_x','Accel_y','Accel_z')
%% 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')) %if your system is big-endian remove the swapbytes function
addpoints(a1,j,double(y(1)));
addpoints(a2,j,double(y(2)));
addpoints(a3,j,double(y(3)));
j=j+1;
drawnow limitrate
end
@jeisjiga
Copy link
Copy Markdown

Excuse me, in what pin slot of the arduino you conect the IMU, could you share the electrical digram

@dxmxax
Copy link
Copy Markdown

dxmxax commented Dec 12, 2019

Excuse me, in what pin slot of the arduino you conect the IMU, could you share the electrical digram

Depends on which Arduino board you are using but you are going to need for cables to connect
MPU-6050's VCC to Arduino's VCC
MPU-6050's GND to Arduino's GND
MPU-6050's SCL to Arduino's resereved pin for SCL
MPU-6050's SDA to Arduino's resereved pin for SDA

Copy link
Copy Markdown

ghost commented Jan 14, 2020

That's very intersting. How can I plot angle x,y and z mpu6050 on matlab?

@captainsmartpants
Copy link
Copy Markdown

I'm getting error:
Unrecognized function or variable 'i2cdev'.

Error in mpu60501 (line 4)
mpu=i2cdev(a,0x68); %mpu adress is normally 0x68

@AstroNiashree
Copy link
Copy Markdown

I'm getting error:
Unrecognized function or variable 'i2cdev'.

Error in mpu60501 (line 4)
mpu=i2cdev(a,0x68); %mpu adress is normally 0x68

I am getting the same error

@ibraEssam
Copy link
Copy Markdown
Author

You need to install Arduino support package

@Driiipstar
Copy link
Copy Markdown

Driiipstar commented Sep 24, 2020

Could you maybe tell me what each of this lines do?
I don't know how it really works.

@Bioma25
Copy link
Copy Markdown

Bioma25 commented Mar 18, 2021

Excuse me, how to solve this error?
Error using IMU_Plot (line 17)
Failed to read int8 values from register 3B.

Line 17 is: data(j,x)= readRegister(mpu, i, 'int8');

@Vit-A-Cuss
Copy link
Copy Markdown

mpu = device(a,'I2CAddress','0x68');

@goku-g
Copy link
Copy Markdown

goku-g commented Jan 26, 2022

@captainsmartpants @AstroNiashree
I got the same problem when I am using R2020a.

Solution:
This problem occurs because you are using the newer version of MatLab. Run your code in the MatLab version older than 2019/2018.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment