Page 1 of 1

I2C error with MPU6050

Posted: Tue May 08, 2018 9:03 am
by Cyborg67
Hi,
I currently use an OpenMV M7 with the recent firmware update for a visual/inertial odometry project.
I tried to connect a Drotek 6050MPU (slave address 0x69) using the openMV build in I2C. But when I run the an exemple code, i got an error : OSError: [Errno 110] ETIMEDOUT
So i check if my IMU is still functional on my aduino and it work with no problem...

Do you have any idea...? :?

Code: Select all

from pyb import I2C

ACCEL_XOUT0 = const(0x3B)
ACCEL_YOUT0 = const(0x3D)
ACCEL_ZOUT0 = const(0x3F)
GYRO_XOUT0 = const(0x43)
GYRO_YOUT0 = const(0x45)
GYRO_ZOUT0 = const(0x47)

# Wake up board
addr = 0x69
i2c = I2C(2)
i2c.init(I2C.MASTER)
i2c.mem_write(0x01, addr, 0x6b)

i2c.mem_write(0b00011000, addr, ACCEL_CONFIG)
i2c.mem_write(0b00011000, addr, GYRO_CONFIG)

# helper for converting 2 bytes to int.
btoi = lambda msb, lsb: (msb << 8 | lsb) if not msb & 0x80 else -(((msb ^ 255) << 8) | (lsb ^ 255) + 1)

accel_range = 16.0
accel_rate = 2048.0
gyro_range = 2000.0
gyro_rate = 16.4
accel = [0.0] * 3
gyro = [0.0] * 3

# init buffers
adata = bytearray(6)
gdata = bytearray(6)

# Start loop
while True:
    i2c.mem_read(adata, addr, ACCEL_XOUT0)
    i2c.mem_read(gdata, addr, GYRO_XOUT0)
    accel = [btoi(adata[0], adata[1])/accel_rate, btoi(adata[2], adata[3])/accel_rate, btoi(adata[4], adata[5])/accel_rate]
    gyro = [btoi(gdata[0], gdata[1])/gyro_rate, btoi(gdata[2], gdata[3])/gyro_rate, btoi(gdata[4], gdata[5])/gyro_rate]
    print('\n\n')
    print('accel: ', accel)
    print('gyro: ', gyro)
    print('\n\n')
    delay(300)

Re: I2C error with MPU6050

Posted: Wed May 09, 2018 1:10 am
by kwagyeman
Hi, was this code working previously? Also, do you have pull ups on the SDA and SCL lines?

Re: I2C error with MPU6050

Posted: Sun May 20, 2018 9:35 am
by Cyborg67
Hi,
I solve my problem : The drotek IMU don't work well with the power 5V output of the OpenMV. So I use an external 5.5V power source. :D

Re: I2C error with MPU6050

Posted: Mon May 21, 2018 11:48 pm
by kwagyeman
The OpenMV Cam only outputs 3.3V. It has a 5V input however. It's I/O pins are 5V tolerant so you can't easily break things.